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!: do not uninstall helm chart after failed install or upgrade #2456

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add msg about using pkg remove and cleanup err handling
  • Loading branch information
Lucas Rodriguez committed Apr 24, 2024
commit 6ab57d0bd36102561deea5a82276d1e2340c22c1
23 changes: 12 additions & 11 deletions src/internal/packager/helm/chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (h *Helm) InstallOrUpgradeChart() (types.ConnectStrings, string, error) {
}

if err != nil {
return fmt.Errorf("unable to complete the helm chart install/upgrade: %w", err)
return err
}

message.Debug(output.Info.Description)
Expand All @@ -92,7 +92,6 @@ func (h *Helm) InstallOrUpgradeChart() (types.ConnectStrings, string, error) {

err = helpers.Retry(tryHelm, h.retries, 5*time.Second, message.Warnf)
if err != nil {
// Try to rollback any deployed releases
releases, _ := histClient.Run(h.chart.ReleaseName)
previouslyDeployedVersion := 0

Expand All @@ -103,19 +102,21 @@ func (h *Helm) InstallOrUpgradeChart() (types.ConnectStrings, string, error) {
}
}

// On total failure try to rollback (if there was a previously deployed version) or uninstall.
if previouslyDeployedVersion > 0 {
spinner.Updatef("Performing chart rollback")
removeMsg := "if you need to remove the failed chart, use `zarf package remove`"

err = h.rollbackChart(h.chart.ReleaseName, previouslyDeployedVersion)
if err != nil {
return nil, "", fmt.Errorf("unable to upgrade chart after %d attempts and unable to rollback: %w", h.retries, err)
}
// No prior releases means this was an initial install.
if previouslyDeployedVersion == 0 {
return nil, "", fmt.Errorf("unable to install chart after %d attempts: %w: %s", h.retries, err, removeMsg)
}

return nil, "", fmt.Errorf("unable to upgrade chart after %d attempts", h.retries)
// Attempt to rollback on a failed upgrade.
spinner.Updatef("Performing chart rollback")
err = h.rollbackChart(h.chart.ReleaseName, previouslyDeployedVersion)
if err != nil {
return nil, "", fmt.Errorf("unable to upgrade chart after %d attempts and unable to rollback: %w: %s", h.retries, err, removeMsg)
}

return nil, "", fmt.Errorf("unable to install chart after %d attempts", h.retries)
return nil, "", fmt.Errorf("unable to upgrade chart after %d attempts: %w: %s", h.retries, err, removeMsg)
}

// return any collected connect strings for zarf connect.
Expand Down
2 changes: 1 addition & 1 deletion src/pkg/packager/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ func (p *Packager) deployComponent(component types.ZarfComponent, noImgChecksum

if hasCharts || hasManifests {
if charts, err = p.installChartAndManifests(componentPath, component); err != nil {
return charts, fmt.Errorf("unable to install helm chart(s): %w", err)
return charts, err
}
}

Expand Down
Loading