mirror of
https://github.com/edgelesssys/constellation.git
synced 2024-10-01 01:36:09 -04:00
helm: retry uninstall manually if atomic install failed (#2984)
This commit is contained in:
parent
1334b84c2e
commit
54af083da3
@ -8,8 +8,10 @@ package helm
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/edgelesssys/constellation/v2/internal/constants"
|
||||
@ -52,6 +54,12 @@ func newHelmInstallAction(config *action.Configuration, release release, timeout
|
||||
return action
|
||||
}
|
||||
|
||||
func newHelmUninstallAction(config *action.Configuration, timeout time.Duration) *action.Uninstall {
|
||||
action := action.NewUninstall(config)
|
||||
action.Timeout = timeout
|
||||
return action
|
||||
}
|
||||
|
||||
func setWaitMode(a *action.Install, waitMode WaitMode) {
|
||||
switch waitMode {
|
||||
case WaitModeNone:
|
||||
@ -73,6 +81,7 @@ type installAction struct {
|
||||
preInstall func(context.Context) error
|
||||
release release
|
||||
helmAction *action.Install
|
||||
uninstallAction *action.Uninstall
|
||||
postInstall func(context.Context) error
|
||||
log debugLog
|
||||
}
|
||||
@ -103,6 +112,11 @@ func (a *installAction) SaveChart(chartsDir string, fileHandler file.Handler) er
|
||||
|
||||
func (a *installAction) apply(ctx context.Context) error {
|
||||
_, err := a.helmAction.RunWithContext(ctx, a.release.chart, a.release.values)
|
||||
if isUninstallError(err) && a.uninstallAction != nil {
|
||||
a.log.Debug("cleaning up manually after failed atomic Helm install", "error", err, "release", a.release.releaseName)
|
||||
_, uninstallErr := a.uninstallAction.Run(a.release.releaseName)
|
||||
err = errors.Join(err, uninstallErr)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
@ -228,3 +242,8 @@ func helmLog(log debugLog) action.DebugLog {
|
||||
log.Debug(fmt.Sprintf(format, v...))
|
||||
}
|
||||
}
|
||||
|
||||
func isUninstallError(err error) bool {
|
||||
return err != nil && (strings.Contains(err.Error(), "an error occurred while uninstalling the release") ||
|
||||
strings.Contains(err.Error(), "cannot re-use a name that is still in use"))
|
||||
}
|
||||
|
@ -139,6 +139,9 @@ func (a actionFactory) appendNewAction(
|
||||
|
||||
func (a actionFactory) newInstall(release release, timeout time.Duration) *installAction {
|
||||
action := &installAction{helmAction: newHelmInstallAction(a.cfg, release, timeout), release: release, log: a.log}
|
||||
if action.IsAtomic() {
|
||||
action.uninstallAction = newHelmUninstallAction(a.cfg, timeout)
|
||||
}
|
||||
return action
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user