Skip to content

Commit

Permalink
reconcile: handle manually uninstalled release
Browse files Browse the repository at this point in the history
This is a better way of dealing with this situation, as the previous
logic would result in an `ErrNoStorageUpdate`.

Signed-off-by: Hidde Beydals <[email protected]>
  • Loading branch information
hiddeco committed Jul 28, 2023
1 parent 3817305 commit 18eb679
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
8 changes: 7 additions & 1 deletion internal/reconcile/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,14 @@ func (r *Uninstall) Reconcile(ctx context.Context, req *Request) error {

// Run the Helm uninstall action.
res, err := action.Uninstall(ctx, cfg, req.Object, cur.Name)

// When the release is not found, something else has already uninstalled
// the release. As such, we can assume the release is uninstalled while
// taking note that we did not do it.
if errors.Is(err, helmdriver.ErrReleaseNotFound) {
err = nil
conditions.MarkFalse(req.Object, v2.ReleasedCondition, v2.UninstallSucceededReason,
"Release %s was not found, assuming it is uninstalled", cur.FullReleaseName())
return nil
}

// The Helm uninstall action does always target the latest release. Before
Expand Down
39 changes: 39 additions & 0 deletions internal/reconcile/uninstall_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,45 @@ func TestUninstall_Reconcile(t *testing.T) {
expectFailures: 1,
wantErr: ErrReleaseMismatch,
},
{
name: "uninstall already deleted release",
driver: func(driver helmdriver.Driver) helmdriver.Driver {
return &storage.Failing{
// Explicitly inherit the driver, as we want to rely on the
// Secret storage, as the memory storage does not detach
// objects from the release action. Causing writes post-persist
// to leak to the stored release object.
// xref: https://github.com/helm/helm/issues/11304
Driver: driver,
QueryErr: helmdriver.ErrReleaseNotFound,
}
},
releases: func(namespace string) []*helmrelease.Release {
return []*helmrelease.Release{
testutil.BuildRelease(&helmrelease.MockReleaseOptions{
Name: mockReleaseName,
Namespace: namespace,
Version: 1,
Chart: testutil.BuildChart(testutil.ChartWithTestHook()),
Status: helmrelease.StatusDeployed,
}),
}
},
status: func(releases []*helmrelease.Release) v2.HelmReleaseStatus {
return v2.HelmReleaseStatus{
Current: release.ObservedToInfo(release.ObserveRelease(releases[0])),
}
},
expectConditions: []metav1.Condition{
*conditions.FalseCondition(meta.ReadyCondition, v2.UninstallSucceededReason,
"assuming it is uninstalled"),
*conditions.FalseCondition(v2.ReleasedCondition, v2.UninstallSucceededReason,
"assuming it is uninstalled"),
},
expectCurrent: func(releases []*helmrelease.Release) *v2.HelmReleaseInfo {
return release.ObservedToInfo(release.ObserveRelease(releases[0]))
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit 18eb679

Please sign in to comment.