diff --git a/pkg/addon-operator/operator.go b/pkg/addon-operator/operator.go index fa6a5363..c0c5e48c 100644 --- a/pkg/addon-operator/operator.go +++ b/pkg/addon-operator/operator.go @@ -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" @@ -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() diff --git a/pkg/helm/helm.go b/pkg/helm/helm.go index 8a745fad..0c2a454d 100644 --- a/pkg/helm/helm.go +++ b/pkg/helm/helm.go @@ -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 { @@ -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, @@ -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, diff --git a/pkg/helm/helm3lib/helm3lib.go b/pkg/helm/helm3lib/helm3lib.go index 59b16fb0..1e5f65c9 100644 --- a/pkg/helm/helm3lib/helm3lib.go +++ b/pkg/helm/helm3lib/helm3lib.go @@ -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