mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-01-12 16:09:39 -05: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 (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/edgelesssys/constellation/v2/internal/constants"
|
"github.com/edgelesssys/constellation/v2/internal/constants"
|
||||||
@ -52,6 +54,12 @@ func newHelmInstallAction(config *action.Configuration, release release, timeout
|
|||||||
return action
|
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) {
|
func setWaitMode(a *action.Install, waitMode WaitMode) {
|
||||||
switch waitMode {
|
switch waitMode {
|
||||||
case WaitModeNone:
|
case WaitModeNone:
|
||||||
@ -70,11 +78,12 @@ func setWaitMode(a *action.Install, waitMode WaitMode) {
|
|||||||
|
|
||||||
// installAction is an action that installs a helm chart.
|
// installAction is an action that installs a helm chart.
|
||||||
type installAction struct {
|
type installAction struct {
|
||||||
preInstall func(context.Context) error
|
preInstall func(context.Context) error
|
||||||
release release
|
release release
|
||||||
helmAction *action.Install
|
helmAction *action.Install
|
||||||
postInstall func(context.Context) error
|
uninstallAction *action.Uninstall
|
||||||
log debugLog
|
postInstall func(context.Context) error
|
||||||
|
log debugLog
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply installs the chart.
|
// Apply installs the chart.
|
||||||
@ -103,6 +112,11 @@ func (a *installAction) SaveChart(chartsDir string, fileHandler file.Handler) er
|
|||||||
|
|
||||||
func (a *installAction) apply(ctx context.Context) error {
|
func (a *installAction) apply(ctx context.Context) error {
|
||||||
_, err := a.helmAction.RunWithContext(ctx, a.release.chart, a.release.values)
|
_, 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
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -228,3 +242,8 @@ func helmLog(log debugLog) action.DebugLog {
|
|||||||
log.Debug(fmt.Sprintf(format, v...))
|
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 {
|
func (a actionFactory) newInstall(release release, timeout time.Duration) *installAction {
|
||||||
action := &installAction{helmAction: newHelmInstallAction(a.cfg, release, timeout), release: release, log: a.log}
|
action := &installAction{helmAction: newHelmInstallAction(a.cfg, release, timeout), release: release, log: a.log}
|
||||||
|
if action.IsAtomic() {
|
||||||
|
action.uninstallAction = newHelmUninstallAction(a.cfg, timeout)
|
||||||
|
}
|
||||||
return action
|
return action
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user