ref(pkg/helm): allow ReleaseContent to call storage directly

pull/3945/head
Adam Reese 7 years ago
parent d52faff7b6
commit 6bca9686a1
No known key found for this signature in database
GPG Key ID: 06F35E60A7A18DD6

@ -81,9 +81,9 @@ func newGetCmd(client helm.Interface, out io.Writer) *cobra.Command {
// getCmd is the command that implements 'helm get' // getCmd is the command that implements 'helm get'
func (g *getCmd) run() error { func (g *getCmd) run() error {
res, err := g.client.ReleaseContent(g.release, helm.ContentReleaseVersion(g.version)) res, err := g.client.ReleaseContent(g.release, g.version)
if err != nil { if err != nil {
return prettyError(err) return prettyError(err)
} }
return printRelease(g.out, res.Release) return printRelease(g.out, res)
} }

@ -62,13 +62,13 @@ func newGetHooksCmd(client helm.Interface, out io.Writer) *cobra.Command {
} }
func (g *getHooksCmd) run() error { func (g *getHooksCmd) run() error {
res, err := g.client.ReleaseContent(g.release, helm.ContentReleaseVersion(g.version)) res, err := g.client.ReleaseContent(g.release, g.version)
if err != nil { if err != nil {
fmt.Fprintln(g.out, g.release) fmt.Fprintln(g.out, g.release)
return prettyError(err) return prettyError(err)
} }
for _, hook := range res.Release.Hooks { for _, hook := range res.Hooks {
fmt.Fprintf(g.out, "---\n# %s\n%s", hook.Name, hook.Manifest) fmt.Fprintf(g.out, "---\n# %s\n%s", hook.Name, hook.Manifest)
} }
return nil return nil

@ -66,10 +66,10 @@ func newGetManifestCmd(client helm.Interface, out io.Writer) *cobra.Command {
// getManifest implements 'helm get manifest' // getManifest implements 'helm get manifest'
func (g *getManifestCmd) run() error { func (g *getManifestCmd) run() error {
res, err := g.client.ReleaseContent(g.release, helm.ContentReleaseVersion(g.version)) res, err := g.client.ReleaseContent(g.release, g.version)
if err != nil { if err != nil {
return prettyError(err) return prettyError(err)
} }
fmt.Fprintln(g.out, res.Release.Manifest) fmt.Fprintln(g.out, res.Manifest)
return nil return nil
} }

@ -65,14 +65,14 @@ func newGetValuesCmd(client helm.Interface, out io.Writer) *cobra.Command {
// getValues implements 'helm get values' // getValues implements 'helm get values'
func (g *getValuesCmd) run() error { func (g *getValuesCmd) run() error {
res, err := g.client.ReleaseContent(g.release, helm.ContentReleaseVersion(g.version)) res, err := g.client.ReleaseContent(g.release, g.version)
if err != nil { if err != nil {
return prettyError(err) return prettyError(err)
} }
// If the user wants all values, compute the values and return. // If the user wants all values, compute the values and return.
if g.allValues { if g.allValues {
cfg, err := chartutil.CoalesceValues(res.Release.Chart, res.Release.Config) cfg, err := chartutil.CoalesceValues(res.Chart, res.Config)
if err != nil { if err != nil {
return err return err
} }
@ -84,6 +84,6 @@ func (g *getValuesCmd) run() error {
return nil return nil
} }
fmt.Fprintln(g.out, res.Release.Config.Raw) fmt.Fprintln(g.out, res.Config.Raw)
return nil return nil
} }

@ -27,9 +27,13 @@ import (
"google.golang.org/grpc/keepalive" "google.golang.org/grpc/keepalive"
healthpb "google.golang.org/grpc/health/grpc_health_v1" healthpb "google.golang.org/grpc/health/grpc_health_v1"
"k8s.io/helm/pkg/chartutil" "k8s.io/helm/pkg/chartutil"
"k8s.io/helm/pkg/proto/hapi/chart" "k8s.io/helm/pkg/proto/hapi/chart"
"k8s.io/helm/pkg/proto/hapi/release"
rls "k8s.io/helm/pkg/proto/hapi/services" rls "k8s.io/helm/pkg/proto/hapi/services"
"k8s.io/helm/pkg/storage"
"k8s.io/helm/pkg/storage/driver"
) )
// maxMsgSize use 20MB as the default message size limit. // maxMsgSize use 20MB as the default message size limit.
@ -39,11 +43,13 @@ const maxMsgSize = 1024 * 1024 * 20
// Client manages client side of the Helm-Tiller protocol. // Client manages client side of the Helm-Tiller protocol.
type Client struct { type Client struct {
opts options opts options
store *storage.Storage
} }
// NewClient creates a new client. // NewClient creates a new client.
func NewClient(opts ...Option) *Client { func NewClient(opts ...Option) *Client {
var c Client var c Client
c.store = storage.Init(driver.NewMemory())
// set some sane defaults // set some sane defaults
c.Option(ConnectTimeout(5)) c.Option(ConnectTimeout(5))
return c.Option(opts...) return c.Option(opts...)
@ -127,11 +133,11 @@ func (h *Client) DeleteRelease(rlsName string, opts ...DeleteOption) (*rls.Unins
if reqOpts.dryRun { if reqOpts.dryRun {
// In the dry run case, just see if the release exists // In the dry run case, just see if the release exists
r, err := h.ReleaseContent(rlsName) r, err := h.ReleaseContent(rlsName, 0)
if err != nil { if err != nil {
return &rls.UninstallReleaseResponse{}, err return &rls.UninstallReleaseResponse{}, err
} }
return &rls.UninstallReleaseResponse{Release: r.Release}, nil return &rls.UninstallReleaseResponse{Release: r}, nil
} }
req := &reqOpts.uninstallReq req := &reqOpts.uninstallReq
@ -234,21 +240,11 @@ func (h *Client) ReleaseStatus(rlsName string, opts ...StatusOption) (*rls.GetRe
} }
// ReleaseContent returns the configuration for a given release. // ReleaseContent returns the configuration for a given release.
func (h *Client) ReleaseContent(rlsName string, opts ...ContentOption) (*rls.GetReleaseContentResponse, error) { func (c *Client) ReleaseContent(name string, version int32) (*release.Release, error) {
reqOpts := h.opts if version <= 0 {
for _, opt := range opts { return c.store.Last(name)
opt(&reqOpts)
}
req := &reqOpts.contentReq
req.Name = rlsName
ctx := NewContext()
if reqOpts.before != nil {
if err := reqOpts.before(ctx, req); err != nil {
return nil, err
}
} }
return h.content(ctx, req) return c.store.Get(name, version)
} }
// ReleaseHistory returns a release's revision history. // ReleaseHistory returns a release's revision history.

@ -106,12 +106,12 @@ func (c *FakeClient) UpdateRelease(rlsName string, chStr string, opts ...UpdateO
// UpdateReleaseFromChart returns an UpdateReleaseResponse containing the updated release, if it exists // UpdateReleaseFromChart returns an UpdateReleaseResponse containing the updated release, if it exists
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) {
// Check to see if the release already exists. // Check to see if the release already exists.
rel, err := c.ReleaseContent(rlsName, nil) rel, err := c.ReleaseContent(rlsName, 0)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return &rls.UpdateReleaseResponse{Release: rel.Release}, nil return &rls.UpdateReleaseResponse{Release: rel}, nil
} }
// RollbackRelease returns nil, nil // RollbackRelease returns nil, nil
@ -134,15 +134,13 @@ func (c *FakeClient) ReleaseStatus(rlsName string, opts ...StatusOption) (*rls.G
} }
// 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, version int32) (*release.Release, error) {
for _, rel := range c.Rels { for _, rel := range c.Rels {
if rel.Name == rlsName { if rel.Name == rlsName {
return &rls.GetReleaseContentResponse{ return rel, nil
Release: rel,
}, nil
} }
} }
return resp, fmt.Errorf("No such release: %s", rlsName) return nil, fmt.Errorf("No such release: %s", rlsName)
} }
// ReleaseHistory returns a release's revision history. // ReleaseHistory returns a release's revision history.

@ -317,6 +317,7 @@ func TestReleaseStatus_VerifyOptions(t *testing.T) {
// 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")
// Options testdata // Options testdata
var releaseName = "test" var releaseName = "test"
var revision = int32(2) var revision = int32(2)
@ -340,7 +341,7 @@ func TestReleaseContent_VerifyOptions(t *testing.T) {
}) })
client := NewClient(b4c) client := NewClient(b4c)
if _, err := client.ReleaseContent(releaseName, ContentReleaseVersion(revision)); err != errSkip { if _, err := client.ReleaseContent(releaseName, revision); err != errSkip {
t.Fatalf("did not expect error but got (%v)\n``", err) t.Fatalf("did not expect error but got (%v)\n``", err)
} }

