Unverified Commit b6afc6bf authored by Matthew Fisher's avatar Matthew Fisher Committed by GitHub

Merge pull request #4985 from bkeroackdsc/client-accept-contexts

Helm client: add methods that accept contexts
parents 5437dd4d 545e2213
...@@ -85,8 +85,29 @@ func (h *Client) InstallRelease(chstr, ns string, opts ...InstallOption) (*rls.I ...@@ -85,8 +85,29 @@ func (h *Client) InstallRelease(chstr, ns string, opts ...InstallOption) (*rls.I
return h.InstallReleaseFromChart(chart, ns, opts...) 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. // InstallReleaseFromChart installs a new chart and returns the release response.
func (h *Client) InstallReleaseFromChart(chart *chart.Chart, ns string, opts ...InstallOption) (*rls.InstallReleaseResponse, error) { func (h *Client) InstallReleaseFromChart(chart *chart.Chart, ns string, opts ...InstallOption) (*rls.InstallReleaseResponse, error) {
return h.installReleaseFromChartWithContext(NewContext(), 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...)
}
// 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) {
// apply the install options // apply the install options
reqOpts := h.opts reqOpts := h.opts
for _, opt := range opts { for _, opt := range opts {
...@@ -99,7 +120,7 @@ func (h *Client) InstallReleaseFromChart(chart *chart.Chart, ns string, opts ... ...@@ -99,7 +120,7 @@ func (h *Client) InstallReleaseFromChart(chart *chart.Chart, ns string, opts ...
req.DisableHooks = reqOpts.disableHooks req.DisableHooks = reqOpts.disableHooks
req.DisableCrdHook = reqOpts.disableCRDHook req.DisableCrdHook = reqOpts.disableCRDHook
req.ReuseName = reqOpts.reuseName req.ReuseName = reqOpts.reuseName
ctx := NewContext() ctx = FromContext(ctx)
if reqOpts.before != nil { if reqOpts.before != nil {
if err := reqOpts.before(ctx, req); err != nil { if err := reqOpts.before(ctx, req); err != nil {
...@@ -159,8 +180,29 @@ func (h *Client) UpdateRelease(rlsName string, chstr string, opts ...UpdateOptio ...@@ -159,8 +180,29 @@ func (h *Client) UpdateRelease(rlsName string, chstr string, opts ...UpdateOptio
return h.UpdateReleaseFromChart(rlsName, chart, opts...) return h.UpdateReleaseFromChart(rlsName, chart, opts...)
} }
// UpdateReleaseWithContext loads a chart from chstr and updates a release to a new/different chart while accepting a context.
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. // UpdateReleaseFromChart updates a release to a new/different chart.
func (h *Client) UpdateReleaseFromChart(rlsName string, chart *chart.Chart, opts ...UpdateOption) (*rls.UpdateReleaseResponse, error) { func (h *Client) UpdateReleaseFromChart(rlsName string, chart *chart.Chart, opts ...UpdateOption) (*rls.UpdateReleaseResponse, error) {
return h.updateReleaseFromChartWithContext(NewContext(), 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 // apply the update options
reqOpts := h.opts reqOpts := h.opts
for _, opt := range opts { for _, opt := range opts {
...@@ -175,7 +217,7 @@ func (h *Client) UpdateReleaseFromChart(rlsName string, chart *chart.Chart, opts ...@@ -175,7 +217,7 @@ func (h *Client) UpdateReleaseFromChart(rlsName string, chart *chart.Chart, opts
req.Force = reqOpts.force req.Force = reqOpts.force
req.ResetValues = reqOpts.resetValues req.ResetValues = reqOpts.resetValues
req.ReuseValues = reqOpts.reuseValues req.ReuseValues = reqOpts.reuseValues
ctx := NewContext() ctx = FromContext(ctx)
if reqOpts.before != nil { if reqOpts.before != nil {
if err := reqOpts.before(ctx, req); err != nil { if err := reqOpts.before(ctx, req); err != nil {
......
...@@ -24,6 +24,7 @@ import ( ...@@ -24,6 +24,7 @@ import (
"sync" "sync"
"github.com/golang/protobuf/ptypes/timestamp" "github.com/golang/protobuf/ptypes/timestamp"
"golang.org/x/net/context"
"k8s.io/helm/pkg/chartutil" "k8s.io/helm/pkg/chartutil"
"k8s.io/helm/pkg/manifest" "k8s.io/helm/pkg/manifest"
"k8s.io/helm/pkg/proto/hapi/chart" "k8s.io/helm/pkg/proto/hapi/chart"
...@@ -87,6 +88,16 @@ func (c *FakeClient) InstallRelease(chStr, ns string, opts ...InstallOption) (*r ...@@ -87,6 +88,16 @@ func (c *FakeClient) InstallRelease(chStr, ns string, opts ...InstallOption) (*r
return c.InstallReleaseFromChart(chart, ns, opts...) return c.InstallReleaseFromChart(chart, ns, opts...)
} }
// InstallReleaseWithContext creates a new release and returns a InstallReleaseResponse containing that release and accepts a context
func (c *FakeClient) InstallReleaseWithContext(ctx context.Context, chStr, ns string, opts ...InstallOption) (*rls.InstallReleaseResponse, error) {
return c.InstallRelease(chStr, ns, opts...)
}
// InstallReleaseFromChartWithContext adds a new MockRelease to the fake client and returns a InstallReleaseResponse containing that release and accepts a context
func (c *FakeClient) InstallReleaseFromChartWithContext(ctx context.Context, chart *chart.Chart, ns string, opts ...InstallOption) (*rls.InstallReleaseResponse, error) {
return c.InstallReleaseFromChart(chart, ns, opts...)
}
// InstallReleaseFromChart adds a new MockRelease to the fake client and returns a InstallReleaseResponse containing that release // InstallReleaseFromChart adds a new MockRelease to the fake client and returns a InstallReleaseResponse containing that release
func (c *FakeClient) InstallReleaseFromChart(chart *chart.Chart, ns string, opts ...InstallOption) (*rls.InstallReleaseResponse, error) { func (c *FakeClient) InstallReleaseFromChart(chart *chart.Chart, ns string, opts ...InstallOption) (*rls.InstallReleaseResponse, error) {
for _, opt := range opts { for _, opt := range opts {
...@@ -155,6 +166,16 @@ func (c *FakeClient) UpdateRelease(rlsName string, chStr string, opts ...UpdateO ...@@ -155,6 +166,16 @@ func (c *FakeClient) UpdateRelease(rlsName string, chStr string, opts ...UpdateO
return c.UpdateReleaseFromChart(rlsName, &chart.Chart{}, opts...) return c.UpdateReleaseFromChart(rlsName, &chart.Chart{}, opts...)
} }
// UpdateReleaseWithContext returns an UpdateReleaseResponse containing the updated release, if it exists and accepts a context
func (c *FakeClient) UpdateReleaseWithContext(ctx context.Context, rlsName string, chStr string, opts ...UpdateOption) (*rls.UpdateReleaseResponse, error) {
return c.UpdateRelease(rlsName, chStr, opts...)
}
// UpdateReleaseFromChartWithContext returns an UpdateReleaseResponse containing the updated release, if it exists and accepts a context
func (c *FakeClient) UpdateReleaseFromChartWithContext(ctx context.Context, rlsName string, newChart *chart.Chart, opts ...UpdateOption) (*rls.UpdateReleaseResponse, error) {
return c.UpdateReleaseFromChart(rlsName, newChart, opts...)
}
// 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, newChart *chart.Chart, opts ...UpdateOption) (*rls.UpdateReleaseResponse, error) { func (c *FakeClient) UpdateReleaseFromChart(rlsName string, newChart *chart.Chart, opts ...UpdateOption) (*rls.UpdateReleaseResponse, error) {
for _, opt := range opts { for _, opt := range opts {
......
...@@ -17,6 +17,7 @@ limitations under the License. ...@@ -17,6 +17,7 @@ limitations under the License.
package helm package helm
import ( import (
"golang.org/x/net/context"
"k8s.io/helm/pkg/proto/hapi/chart" "k8s.io/helm/pkg/proto/hapi/chart"
rls "k8s.io/helm/pkg/proto/hapi/services" rls "k8s.io/helm/pkg/proto/hapi/services"
) )
...@@ -25,11 +26,15 @@ import ( ...@@ -25,11 +26,15 @@ import (
type Interface interface { type Interface interface {
ListReleases(opts ...ReleaseListOption) (*rls.ListReleasesResponse, error) ListReleases(opts ...ReleaseListOption) (*rls.ListReleasesResponse, error)
InstallRelease(chStr, namespace string, opts ...InstallOption) (*rls.InstallReleaseResponse, error) InstallRelease(chStr, namespace string, opts ...InstallOption) (*rls.InstallReleaseResponse, error)
InstallReleaseWithContext(ctx context.Context, chStr, namespace string, opts ...InstallOption) (*rls.InstallReleaseResponse, error)
InstallReleaseFromChart(chart *chart.Chart, namespace string, opts ...InstallOption) (*rls.InstallReleaseResponse, error) InstallReleaseFromChart(chart *chart.Chart, namespace string, opts ...InstallOption) (*rls.InstallReleaseResponse, error)
InstallReleaseFromChartWithContext(ctx context.Context, chart *chart.Chart, namespace string, opts ...InstallOption) (*rls.InstallReleaseResponse, error)
DeleteRelease(rlsName string, opts ...DeleteOption) (*rls.UninstallReleaseResponse, error) DeleteRelease(rlsName string, opts ...DeleteOption) (*rls.UninstallReleaseResponse, error)
ReleaseStatus(rlsName string, opts ...StatusOption) (*rls.GetReleaseStatusResponse, error) ReleaseStatus(rlsName string, opts ...StatusOption) (*rls.GetReleaseStatusResponse, error)
UpdateRelease(rlsName, chStr string, opts ...UpdateOption) (*rls.UpdateReleaseResponse, error) UpdateRelease(rlsName, chStr string, opts ...UpdateOption) (*rls.UpdateReleaseResponse, error)
UpdateReleaseWithContext(ctx context.Context, 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)
UpdateReleaseFromChartWithContext(ctx context.Context, 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, opts ...ContentOption) (*rls.GetReleaseContentResponse, error)
ReleaseHistory(rlsName string, opts ...HistoryOption) (*rls.GetHistoryResponse, error) ReleaseHistory(rlsName string, opts ...HistoryOption) (*rls.GetHistoryResponse, error)
......
...@@ -514,8 +514,13 @@ func WithMaxHistory(max int32) HistoryOption { ...@@ -514,8 +514,13 @@ func WithMaxHistory(max int32) HistoryOption {
// NewContext creates a versioned context. // NewContext creates a versioned context.
func NewContext() context.Context { func NewContext() context.Context {
return FromContext(context.TODO())
}
// FromContext returns a versioned context from a parent context
func FromContext(ctx context.Context) context.Context {
md := metadata.Pairs("x-helm-api-client", version.GetVersion()) 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 // ReleaseTestOption allows configuring optional request data for
......
...@@ -415,7 +415,9 @@ func (rs mockStream) SendHeader(m metadata.MD) error { return nil } ...@@ -415,7 +415,9 @@ func (rs mockStream) SendHeader(m metadata.MD) error { return nil }
func (rs mockStream) SetTrailer(m metadata.MD) {} func (rs mockStream) SetTrailer(m metadata.MD) {}
func (rs mockStream) SendMsg(v interface{}) error { return nil } func (rs mockStream) SendMsg(v interface{}) error { return nil }
func (rs mockStream) RecvMsg(v interface{}) error { return nil } func (rs mockStream) RecvMsg(v interface{}) error { return nil }
func (rs mockStream) Context() context.Context { return helm.NewContext() } func (rs mockStream) Context() context.Context {
return helm.NewContext()
}
type podSucceededKubeClient struct { type podSucceededKubeClient struct {
tillerEnv.PrintingKubeClient tillerEnv.PrintingKubeClient
......
...@@ -584,7 +584,9 @@ func (rs mockRunReleaseTestServer) SendHeader(m metadata.MD) error { return nil ...@@ -584,7 +584,9 @@ func (rs mockRunReleaseTestServer) SendHeader(m metadata.MD) error { return nil
func (rs mockRunReleaseTestServer) SetTrailer(m metadata.MD) {} func (rs mockRunReleaseTestServer) SetTrailer(m metadata.MD) {}
func (rs mockRunReleaseTestServer) SendMsg(v interface{}) error { return nil } func (rs mockRunReleaseTestServer) SendMsg(v interface{}) error { return nil }
func (rs mockRunReleaseTestServer) RecvMsg(v interface{}) error { return nil } func (rs mockRunReleaseTestServer) RecvMsg(v interface{}) error { return nil }
func (rs mockRunReleaseTestServer) Context() context.Context { return helm.NewContext() } func (rs mockRunReleaseTestServer) Context() context.Context {
return helm.NewContext()
}
type mockHooksManifest struct { type mockHooksManifest struct {
Metadata struct { Metadata struct {
......
...@@ -18,6 +18,7 @@ package tiller ...@@ -18,6 +18,7 @@ package tiller
import ( import (
"fmt" "fmt"
"reflect"
"strings" "strings"
"testing" "testing"
...@@ -28,7 +29,6 @@ import ( ...@@ -28,7 +29,6 @@ import (
"k8s.io/helm/pkg/proto/hapi/chart" "k8s.io/helm/pkg/proto/hapi/chart"
"k8s.io/helm/pkg/proto/hapi/release" "k8s.io/helm/pkg/proto/hapi/release"
"k8s.io/helm/pkg/proto/hapi/services" "k8s.io/helm/pkg/proto/hapi/services"
"reflect"
) )
func TestUpdateRelease(t *testing.T) { func TestUpdateRelease(t *testing.T) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment