Refactor based on review comment

Signed-off-by: Chris Berry <bez625@gmail.com>
pull/10309/head
Chris Berry 7 months ago
parent 9791767baa
commit e5bc21c56b

@ -79,12 +79,13 @@ func main() {
// run when each command's execute method is called
cobra.OnInitialize(func() {
helmDriver := os.Getenv("HELM_DRIVER")
if err := actionConfig.Init(settings.RESTClientGetter(), settings.Namespace(), helmDriver, debug, hookOutputWriter); err != nil {
if err := actionConfig.Init(settings.RESTClientGetter(), settings.Namespace(), helmDriver, debug); err != nil {
log.Fatal(err)
}
if helmDriver == "memory" {
loadReleasesInMemory(actionConfig)
}
actionConfig.SetHookOutputFunc(hookOutputWriter)
})
if err := cmd.Execute(); err != nil {

@ -71,7 +71,7 @@ func newListCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
ValidArgsFunction: noMoreArgsCompFunc,
RunE: func(cmd *cobra.Command, _ []string) error {
if client.AllNamespaces {
if err := cfg.Init(settings.RESTClientGetter(), "", os.Getenv("HELM_DRIVER"), debug, nil); err != nil {
if err := cfg.Init(settings.RESTClientGetter(), "", os.Getenv("HELM_DRIVER"), debug); err != nil {
return err
}
}

@ -246,9 +246,6 @@ type RESTClientGetter interface {
// DebugLog sets the logger that writes debug strings
type DebugLog func(format string, v ...interface{})
// HookOutputFunc returns the io.Writer for outputting hook logs.
type HookOutputFunc func(namespace, pod, container string) io.Writer
// capabilities builds a Capabilities from discovery information.
func (cfg *Configuration) getCapabilities() (*chartutil.Capabilities, error) {
if cfg.Capabilities != nil {
@ -377,7 +374,7 @@ func (cfg *Configuration) recordRelease(r *release.Release) {
}
// Init initializes the action configuration
func (cfg *Configuration) Init(getter genericclioptions.RESTClientGetter, namespace, helmDriver string, log DebugLog, outputFunc HookOutputFunc) error {
func (cfg *Configuration) Init(getter genericclioptions.RESTClientGetter, namespace, helmDriver string, log DebugLog) error {
kc := kube.New(getter)
kc.Log = log
@ -429,11 +426,12 @@ func (cfg *Configuration) Init(getter genericclioptions.RESTClientGetter, namesp
cfg.KubeClient = kc
cfg.Releases = store
cfg.Log = log
if outputFunc != nil {
cfg.HookOutputFunc = outputFunc
} else {
cfg.HookOutputFunc = func(_, _, _ string) io.Writer { return io.Discard }
}
cfg.HookOutputFunc = func(_, _, _ string) io.Writer { return io.Discard }
return nil
}
// SetHookOutputFunc sets the HookOutputFunc on the Configuration.
func (cfg *Configuration) SetHookOutputFunc(hookOutputFunc func(_, _, _ string) io.Writer) {
cfg.HookOutputFunc = hookOutputFunc
}

@ -334,7 +334,7 @@ func TestConfiguration_Init(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
cfg := &Configuration{}
actualErr := cfg.Init(nil, "default", tt.helmDriver, nil, nil)
actualErr := cfg.Init(nil, "default", tt.helmDriver, nil)
if tt.expectErr {
assert.Error(t, actualErr)
assert.Contains(t, actualErr.Error(), tt.errMsg)

Loading…
Cancel
Save