Skip to content

Commit 6261f25

Browse files
authored
pkg/client: add Config method to ActionClient (#424)
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: operator-framework/operator-controller#1776 Signed-off-by: Artur Zych <[email protected]> Co-authored-by: Artur Zych <[email protected]>
1 parent 0e346e6 commit 6261f25

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

pkg/client/actionclient.go

+6
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ type ActionInterface interface {
5858
Upgrade(name, namespace string, chrt *chart.Chart, vals map[string]interface{}, opts ...UpgradeOption) (*release.Release, error)
5959
Uninstall(name string, opts ...UninstallOption) (*release.UninstallReleaseResponse, error)
6060
Reconcile(rel *release.Release) error
61+
Config() *action.Configuration
6162
}
6263

6364
type GetOption func(*action.Get) error
@@ -212,6 +213,11 @@ type actionClient struct {
212213

213214
var _ ActionInterface = &actionClient{}
214215

216+
// Config returns action.Configuration that this actionClient uses.
217+
func (c *actionClient) Config() *action.Configuration {
218+
return c.conf
219+
}
220+
215221
func (c *actionClient) Get(name string, opts ...GetOption) (*release.Release, error) {
216222
get := action.NewGet(c.conf)
217223
for _, o := range concat(c.defaultGetOpts, opts...) {

pkg/client/actionclient_test.go

+12
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,12 @@ var _ = Describe("ActionClient", func() {
454454
Expect(resp).To(BeNil())
455455
})
456456
})
457+
var _ = Describe("Config", func() {
458+
It("should succeed", func() {
459+
config := ac.Config()
460+
Expect(config).NotTo(BeNil())
461+
})
462+
})
457463
})
458464

459465
When("release is installed", func() {
@@ -674,6 +680,12 @@ var _ = Describe("ActionClient", func() {
674680
verifyRelease(cl, obj, installedRelease)
675681
})
676682
})
683+
var _ = Describe("Config", func() {
684+
It("should succeed", func() {
685+
config := ac.Config()
686+
Expect(config).NotTo(BeNil())
687+
})
688+
})
677689
})
678690
})
679691

pkg/reconciler/internal/fake/actionclient.go

+15
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"context"
2121
"errors"
2222

23+
"helm.sh/helm/v3/pkg/action"
2324
"helm.sh/helm/v3/pkg/chart"
2425
"helm.sh/helm/v3/pkg/release"
2526
crclient "sigs.k8s.io/controller-runtime/pkg/client"
@@ -55,13 +56,15 @@ type ActionClient struct {
5556
Upgrades []UpgradeCall
5657
Uninstalls []UninstallCall
5758
Reconciles []ReconcileCall
59+
Configs []ConfigCall
5860

5961
HandleGet func() (*release.Release, error)
6062
HandleHistory func() ([]*release.Release, error)
6163
HandleInstall func() (*release.Release, error)
6264
HandleUpgrade func() (*release.Release, error)
6365
HandleUninstall func() (*release.UninstallReleaseResponse, error)
6466
HandleReconcile func() error
67+
HandleConfig func() *action.Configuration
6568
}
6669

6770
func NewActionClient() ActionClient {
@@ -77,20 +80,25 @@ func NewActionClient() ActionClient {
7780
recFunc := func(err error) func() error {
7881
return func() error { return err }
7982
}
83+
conFunc := func(conf *action.Configuration) func() *action.Configuration {
84+
return func() *action.Configuration { return conf }
85+
}
8086
return ActionClient{
8187
Gets: make([]GetCall, 0),
8288
Histories: make([]HistoryCall, 0),
8389
Installs: make([]InstallCall, 0),
8490
Upgrades: make([]UpgradeCall, 0),
8591
Uninstalls: make([]UninstallCall, 0),
8692
Reconciles: make([]ReconcileCall, 0),
93+
Configs: make([]ConfigCall, 0),
8794

8895
HandleGet: relFunc(errors.New("get not implemented")),
8996
HandleHistory: historyFunc(errors.New("history not implemented")),
9097
HandleInstall: relFunc(errors.New("install not implemented")),
9198
HandleUpgrade: relFunc(errors.New("upgrade not implemented")),
9299
HandleUninstall: uninstFunc(errors.New("uninstall not implemented")),
93100
HandleReconcile: recFunc(errors.New("reconcile not implemented")),
101+
HandleConfig: conFunc(nil),
94102
}
95103
}
96104

@@ -131,6 +139,8 @@ type ReconcileCall struct {
131139
Release *release.Release
132140
}
133141

142+
type ConfigCall struct{}
143+
134144
func (c *ActionClient) Get(name string, opts ...client.GetOption) (*release.Release, error) {
135145
c.Gets = append(c.Gets, GetCall{name, opts})
136146
return c.HandleGet()
@@ -160,3 +170,8 @@ func (c *ActionClient) Reconcile(rel *release.Release) error {
160170
c.Reconciles = append(c.Reconciles, ReconcileCall{rel})
161171
return c.HandleReconcile()
162172
}
173+
174+
func (c *ActionClient) Config() *action.Configuration {
175+
c.Configs = append(c.Configs, ConfigCall{})
176+
return c.HandleConfig()
177+
}

0 commit comments

Comments
 (0)