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

fix(plugins): set pending releases to failed #696

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
23 changes: 21 additions & 2 deletions pkg/helm/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,15 @@ func InstallOrUpgradeHelmChartFromPlugin(ctx context.Context, local client.Clien
return err
}
}
// Avoid upgrading a currently pending release.
if releaseStatus, ok := isCanReleaseBeUpgraded(latestRelease); !ok {
return fmt.Errorf("cannot upgrade release %s/%s in status %s", latestRelease.Namespace, latestRelease.Name, releaseStatus.String())
if releaseStatus.IsPending() {
log.FromContext(ctx).Info("unlocking pending release in state", "namespace", latestRelease.Namespace, "name", plugin.Name)
if err := unlockPendingRelease(restClientGetter, latestRelease); err != nil {
return fmt.Errorf("failed unlocking pending release %s/%s: %w", latestRelease.Namespace, latestRelease.Name, err)
}
return fmt.Errorf("cannot upgrade pending release %s/%s, set to state to '%s'", latestRelease.Namespace, latestRelease.Name, release.StatusFailed)
}
return fmt.Errorf("cannot upgrade release %s/%s in status '%s'", latestRelease.Namespace, latestRelease.Name, releaseStatus.String())
}
log.FromContext(ctx).Info("upgrading release", "namespace", plugin.Spec.ReleaseNamespace, "name", plugin.Name)

Expand Down Expand Up @@ -547,6 +553,19 @@ func getValueFromSecret(ctx context.Context, c client.Client, secretNamespace, s
return string(valByte), nil
}

// unlockPendingRelease sets the status of a pending release to failed.
func unlockPendingRelease(restClientGetter genericclioptions.RESTClientGetter, rls *release.Release) error {
cfg, err := newHelmAction(restClientGetter, rls.Namespace)
if err != nil {
return err
}
if status := rls.Info.Status; status.IsPending() {
rls.SetStatus(release.StatusFailed, fmt.Sprintf("Release set to failed from stuck '%s' state", status.String()))
return cfg.Releases.Update(rls)
}
return nil
}

func isCanReleaseBeUpgraded(r *release.Release) (release.Status, bool) {
if r.Info == nil {
return release.StatusUnknown, false
Expand Down
Loading