From 5b8c13f65a65a5d78523dba7b22d8477259856b7 Mon Sep 17 00:00:00 2001 From: Artur Zych <5843875+azych@users.noreply.github.com> Date: Wed, 19 Feb 2025 10:00:46 +0100 Subject: [PATCH] pkg/client: add Config method to ActionClient This exposes action.Configuration of a specific actionClient instance. General motivation behind it is for the users to have an 'escape hatch' access to the underlying dependency objects that action.Configuration holds, which include for example: - release records store - registry client - Kubernetes API client More specific motivation comes from a scenario where an access to the underlying release store instance is needed in order to gracefully handle pending helm releases which were previously interrupted. For additional context on this, see: https://github.com/operator-framework/operator-controller/pull/1776 Signed-off-by: Artur Zych <5843875+azych@users.noreply.github.com> --- pkg/client/actionclient.go | 6 ++++++ pkg/client/actionclient_test.go | 12 ++++++++++++ pkg/reconciler/internal/fake/actionclient.go | 15 +++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/pkg/client/actionclient.go b/pkg/client/actionclient.go index 130219d9..5af991a7 100644 --- a/pkg/client/actionclient.go +++ b/pkg/client/actionclient.go @@ -58,6 +58,7 @@ type ActionInterface interface { Upgrade(name, namespace string, chrt *chart.Chart, vals map[string]interface{}, opts ...UpgradeOption) (*release.Release, error) Uninstall(name string, opts ...UninstallOption) (*release.UninstallReleaseResponse, error) Reconcile(rel *release.Release) error + Config() *action.Configuration } type GetOption func(*action.Get) error @@ -212,6 +213,11 @@ type actionClient struct { var _ ActionInterface = &actionClient{} +// Config returns action.Configuration that this actionClient uses +func (c *actionClient) Config() *action.Configuration { + return c.conf +} + func (c *actionClient) Get(name string, opts ...GetOption) (*release.Release, error) { get := action.NewGet(c.conf) for _, o := range concat(c.defaultGetOpts, opts...) { diff --git a/pkg/client/actionclient_test.go b/pkg/client/actionclient_test.go index 727d3d1b..ef118309 100644 --- a/pkg/client/actionclient_test.go +++ b/pkg/client/actionclient_test.go @@ -454,6 +454,12 @@ var _ = Describe("ActionClient", func() { Expect(resp).To(BeNil()) }) }) + var _ = Describe("Config", func() { + It("should succeed", func() { + config := ac.Config() + Expect(config).NotTo(BeNil()) + }) + }) }) When("release is installed", func() { @@ -674,6 +680,12 @@ var _ = Describe("ActionClient", func() { verifyRelease(cl, obj, installedRelease) }) }) + var _ = Describe("Config", func() { + It("should succeed", func() { + config := ac.Config() + Expect(config).NotTo(BeNil()) + }) + }) }) }) diff --git a/pkg/reconciler/internal/fake/actionclient.go b/pkg/reconciler/internal/fake/actionclient.go index 162cdc1d..57cc3335 100644 --- a/pkg/reconciler/internal/fake/actionclient.go +++ b/pkg/reconciler/internal/fake/actionclient.go @@ -20,6 +20,7 @@ import ( "context" "errors" + "helm.sh/helm/v3/pkg/action" "helm.sh/helm/v3/pkg/chart" "helm.sh/helm/v3/pkg/release" crclient "sigs.k8s.io/controller-runtime/pkg/client" @@ -55,6 +56,7 @@ type ActionClient struct { Upgrades []UpgradeCall Uninstalls []UninstallCall Reconciles []ReconcileCall + Configs []ConfigCall HandleGet func() (*release.Release, error) HandleHistory func() ([]*release.Release, error) @@ -62,6 +64,7 @@ type ActionClient struct { HandleUpgrade func() (*release.Release, error) HandleUninstall func() (*release.UninstallReleaseResponse, error) HandleReconcile func() error + HandleConfig func() *action.Configuration } func NewActionClient() ActionClient { @@ -77,6 +80,9 @@ func NewActionClient() ActionClient { recFunc := func(err error) func() error { return func() error { return err } } + conFunc := func(conf *action.Configuration) func() *action.Configuration { + return func() *action.Configuration { return conf } + } return ActionClient{ Gets: make([]GetCall, 0), Histories: make([]HistoryCall, 0), @@ -84,6 +90,7 @@ func NewActionClient() ActionClient { Upgrades: make([]UpgradeCall, 0), Uninstalls: make([]UninstallCall, 0), Reconciles: make([]ReconcileCall, 0), + Configs: make([]ConfigCall, 0), HandleGet: relFunc(errors.New("get not implemented")), HandleHistory: historyFunc(errors.New("history not implemented")), @@ -91,6 +98,7 @@ func NewActionClient() ActionClient { HandleUpgrade: relFunc(errors.New("upgrade not implemented")), HandleUninstall: uninstFunc(errors.New("uninstall not implemented")), HandleReconcile: recFunc(errors.New("reconcile not implemented")), + HandleConfig: conFunc(nil), } } @@ -131,6 +139,8 @@ type ReconcileCall struct { Release *release.Release } +type ConfigCall struct{} + func (c *ActionClient) Get(name string, opts ...client.GetOption) (*release.Release, error) { c.Gets = append(c.Gets, GetCall{name, opts}) return c.HandleGet() @@ -160,3 +170,8 @@ func (c *ActionClient) Reconcile(rel *release.Release) error { c.Reconciles = append(c.Reconciles, ReconcileCall{rel}) return c.HandleReconcile() } + +func (c *ActionClient) Config() *action.Configuration { + c.Configs = append(c.Configs, ConfigCall{}) + return c.HandleConfig() +}