Skip to content

Commit

Permalink
Add msg about using pkg remove and cleanup err handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas Rodriguez committed Apr 24, 2024
1 parent 98f1562 commit 6ab57d0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
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

0 comments on commit 6ab57d0

Please sign in to comment.