helm client: add methods that accept contexts

Signed-off-by: Benjamen Keroack <benjamen.keroack@dollarshaveclub.com>
pull/4971/head
Benjamen Keroack 7 years ago
parent e8f52c8550
commit 43c446d76a

@ -64,7 +64,7 @@ func (h *Client) ListReleases(opts ...ReleaseListOption) (*rls.ListReleasesRespo
opt(&reqOpts)
}
req := &reqOpts.listReq
ctx := NewContext()
ctx := NewContext(context.Background())
if reqOpts.before != nil {
if err := reqOpts.before(ctx, req); err != nil {
@ -85,8 +85,29 @@ func (h *Client) InstallRelease(chstr, ns string, opts ...InstallOption) (*rls.I
return h.InstallReleaseFromChart(chart, ns, opts...)
}
// InstallReleaseWithContext loads a chart from chstr, installs it, and returns the release response while accepting a context.
func (h *Client) InstallReleaseWithContext(ctx context.Context, 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.installReleaseFromChartWithContext(ctx, 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) {
return h.installReleaseFromChartWithContext(context.Background(), chart, ns, opts...)
}
// InstallReleaseFromChartWithContext installs a new chart and returns the release response while accepting a context.
func (h *Client) InstallReleaseFromChartWithContext(ctx context.Context, chart *chart.Chart, ns string, opts ...InstallOption) (*rls.InstallReleaseResponse, error) {
return h.installReleaseFromChartWithContext(ctx, chart, ns, opts...)
}
// InstallReleaseFromChart installs a new chart and returns the release response while accepting a context.
func (h *Client) installReleaseFromChartWithContext(ctx context.Context, chart *chart.Chart, ns string, opts ...InstallOption) (*rls.InstallReleaseResponse, error) {
// apply the install options
reqOpts := h.opts
for _, opt := range opts {
@ -99,7 +120,7 @@ func (h *Client) InstallReleaseFromChart(chart *chart.Chart, ns string, opts ...
req.DisableHooks = reqOpts.disableHooks
req.DisableCrdHook = reqOpts.disableCRDHook
req.ReuseName = reqOpts.reuseName
ctx := NewContext()
ctx = NewContext(ctx)
if reqOpts.before != nil {
if err := reqOpts.before(ctx, req); err != nil {
@ -138,7 +159,7 @@ func (h *Client) DeleteRelease(rlsName string, opts ...DeleteOption) (*rls.Unins
req := &reqOpts.uninstallReq
req.Name = rlsName
req.DisableHooks = reqOpts.disableHooks
ctx := NewContext()
ctx := NewContext(context.Background())
if reqOpts.before != nil {
if err := reqOpts.before(ctx, req); err != nil {
@ -159,8 +180,28 @@ func (h *Client) UpdateRelease(rlsName string, chstr string, opts ...UpdateOptio
return h.UpdateReleaseFromChart(rlsName, chart, opts...)
}
func (h *Client) UpdateReleaseWithContext(ctx context.Context, 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.updateReleaseFromChartWithContext(ctx, 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) {
return h.updateReleaseFromChartWithContext(context.Background(), rlsName, chart, opts...)
}
// UpdateReleaseFromChartWithContext updates a release to a new/different chart while accepting a context.
func (h *Client) UpdateReleaseFromChartWithContext(ctx context.Context, rlsName string, chart *chart.Chart, opts ...UpdateOption) (*rls.UpdateReleaseResponse, error) {
return h.updateReleaseFromChartWithContext(ctx, rlsName, chart, opts...)
}
// updateReleaseFromChartWithContext updates a release to a new/different chart and accepts a context.
func (h *Client) updateReleaseFromChartWithContext(ctx context.Context, rlsName string, chart *chart.Chart, opts ...UpdateOption) (*rls.UpdateReleaseResponse, error) {
// apply the update options
reqOpts := h.opts
for _, opt := range opts {
@ -175,7 +216,7 @@ func (h *Client) UpdateReleaseFromChart(rlsName string, chart *chart.Chart, opts
req.Force = reqOpts.force
req.ResetValues = reqOpts.resetValues
req.ReuseValues = reqOpts.reuseValues
ctx := NewContext()
ctx = NewContext(ctx)
if reqOpts.before != nil {
if err := reqOpts.before(ctx, req); err != nil {
@ -201,7 +242,7 @@ func (h *Client) GetVersion(opts ...VersionOption) (*rls.GetVersionResponse, err
opt(&reqOpts)
}
req := &rls.GetVersionRequest{}
ctx := NewContext()
ctx := NewContext(context.Background())
if reqOpts.before != nil {
if err := reqOpts.before(ctx, req); err != nil {
@ -223,7 +264,7 @@ func (h *Client) RollbackRelease(rlsName string, opts ...RollbackOption) (*rls.R
req.DisableHooks = reqOpts.disableHooks
req.DryRun = reqOpts.dryRun
req.Name = rlsName
ctx := NewContext()
ctx := NewContext(context.Background())
if reqOpts.before != nil {
if err := reqOpts.before(ctx, req); err != nil {
@ -241,7 +282,7 @@ func (h *Client) ReleaseStatus(rlsName string, opts ...StatusOption) (*rls.GetRe
}
req := &reqOpts.statusReq
req.Name = rlsName
ctx := NewContext()
ctx := NewContext(context.Background())
if reqOpts.before != nil {
if err := reqOpts.before(ctx, req); err != nil {
@ -259,7 +300,7 @@ func (h *Client) ReleaseContent(rlsName string, opts ...ContentOption) (*rls.Get
}
req := &reqOpts.contentReq
req.Name = rlsName
ctx := NewContext()
ctx := NewContext(context.Background())
if reqOpts.before != nil {
if err := reqOpts.before(ctx, req); err != nil {
@ -278,7 +319,7 @@ func (h *Client) ReleaseHistory(rlsName string, opts ...HistoryOption) (*rls.Get
req := &reqOpts.histReq
req.Name = rlsName
ctx := NewContext()
ctx := NewContext(context.Background())
if reqOpts.before != nil {
if err := reqOpts.before(ctx, req); err != nil {
@ -297,14 +338,14 @@ func (h *Client) RunReleaseTest(rlsName string, opts ...ReleaseTestOption) (<-ch
req := &reqOpts.testReq
req.Name = rlsName
ctx := NewContext()
ctx := NewContext(context.Background())
return h.test(ctx, req)
}
// PingTiller pings the Tiller pod and ensure's that it is up and running
func (h *Client) PingTiller() error {
ctx := NewContext()
ctx := NewContext(context.Background())
return h.ping(ctx)
}

@ -471,9 +471,9 @@ func WithMaxHistory(max int32) HistoryOption {
}
// NewContext creates a versioned context.
func NewContext() context.Context {
func NewContext(ctx context.Context) context.Context {
md := metadata.Pairs("x-helm-api-client", version.GetVersion())
return metadata.NewOutgoingContext(context.TODO(), md)
return metadata.NewOutgoingContext(ctx, md)
}
// ReleaseTestOption allows configuring optional request data for

Loading…
Cancel
Save