reconcile: simplify `NextAction` logic

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>
This commit is contained in:
Hidde Beydals 2023-10-31 22:33:06 +01:00
parent f156c3550e
commit 191bebfafd
No known key found for this signature in database
GPG Key ID: 979F380FC2341744
1 changed files with 11 additions and 13 deletions

View File

@ -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: