|
|
@ -17,9 +17,12 @@ limitations under the License.
|
|
|
|
package helm // import "k8s.io/helm/pkg/helm"
|
|
|
|
package helm // import "k8s.io/helm/pkg/helm"
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"strings"
|
|
|
|
"sync"
|
|
|
|
"sync"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/technosophos/moniker"
|
|
|
|
"k8s.io/helm/pkg/proto/hapi/chart"
|
|
|
|
"k8s.io/helm/pkg/proto/hapi/chart"
|
|
|
|
"k8s.io/helm/pkg/proto/hapi/release"
|
|
|
|
"k8s.io/helm/pkg/proto/hapi/release"
|
|
|
|
rls "k8s.io/helm/pkg/proto/hapi/services"
|
|
|
|
rls "k8s.io/helm/pkg/proto/hapi/services"
|
|
|
@ -30,7 +33,15 @@ import (
|
|
|
|
type FakeClient struct {
|
|
|
|
type FakeClient struct {
|
|
|
|
Rels []*release.Release
|
|
|
|
Rels []*release.Release
|
|
|
|
Responses map[string]release.TestRun_Status
|
|
|
|
Responses map[string]release.TestRun_Status
|
|
|
|
Err error
|
|
|
|
Opts options
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Option returns the fake release client
|
|
|
|
|
|
|
|
func (c *FakeClient) Option(opts ...Option) Interface {
|
|
|
|
|
|
|
|
for _, opt := range opts {
|
|
|
|
|
|
|
|
opt(&c.Opts)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return c
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var _ Interface = &FakeClient{}
|
|
|
|
var _ Interface = &FakeClient{}
|
|
|
@ -42,31 +53,66 @@ func (c *FakeClient) ListReleases(opts ...ReleaseListOption) (*rls.ListReleasesR
|
|
|
|
Count: int64(len(c.Rels)),
|
|
|
|
Count: int64(len(c.Rels)),
|
|
|
|
Releases: c.Rels,
|
|
|
|
Releases: c.Rels,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return resp, c.Err
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// InstallRelease returns a response with the first Release on the fake release client
|
|
|
|
// InstallRelease returns a response with the first Release on the fake release client
|
|
|
|
func (c *FakeClient) InstallRelease(chStr, ns string, opts ...InstallOption) (*rls.InstallReleaseResponse, error) {
|
|
|
|
func (c *FakeClient) InstallRelease(chStr, ns string, opts ...InstallOption) (*rls.InstallReleaseResponse, error) {
|
|
|
|
return &rls.InstallReleaseResponse{
|
|
|
|
chart := &chart.Chart{}
|
|
|
|
Release: c.Rels[0],
|
|
|
|
return c.InstallReleaseFromChart(chart, ns, opts...)
|
|
|
|
}, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// InstallReleaseFromChart returns a response with the first Release on the fake release client
|
|
|
|
// InstallReleaseFromChart returns a response with the first Release on the fake release client
|
|
|
|
func (c *FakeClient) InstallReleaseFromChart(chart *chart.Chart, ns string, opts ...InstallOption) (*rls.InstallReleaseResponse, error) {
|
|
|
|
func (c *FakeClient) InstallReleaseFromChart(chart *chart.Chart, ns string, opts ...InstallOption) (*rls.InstallReleaseResponse, error) {
|
|
|
|
|
|
|
|
for _, opt := range opts {
|
|
|
|
|
|
|
|
opt(&c.Opts)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
releaseName := c.Opts.instReq.Name
|
|
|
|
|
|
|
|
if releaseName == "" {
|
|
|
|
|
|
|
|
for i := 0; i < 5; i++ {
|
|
|
|
|
|
|
|
namer := moniker.New()
|
|
|
|
|
|
|
|
name := namer.NameSep("-")
|
|
|
|
|
|
|
|
if len(name) > 53 {
|
|
|
|
|
|
|
|
name = name[:53]
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if _, err := c.ReleaseStatus(name, nil); strings.Contains(err.Error(), "No such release") {
|
|
|
|
|
|
|
|
releaseName = name
|
|
|
|
|
|
|
|
break
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Check to see if the release already exists.
|
|
|
|
|
|
|
|
rel, err := c.ReleaseStatus(releaseName, nil)
|
|
|
|
|
|
|
|
if err == nil && rel != nil {
|
|
|
|
|
|
|
|
return nil, errors.New("cannot re-use a name that is still in use")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
release := &release.Release{
|
|
|
|
|
|
|
|
Name: releaseName,
|
|
|
|
|
|
|
|
Namespace: ns,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
c.Rels = append(c.Rels, release)
|
|
|
|
|
|
|
|
|
|
|
|
return &rls.InstallReleaseResponse{
|
|
|
|
return &rls.InstallReleaseResponse{
|
|
|
|
Release: c.Rels[0],
|
|
|
|
Release: release,
|
|
|
|
}, nil
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// DeleteRelease returns nil, nil
|
|
|
|
// DeleteRelease returns nil, nil
|
|
|
|
func (c *FakeClient) DeleteRelease(rlsName string, opts ...DeleteOption) (*rls.UninstallReleaseResponse, error) {
|
|
|
|
func (c *FakeClient) DeleteRelease(rlsName string, opts ...DeleteOption) (*rls.UninstallReleaseResponse, error) {
|
|
|
|
return nil, nil
|
|
|
|
for i, rel := range c.Rels {
|
|
|
|
|
|
|
|
if rel.Name == rlsName {
|
|
|
|
|
|
|
|
c.Rels = append(c.Rels[:i], c.Rels[i+1:]...)
|
|
|
|
|
|
|
|
return &rls.UninstallReleaseResponse{
|
|
|
|
|
|
|
|
Release: rel,
|
|
|
|
|
|
|
|
}, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// UpdateRelease returns nil, nil
|
|
|
|
return nil, fmt.Errorf("No such release: %s", rlsName)
|
|
|
|
func (c *FakeClient) UpdateRelease(rlsName string, chStr string, opts ...UpdateOption) (*rls.UpdateReleaseResponse, error) {
|
|
|
|
|
|
|
|
return nil, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// GetVersion returns a fake version
|
|
|
|
// GetVersion returns a fake version
|
|
|
@ -78,9 +124,20 @@ func (c *FakeClient) GetVersion(opts ...VersionOption) (*rls.GetVersionResponse,
|
|
|
|
}, nil
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// UpdateRelease returns nil, nil
|
|
|
|
|
|
|
|
func (c *FakeClient) UpdateRelease(rlsName string, chStr string, opts ...UpdateOption) (*rls.UpdateReleaseResponse, error) {
|
|
|
|
|
|
|
|
return c.UpdateReleaseFromChart(rlsName, &chart.Chart{}, opts...)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// UpdateReleaseFromChart returns nil, nil
|
|
|
|
// UpdateReleaseFromChart returns nil, nil
|
|
|
|
func (c *FakeClient) UpdateReleaseFromChart(rlsName string, chart *chart.Chart, opts ...UpdateOption) (*rls.UpdateReleaseResponse, error) {
|
|
|
|
func (c *FakeClient) UpdateReleaseFromChart(rlsName string, chart *chart.Chart, opts ...UpdateOption) (*rls.UpdateReleaseResponse, error) {
|
|
|
|
return nil, nil
|
|
|
|
// Check to see if the release already exists.
|
|
|
|
|
|
|
|
rel, err := c.ReleaseContent(rlsName, nil)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return &rls.UpdateReleaseResponse{Release: rel.Release}, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// RollbackRelease returns nil, nil
|
|
|
|
// RollbackRelease returns nil, nil
|
|
|
@ -90,37 +147,33 @@ func (c *FakeClient) RollbackRelease(rlsName string, opts ...RollbackOption) (*r
|
|
|
|
|
|
|
|
|
|
|
|
// ReleaseStatus returns a release status response with info from the matching release name in the fake release client.
|
|
|
|
// ReleaseStatus returns a release status response with info from the matching release name in the fake release client.
|
|
|
|
func (c *FakeClient) ReleaseStatus(rlsName string, opts ...StatusOption) (*rls.GetReleaseStatusResponse, error) {
|
|
|
|
func (c *FakeClient) ReleaseStatus(rlsName string, opts ...StatusOption) (*rls.GetReleaseStatusResponse, error) {
|
|
|
|
if len(c.Rels) > 0 {
|
|
|
|
for _, rel := range c.Rels {
|
|
|
|
for _, release := range c.Rels {
|
|
|
|
if rel.Name == rlsName {
|
|
|
|
if release.Name == rlsName {
|
|
|
|
|
|
|
|
return &rls.GetReleaseStatusResponse{
|
|
|
|
return &rls.GetReleaseStatusResponse{
|
|
|
|
Name: release.Name,
|
|
|
|
Name: rel.Name,
|
|
|
|
Info: release.Info,
|
|
|
|
Info: rel.Info,
|
|
|
|
Namespace: release.Namespace,
|
|
|
|
Namespace: rel.Namespace,
|
|
|
|
}, nil
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil, fmt.Errorf("No such release: %s", rlsName)
|
|
|
|
return nil, fmt.Errorf("No such release: %s", rlsName)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ReleaseContent returns the configuration for the matching release name in the fake release client.
|
|
|
|
// ReleaseContent returns the configuration for the matching release name in the fake release client.
|
|
|
|
func (c *FakeClient) ReleaseContent(rlsName string, opts ...ContentOption) (resp *rls.GetReleaseContentResponse, err error) {
|
|
|
|
func (c *FakeClient) ReleaseContent(rlsName string, opts ...ContentOption) (resp *rls.GetReleaseContentResponse, err error) {
|
|
|
|
if len(c.Rels) > 0 {
|
|
|
|
for _, rel := range c.Rels {
|
|
|
|
for _, release := range c.Rels {
|
|
|
|
if rel.Name == rlsName {
|
|
|
|
if release.Name == rlsName {
|
|
|
|
return &rls.GetReleaseContentResponse{
|
|
|
|
resp = &rls.GetReleaseContentResponse{
|
|
|
|
Release: rel,
|
|
|
|
Release: release,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return resp, c.Err
|
|
|
|
return resp, fmt.Errorf("No such release: %s", rlsName)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ReleaseHistory returns a release's revision history.
|
|
|
|
// ReleaseHistory returns a release's revision history.
|
|
|
|
func (c *FakeClient) ReleaseHistory(rlsName string, opts ...HistoryOption) (*rls.GetHistoryResponse, error) {
|
|
|
|
func (c *FakeClient) ReleaseHistory(rlsName string, opts ...HistoryOption) (*rls.GetHistoryResponse, error) {
|
|
|
|
return &rls.GetHistoryResponse{Releases: c.Rels}, c.Err
|
|
|
|
return &rls.GetHistoryResponse{Releases: c.Rels}, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// RunReleaseTest executes a pre-defined tests on a release
|
|
|
|
// RunReleaseTest executes a pre-defined tests on a release
|
|
|
@ -147,8 +200,3 @@ func (c *FakeClient) RunReleaseTest(rlsName string, opts ...ReleaseTestOption) (
|
|
|
|
|
|
|
|
|
|
|
|
return results, errc
|
|
|
|
return results, errc
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Option returns the fake release client
|
|
|
|
|
|
|
|
func (c *FakeClient) Option(opt ...Option) Interface {
|
|
|
|
|
|
|
|
return c
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|