Skip to content

Commit

Permalink
reconcile: simplify NextAction logic
Browse files Browse the repository at this point in the history
By looking at the type of the error, instead of doing a separate check
on `cur != nil`.

Signed-off-by: Hidde Beydals <hidde@hhh.computer>
  • Loading branch information
hiddeco committed Oct 31, 2023
1 parent 596b071 commit 9a33863
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions internal/reconcile/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,29 +48,27 @@ func NextAction(ctx context.Context, cfg *action.ConfigFactory, recorder record.
config := cfg.Build(nil)
cur := req.Object.GetCurrent().DeepCopy()

// If we do not have a current release, we should either install or upgrade
// the release depending on the state of the storage.
if cur == nil {
// Verify the current release is still in storage and unmodified.
rls, err := action.VerifyLastStorageItem(config, cur)
switch err {
case nil:
// Noop
case action.ErrReleaseNotFound:
// If we do not have a current release, we should either install or upgrade
// the release depending on the state of the storage.
ok, err := action.IsInstalled(config, req.Object.GetReleaseName())
if err != nil {
return nil, fmt.Errorf("cannot confirm if release is already installed: %w", err)
}

if ok {
log.Info("found existing release in storage without it being observed as installed")
log.Info("found existing release in storage that is not owned by this HelmRelease")
return NewUpgrade(cfg, recorder), nil
}

log.Info("no existing release found in storage")
log.Info("no release found in storage")
return NewInstall(cfg, recorder), nil
}

// Verify the current release is still in storage and unmodified.
rls, err := action.VerifyLastStorageItem(config, cur)
switch err {
case nil:
// Noop
case action.ErrReleaseNotFound, action.ErrReleaseDisappeared:
case action.ErrReleaseDisappeared:
log.Info(fmt.Sprintf("unable to verify last release in storage: %s", err.Error()))
return NewInstall(cfg, recorder), nil
case action.ErrReleaseNotObserved, action.ErrReleaseDigest:
Expand Down

0 comments on commit 9a33863

Please sign in to comment.