Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkg/client: add Config method to ActionClient #424

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pkg/client/actionclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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...) {
Expand Down
12 changes: 12 additions & 0 deletions pkg/client/actionclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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())
})
})
})
})

Expand Down
15 changes: 15 additions & 0 deletions pkg/reconciler/internal/fake/actionclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -55,13 +56,15 @@ type ActionClient struct {
Upgrades []UpgradeCall
Uninstalls []UninstallCall
Reconciles []ReconcileCall
Configs []ConfigCall

HandleGet func() (*release.Release, error)
HandleHistory func() ([]*release.Release, error)
HandleInstall func() (*release.Release, error)
HandleUpgrade func() (*release.Release, error)
HandleUninstall func() (*release.UninstallReleaseResponse, error)
HandleReconcile func() error
HandleConfig func() *action.Configuration
}

func NewActionClient() ActionClient {
Expand All @@ -77,20 +80,25 @@ 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),
Installs: make([]InstallCall, 0),
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")),
HandleInstall: relFunc(errors.New("install not implemented")),
HandleUpgrade: relFunc(errors.New("upgrade not implemented")),
HandleUninstall: uninstFunc(errors.New("uninstall not implemented")),
HandleReconcile: recFunc(errors.New("reconcile not implemented")),
HandleConfig: conFunc(nil),
}
}

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
}
Loading