@ -18,6 +18,7 @@ package helm
import ( import (
"k8s.io/helm/pkg/proto/hapi/chart" "k8s.io/helm/pkg/proto/hapi/chart"
"k8s.io/helm/pkg/proto/hapi/release"
rls "k8s.io/helm/pkg/proto/hapi/services" rls "k8s.io/helm/pkg/proto/hapi/services"
) )
@ -31,7 +32,7 @@ type Interface interface {
UpdateRelease(rlsName, chStr string, opts ...UpdateOption) (*rls.UpdateReleaseResponse, error) UpdateRelease(rlsName, chStr string, opts ...UpdateOption) (*rls.UpdateReleaseResponse, error)
UpdateReleaseFromChart(rlsName string, chart *chart.Chart, opts ...UpdateOption) (*rls.UpdateReleaseResponse, error) UpdateReleaseFromChart(rlsName string, chart *chart.Chart, opts ...UpdateOption) (*rls.UpdateReleaseResponse, error)
RollbackRelease(rlsName string, opts ...RollbackOption) (*rls.RollbackReleaseResponse, error) RollbackRelease(rlsName string, opts ...RollbackOption) (*rls.RollbackReleaseResponse, error)
ReleaseContent(rlsName string, opts ...ContentOption) (*rls.GetReleaseContentResponse, error) ReleaseContent(rlsName string, version int32) (*release.Release, error)
ReleaseHistory(rlsName string, opts ...HistoryOption) (*rls.GetHistoryResponse, error) ReleaseHistory(rlsName string, opts ...HistoryOption) (*rls.GetHistoryResponse, error)
RunReleaseTest(rlsName string, opts ...ReleaseTestOption) (<-chan *rls.TestReleaseResponse, <-chan error) RunReleaseTest(rlsName string, opts ...ReleaseTestOption) (<-chan *rls.TestReleaseResponse, <-chan error)
} }

Loading…
Cancel
Save