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

reinit helm3lib action config on global hook module reload #505

Merged
merged 1 commit into from
Sep 26, 2024
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
11 changes: 11 additions & 0 deletions pkg/addon-operator/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/flant/addon-operator/pkg/addon-operator/converge"
"github.com/flant/addon-operator/pkg/app"
"github.com/flant/addon-operator/pkg/helm"
"github.com/flant/addon-operator/pkg/helm/helm3lib"
"github.com/flant/addon-operator/pkg/helm_resources_manager"
hookTypes "github.com/flant/addon-operator/pkg/hook/types"
"github.com/flant/addon-operator/pkg/kube_config_manager"
Expand Down Expand Up @@ -2023,6 +2024,16 @@ func (op *AddonOperator) HandleGlobalHookRun(t sh_task.Task, labels map[string]s
}
// Queue ReloadAllModules task
if reloadAll {
// if helm3lib is in use - reinit helm action configuration to update helm capabilities (newly available apiVersions and resoruce kinds)
if op.Helm.ClientType == helm.Helm3Lib {
if err := helm3lib.ReinitActionConfig(); err != nil {
logEntry.Errorf("Couldn't reinitialize helm3lib action configuration: %s", err)
t.UpdateFailureMessage(err.Error())
t.WithQueuedAt(time.Now())
res.Status = queue.Fail
return res
}
}
// Stop and remove all resource monitors to prevent excessive ModuleRun tasks
op.HelmResourcesManager.StopMonitors()
logLabels := t.GetLogLabels()
Expand Down
3 changes: 3 additions & 0 deletions pkg/helm/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

type ClientFactory struct {
NewClientFn func(logLabels ...map[string]string) client.HelmClient
ClientType ClientType
}

func (f *ClientFactory) NewClient(logLabels ...map[string]string) client.HelmClient {
Expand All @@ -31,6 +32,7 @@ func InitHelmClientFactory() (*ClientFactory, error) {
switch helmVersion {
case Helm3Lib:
log.Info("Helm3Lib detected. Use builtin Helm.")
factory.ClientType = Helm3Lib
factory.NewClientFn = helm3lib.NewClient
err = helm3lib.Init(&helm3lib.Options{
Namespace: app.Namespace,
Expand All @@ -41,6 +43,7 @@ func InitHelmClientFactory() (*ClientFactory, error) {
case Helm3:
log.Infof("Helm 3 detected (path is '%s')", helm3.Helm3Path)
// Use helm3 client.
factory.ClientType = Helm3
factory.NewClientFn = helm3.NewClient
err = helm3.Init(&helm3.Helm3Options{
Namespace: app.Namespace,
Expand Down
10 changes: 10 additions & 0 deletions pkg/helm/helm3lib/helm3lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ func Init(opts *Options) error {
return hc.initAndVersion()
}

// ReinitActionConfig reinitializes helm3 action configuration to update its list of capabilities
func ReinitActionConfig() error {
hc := &LibClient{
LogEntry: log.WithField("operator.component", "helm3lib"),
}
log.Debug("Reinitialize Helm 3 lib action configuration")

return hc.actionConfigInit()
}

// LibClient use helm3 package as Go library.
type LibClient struct {
LogEntry *log.Entry
Expand Down
Loading