Skip to content

Commit

Permalink
reinit helm3lib action config on global hook module reload (#505)
Browse files Browse the repository at this point in the history
Signed-off-by: Mikhail Scherba <mikhail.scherba@flant.com>
  • Loading branch information
miklezzzz authored Sep 26, 2024
1 parent 2aac189 commit 1d2364e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pkg/addon-operator/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,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 @@ -2070,6 +2071,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

0 comments on commit 1d2364e

Please sign in to comment.