From e42aa6c09c58bf5e6113a5beb7c0834c1e383fa9 Mon Sep 17 00:00:00 2001 From: fibonacci1729 Date: Thu, 1 Sep 2016 13:56:07 -0600 Subject: [PATCH] feat(helm): add optional version flag to helm{get,status} --- cmd/helm/get.go | 6 +++++- cmd/helm/status.go | 6 +++++- pkg/helm/option.go | 43 ++++++++++++++++++++++++++++++++++++------- 3 files changed, 46 insertions(+), 9 deletions(-) diff --git a/cmd/helm/get.go b/cmd/helm/get.go index f1ad5334c..3a2fddb8d 100644 --- a/cmd/helm/get.go +++ b/cmd/helm/get.go @@ -48,6 +48,7 @@ type getCmd struct { release string out io.Writer client helm.Interface + version int32 } func newGetCmd(client helm.Interface, out io.Writer) *cobra.Command { @@ -71,6 +72,9 @@ func newGetCmd(client helm.Interface, out io.Writer) *cobra.Command { return get.run() }, } + + cmd.PersistentFlags().Int32Var(&get.version, "version", 0, "version of release") + cmd.AddCommand(newGetValuesCmd(nil, out)) cmd.AddCommand(newGetManifestCmd(nil, out)) cmd.AddCommand(newGetHooksCmd(nil, out)) @@ -96,7 +100,7 @@ MANIFEST: // getCmd is the command that implements 'helm get' func (g *getCmd) run() error { - res, err := g.client.ReleaseContent(g.release) + res, err := g.client.ReleaseContent(g.release, helm.ContentReleaseVersion(g.version)) if err != nil { return prettyError(err) } diff --git a/cmd/helm/status.go b/cmd/helm/status.go index a3403a824..2f9cfc032 100644 --- a/cmd/helm/status.go +++ b/cmd/helm/status.go @@ -35,6 +35,7 @@ type statusCmd struct { release string out io.Writer client helm.Interface + version int32 } func newStatusCmd(client helm.Interface, out io.Writer) *cobra.Command { @@ -58,11 +59,14 @@ func newStatusCmd(client helm.Interface, out io.Writer) *cobra.Command { return status.run() }, } + + cmd.PersistentFlags().Int32Var(&status.version, "version", 0, "version of release") + return cmd } func (s *statusCmd) run() error { - res, err := s.client.ReleaseStatus(s.release) + res, err := s.client.ReleaseStatus(s.release, helm.StatusReleaseVersion(s.version)) if err != nil { return prettyError(err) } diff --git a/pkg/helm/option.go b/pkg/helm/option.go index dff6acbd3..5d72f1f58 100644 --- a/pkg/helm/option.go +++ b/pkg/helm/option.go @@ -50,6 +50,10 @@ type options struct { updateReq rls.UpdateReleaseRequest // release uninstall options are applied directly to the uninstall release request uninstallReq rls.UninstallReleaseRequest + // release get status options are applied directly to the get release status request + statusReq rls.GetReleaseStatusRequest + // release get content options are applied directly to the get release content request + contentReq rls.GetReleaseContentRequest } // Home specifies the location of helm home, (default = "$HOME/.helm"). @@ -198,13 +202,32 @@ func InstallReuseName(reuse bool) InstallOption { } } -// ContentOption -- TODO +// ContentOption allows setting optional attributes when +// performing a GetReleaseContent tiller rpc. type ContentOption func(*options) -// StatusOption -- TODO +// ContentReleaseVersion will instruct Tiller to retrieve the content +// of a paritcular version of a release. +func ContentReleaseVersion(version int32) ContentOption { + return func(opts *options) { + opts.contentReq.Version = version + } +} + +// StatusOption allows setting optional attributes when +// performing a GetReleaseStatus tiller rpc. type StatusOption func(*options) -// DeleteOption -- TODO +// StatusReleaseVersion will instruct Tiller to retrieve the status +// of a paritcular version of a release. +func StatusReleaseVersion(version int32) StatusOption { + return func(opts *options) { + opts.statusReq.Version = version + } +} + +// DeleteOption allows setting optional attributes when +// performing a UninstallRelease tiller rpc. type DeleteOption func(*options) // UpdateOption allows specifying various settings @@ -281,12 +304,18 @@ func (o *options) rpcUpdateRelease(rlsName string, chr *cpb.Chart, rlc rls.Relea // Executes tiller.GetReleaseStatus RPC. func (o *options) rpcGetReleaseStatus(rlsName string, rlc rls.ReleaseServiceClient, opts ...StatusOption) (*rls.GetReleaseStatusResponse, error) { - req := &rls.GetReleaseStatusRequest{Name: rlsName} - return rlc.GetReleaseStatus(context.TODO(), req) + for _, opt := range opts { + opt(o) + } + o.statusReq.Name = rlsName + return rlc.GetReleaseStatus(context.TODO(), &o.statusReq) } // Executes tiller.GetReleaseContent. func (o *options) rpcGetReleaseContent(rlsName string, rlc rls.ReleaseServiceClient, opts ...ContentOption) (*rls.GetReleaseContentResponse, error) { - req := &rls.GetReleaseContentRequest{Name: rlsName} - return rlc.GetReleaseContent(context.TODO(), req) + for _, opt := range opts { + opt(o) + } + o.contentReq.Name = rlsName + return rlc.GetReleaseContent(context.TODO(), &o.contentReq) }