Skip to content
Closed
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
entries:
- description: >
For Helm-based operators, if the release is not installed but status.DeployedRelease is populated, skip the rollback(uninstall) if the install errors.
kind: "change"
breaking: false
11 changes: 10 additions & 1 deletion internal/helm/controller/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,20 @@ func (r HelmOperatorReconciler) Reconcile(ctx context.Context, request reconcile
status.RemoveCondition(types.ConditionIrreconcilable)

if !manager.IsInstalled() {
// If all the Helm release records are deleted, then the Helm operator will try to install the release again.
// In that case, if the install errors, then don't perform the uninstall rollback because it might lead to unintended data loss.
// See: https://github.com/operator-framework/operator-sdk/issues/4296
rollbackByUninstall := true
if status.DeployedRelease != nil {
log.Info("Release is not installed but status.DeployedRelease is populated. If the install error, skip rollback")
rollbackByUninstall = false
}

for k, v := range r.OverrideValues {
r.EventRecorder.Eventf(o, "Warning", "OverrideValuesInUse",
"Chart value %q overridden to %q by operator's watches.yaml", k, v)
}
installedRelease, err := manager.InstallRelease(ctx)
installedRelease, err := manager.InstallRelease(ctx, rollbackByUninstall)
if err != nil {
log.Error(err, "Release failed")
status.SetCondition(types.HelmAppCondition{
Expand Down
6 changes: 3 additions & 3 deletions internal/helm/release/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ type Manager interface {
IsInstalled() bool
IsUpgradeRequired() bool
Sync(context.Context) error
InstallRelease(context.Context, ...InstallOption) (*rpb.Release, error)
InstallRelease(context.Context, bool, ...InstallOption) (*rpb.Release, error)
UpgradeRelease(context.Context, ...UpgradeOption) (*rpb.Release, *rpb.Release, error)
ReconcileRelease(context.Context) (*rpb.Release, error)
UninstallRelease(context.Context, ...UninstallOption) (*rpb.Release, error)
Expand Down Expand Up @@ -157,7 +157,7 @@ func (m manager) getCandidateRelease(namespace, name string, chart *cpb.Chart,
}

// InstallRelease performs a Helm release install.
func (m manager) InstallRelease(ctx context.Context, opts ...InstallOption) (*rpb.Release, error) {
func (m manager) InstallRelease(ctx context.Context, rollbackByUninstall bool, opts ...InstallOption) (*rpb.Release, error) {
install := action.NewInstall(m.actionConfig)
install.ReleaseName = m.releaseName
install.Namespace = m.namespace
Expand All @@ -170,7 +170,7 @@ func (m manager) InstallRelease(ctx context.Context, opts ...InstallOption) (*rp
installedRelease, err := install.Run(m.chart, m.values)
if err != nil {
// Workaround for helm/helm#3338
if installedRelease != nil {
if installedRelease != nil && rollbackByUninstall {
uninstall := action.NewUninstall(m.actionConfig)
_, uninstallErr := uninstall.Run(m.releaseName)

Expand Down