Skip to content

Commit

Permalink
add InstallReleaseFromChart and UpdateReleaseFromChart
Browse files Browse the repository at this point in the history
When using pkg/helm as a third party client, I am using chartutil.LoadArchive()
to load a chart from an io.Reader. After that is loaded I wish to install/update that
chart, however InstallRelease and UpdateRelease only accepts a path rather than
something of type *chart.Chart. This adds a new function called InstallReleaseFromChart
which allows one to load a chart separate from the path, then install said chart.
  • Loading branch information
Matthew Fisher committed Jan 23, 2017
1 parent 7389b34 commit dad40fc
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
10 changes: 10 additions & 0 deletions cmd/helm/helm_test.go
Expand Up @@ -135,6 +135,12 @@ func (c *fakeReleaseClient) InstallRelease(chStr, ns string, opts ...helm.Instal
}, nil
}

func (c *fakeReleaseClient) InstallReleaseFromChart(chart *chart.Chart, ns string, opts ...helm.InstallOption) (*rls.InstallReleaseResponse, error) {
return &rls.InstallReleaseResponse{
Release: c.rels[0],
}, nil
}

func (c *fakeReleaseClient) DeleteRelease(rlsName string, opts ...helm.DeleteOption) (*rls.UninstallReleaseResponse, error) {
return nil, nil
}
Expand Down Expand Up @@ -162,6 +168,10 @@ func (c *fakeReleaseClient) UpdateRelease(rlsName string, chStr string, opts ...
return nil, nil
}

func (c *fakeReleaseClient) UpdateReleaseFromChart(rlsName string, chart *chart.Chart, opts ...helm.UpdateOption) (*rls.UpdateReleaseResponse, error) {
return nil, nil
}

func (c *fakeReleaseClient) RollbackRelease(rlsName string, opts ...helm.RollbackOption) (*rls.RollbackReleaseResponse, error) {
return nil, nil
}
Expand Down
16 changes: 14 additions & 2 deletions pkg/helm/client.go
Expand Up @@ -21,6 +21,7 @@ import (
"google.golang.org/grpc"

"k8s.io/helm/pkg/chartutil"
"k8s.io/helm/pkg/proto/hapi/chart"
rls "k8s.io/helm/pkg/proto/hapi/services"
)

Expand Down Expand Up @@ -59,14 +60,19 @@ func (h *Client) ListReleases(opts ...ReleaseListOption) (*rls.ListReleasesRespo
return h.list(ctx, req)
}

// InstallRelease installs a new chart and returns the release response.
// InstallRelease loads a chart from chstr, installs it and returns the release response.
func (h *Client) InstallRelease(chstr, ns string, opts ...InstallOption) (*rls.InstallReleaseResponse, error) {
// load the chart to install
chart, err := chartutil.Load(chstr)
if err != nil {
return nil, err
}

return h.InstallReleaseFromChart(chart, ns, opts...)
}

// InstallReleaseFromChart installs a new chart and returns the release response.
func (h *Client) InstallReleaseFromChart(chart *chart.Chart, ns string, opts ...InstallOption) (*rls.InstallReleaseResponse, error) {
// apply the install options
for _, opt := range opts {
opt(&h.opts)
Expand Down Expand Up @@ -116,14 +122,20 @@ func (h *Client) DeleteRelease(rlsName string, opts ...DeleteOption) (*rls.Unins
return h.delete(ctx, req)
}

// UpdateRelease updates a release to a new/different chart
// UpdateRelease loads a chart from chstr and updates a release to a new/different chart
func (h *Client) UpdateRelease(rlsName string, chstr string, opts ...UpdateOption) (*rls.UpdateReleaseResponse, error) {
// load the chart to update
chart, err := chartutil.Load(chstr)
if err != nil {
return nil, err
}

return h.UpdateReleaseFromChart(rlsName, chart, opts...)
}

// UpdateReleaseFromChart updates a release to a new/different chart
func (h *Client) UpdateReleaseFromChart(rlsName string, chart *chart.Chart, opts ...UpdateOption) (*rls.UpdateReleaseResponse, error) {

// apply the update options
for _, opt := range opts {
opt(&h.opts)
Expand Down
3 changes: 3 additions & 0 deletions pkg/helm/interface.go
Expand Up @@ -17,16 +17,19 @@ limitations under the License.
package helm

import (
"k8s.io/helm/pkg/proto/hapi/chart"
rls "k8s.io/helm/pkg/proto/hapi/services"
)

// Interface for helm client for mocking in tests
type Interface interface {
ListReleases(opts ...ReleaseListOption) (*rls.ListReleasesResponse, error)
InstallRelease(chStr, namespace string, opts ...InstallOption) (*rls.InstallReleaseResponse, error)
InstallReleaseFromChart(chart *chart.Chart, namespace string, opts ...InstallOption) (*rls.InstallReleaseResponse, error)
DeleteRelease(rlsName string, opts ...DeleteOption) (*rls.UninstallReleaseResponse, error)
ReleaseStatus(rlsName string, opts ...StatusOption) (*rls.GetReleaseStatusResponse, error)
UpdateRelease(rlsName, chStr string, opts ...UpdateOption) (*rls.UpdateReleaseResponse, error)
UpdateReleaseFromChart(rlsName string, chart *chart.Chart, opts ...UpdateOption) (*rls.UpdateReleaseResponse, error)
RollbackRelease(rlsName string, opts ...RollbackOption) (*rls.RollbackReleaseResponse, error)
ReleaseContent(rlsName string, opts ...ContentOption) (*rls.GetReleaseContentResponse, error)
ReleaseHistory(rlsName string, opts ...HistoryOption) (*rls.GetHistoryResponse, error)
Expand Down

0 comments on commit dad40fc

Please sign in to comment.