Merge pull request #5383 from adamreese/v3/remove-releasestatus

ref(pkg/helm): refactor out `ReleaseStatus`
pull/5401/head
Adam Reese 6 years ago committed by GitHub
commit f4737d19aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -30,7 +30,6 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"k8s.io/helm/cmd/helm/require" "k8s.io/helm/cmd/helm/require"
"k8s.io/helm/pkg/hapi"
"k8s.io/helm/pkg/hapi/release" "k8s.io/helm/pkg/hapi/release"
"k8s.io/helm/pkg/helm" "k8s.io/helm/pkg/helm"
) )
@ -75,7 +74,7 @@ func newStatusCmd(client helm.Interface, out io.Writer) *cobra.Command {
} }
func (o *statusOptions) run(out io.Writer) error { func (o *statusOptions) run(out io.Writer) error {
res, err := o.client.ReleaseStatus(o.release, o.version) res, err := o.client.ReleaseContent(o.release, o.version)
if err != nil { if err != nil {
return err return err
} }
@ -105,7 +104,7 @@ func (o *statusOptions) run(out io.Writer) error {
// PrintStatus prints out the status of a release. Shared because also used by // PrintStatus prints out the status of a release. Shared because also used by
// install / upgrade // install / upgrade
func PrintStatus(out io.Writer, res *hapi.GetReleaseStatusResponse) { func PrintStatus(out io.Writer, res *release.Release) {
if !res.Info.LastDeployed.IsZero() { if !res.Info.LastDeployed.IsZero() {
fmt.Fprintf(out, "LAST DEPLOYED: %s\n", res.Info.LastDeployed) fmt.Fprintf(out, "LAST DEPLOYED: %s\n", res.Info.LastDeployed)
} }

@ -181,13 +181,6 @@ func (o *upgradeOptions) run(out io.Writer) error {
} }
fmt.Fprintf(out, "Release %q has been upgraded. Happy Helming!\n", o.release) fmt.Fprintf(out, "Release %q has been upgraded. Happy Helming!\n", o.release)
PrintStatus(out, resp)
// Print the status like status command does
status, err := o.client.ReleaseStatus(o.release, 0)
if err != nil {
return err
}
PrintStatus(out, status)
return nil return nil
} }

@ -169,19 +169,6 @@ func (c *Client) RollbackRelease(rlsName string, opts ...RollbackOption) (*relea
return c.tiller.RollbackRelease(req) return c.tiller.RollbackRelease(req)
} }
// ReleaseStatus returns the given release's status.
func (c *Client) ReleaseStatus(rlsName string, version int) (*hapi.GetReleaseStatusResponse, error) {
reqOpts := c.opts
req := &reqOpts.statusReq
req.Name = rlsName
req.Version = version
if err := reqOpts.runBefore(req); err != nil {
return nil, err
}
return c.tiller.GetReleaseStatus(req)
}
// ReleaseContent returns the configuration for a given release. // ReleaseContent returns the configuration for a given release.
func (c *Client) ReleaseContent(name string, version int) (*release.Release, error) { func (c *Client) ReleaseContent(name string, version int) (*release.Release, error) {
reqOpts := c.opts reqOpts := c.opts

@ -62,7 +62,7 @@ func (c *FakeClient) InstallReleaseFromChart(chart *chart.Chart, ns string, opts
releaseName := c.Opts.instReq.Name releaseName := c.Opts.instReq.Name
// Check to see if the release already exists. // Check to see if the release already exists.
rel, err := c.ReleaseStatus(releaseName, 0) rel, err := c.ReleaseContent(releaseName, 0)
if err == nil && rel != nil { if err == nil && rel != nil {
return nil, errors.New("cannot re-use a name that is still in use") return nil, errors.New("cannot re-use a name that is still in use")
} }

@ -25,93 +25,6 @@ import (
"k8s.io/helm/pkg/hapi/release" "k8s.io/helm/pkg/hapi/release"
) )
func TestFakeClient_ReleaseStatus(t *testing.T) {
releasePresent := ReleaseMock(&MockReleaseOptions{Name: "release-present"})
releaseNotPresent := ReleaseMock(&MockReleaseOptions{Name: "release-not-present"})
type fields struct {
Rels []*release.Release
}
type args struct {
rlsName string
}
tests := []struct {
name string
fields fields
args args
want *hapi.GetReleaseStatusResponse
wantErr bool
}{
{
name: "Get a single release that exists",
fields: fields{
Rels: []*release.Release{
releasePresent,
},
},
args: args{
rlsName: releasePresent.Name,
},
want: &hapi.GetReleaseStatusResponse{
Name: releasePresent.Name,
Info: releasePresent.Info,
Namespace: releasePresent.Namespace,
},
wantErr: false,
},
{
name: "Get a release that does not exist",
fields: fields{
Rels: []*release.Release{
releasePresent,
},
},
args: args{
rlsName: releaseNotPresent.Name,
},
want: nil,
wantErr: true,
},
{
name: "Get a single release that exists from list",
fields: fields{
Rels: []*release.Release{
ReleaseMock(&MockReleaseOptions{Name: "angry-dolphin", Namespace: "default"}),
ReleaseMock(&MockReleaseOptions{Name: "trepid-tapir", Namespace: "default"}),
releasePresent,
},
},
args: args{
rlsName: releasePresent.Name,
},
want: &hapi.GetReleaseStatusResponse{
Name: releasePresent.Name,
Info: releasePresent.Info,
Namespace: releasePresent.Namespace,
},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
c := &FakeClient{
Rels: tt.fields.Rels,
}
got, err := c.ReleaseStatus(tt.args.rlsName, 0)
if (err != nil) != tt.wantErr {
t.Errorf("FakeClient.ReleaseStatus() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("FakeClient.ReleaseStatus() = %v, want %v", got, tt.want)
}
})
}
}
func TestFakeClient_InstallReleaseFromChart(t *testing.T) { func TestFakeClient_InstallReleaseFromChart(t *testing.T) {
installChart := &chart.Chart{} installChart := &chart.Chart{}
type fields struct { type fields struct {

@ -213,39 +213,6 @@ func TestRollbackRelease_VerifyOptions(t *testing.T) {
assert(t, "", client.opts.rollbackReq.Name) assert(t, "", client.opts.rollbackReq.Name)
} }
// Verify each StatusOption is applied to a GetReleaseStatusRequest correctly.
func TestReleaseStatus_VerifyOptions(t *testing.T) {
// Options testdata
var releaseName = "test"
var revision = 2
// Expected GetReleaseStatusRequest message
exp := &hapi.GetReleaseStatusRequest{
Name: releaseName,
Version: revision,
}
// BeforeCall option to intercept Helm client GetReleaseStatusRequest
b4c := BeforeCall(func(msg interface{}) error {
switch act := msg.(type) {
case *hapi.GetReleaseStatusRequest:
t.Logf("GetReleaseStatusRequest: %#+v\n", act)
assert(t, exp, act)
default:
t.Fatalf("expected message of type GetReleaseStatusRequest, got %T\n", act)
}
return errSkip
})
client := NewClient(b4c)
if _, err := client.ReleaseStatus(releaseName, revision); err != errSkip {
t.Fatalf("did not expect error but got (%v)\n``", err)
}
// ensure options for call are not saved to client
assert(t, "", client.opts.statusReq.Name)
}
// Verify each ContentOption is applied to a GetReleaseContentRequest correctly. // Verify each ContentOption is applied to a GetReleaseContentRequest correctly.
func TestReleaseContent_VerifyOptions(t *testing.T) { func TestReleaseContent_VerifyOptions(t *testing.T) {
t.Skip("refactoring out") t.Skip("refactoring out")

@ -27,7 +27,6 @@ type Interface interface {
InstallRelease(chStr, namespace string, opts ...InstallOption) (*release.Release, error) InstallRelease(chStr, namespace string, opts ...InstallOption) (*release.Release, error)
InstallReleaseFromChart(chart *chart.Chart, namespace string, opts ...InstallOption) (*release.Release, error) InstallReleaseFromChart(chart *chart.Chart, namespace string, opts ...InstallOption) (*release.Release, error)
UninstallRelease(rlsName string, opts ...UninstallOption) (*hapi.UninstallReleaseResponse, error) UninstallRelease(rlsName string, opts ...UninstallOption) (*hapi.UninstallReleaseResponse, error)
ReleaseStatus(rlsName string, version int) (*hapi.GetReleaseStatusResponse, error)
UpdateRelease(rlsName, chStr string, opts ...UpdateOption) (*release.Release, error) UpdateRelease(rlsName, chStr string, opts ...UpdateOption) (*release.Release, error)
UpdateReleaseFromChart(rlsName string, chart *chart.Chart, opts ...UpdateOption) (*release.Release, error) UpdateReleaseFromChart(rlsName string, chart *chart.Chart, opts ...UpdateOption) (*release.Release, error)
RollbackRelease(rlsName string, opts ...RollbackOption) (*release.Release, error) RollbackRelease(rlsName string, opts ...RollbackOption) (*release.Release, error)

Loading…
Cancel
Save