From 026fd45c2c9d38551dd669b2e7c60bccfc15f41b Mon Sep 17 00:00:00 2001 From: Hidde Beydals Date: Thu, 15 Sep 2022 14:40:48 +0000 Subject: [PATCH] action: add name param to rollback and uninstall This gives more fine-grain control over what release must be targeted, as we do not always want to rely on the current spec but rather on e.g. a release we have made ourselves with a previous configuration for garbage collection purposes. Signed-off-by: Hidde Beydals --- internal/action/rollback.go | 4 ++-- internal/action/uninstall.go | 6 +++--- internal/reconcile/rollback.go | 2 +- internal/reconcile/uninstall.go | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/internal/action/rollback.go b/internal/action/rollback.go index 130ba4f..c839d51 100644 --- a/internal/action/rollback.go +++ b/internal/action/rollback.go @@ -35,9 +35,9 @@ type RollbackOption func(*helmaction.Rollback) // expected to be done by the caller. In addition, it does not take note of the // action result. The caller is expected to listen to this using a // storage.ObserveFunc, which provides superior access to Helm storage writes. -func Rollback(config *helmaction.Configuration, obj *v2.HelmRelease, opts ...RollbackOption) error { +func Rollback(config *helmaction.Configuration, obj *v2.HelmRelease, releaseName string, opts ...RollbackOption) error { rollback := newRollback(config, obj, opts) - return rollback.Run(obj.GetReleaseName()) + return rollback.Run(releaseName) } func newRollback(config *helmaction.Configuration, obj *v2.HelmRelease, opts []RollbackOption) *helmaction.Rollback { diff --git a/internal/action/uninstall.go b/internal/action/uninstall.go index 612773f..9c866e1 100644 --- a/internal/action/uninstall.go +++ b/internal/action/uninstall.go @@ -28,7 +28,7 @@ import ( // UninstallOption can be used to modify Helm's action.Uninstall after the // instructions from the v2beta2.HelmRelease have been applied. This is for // example useful to enable the dry-run setting as a CLI. -type UninstallOption func(*helmaction.Uninstall) +type UninstallOption func(cfg *helmaction.Uninstall) // Uninstall runs the Helm uninstall action with the provided config, using the // v2beta2.HelmReleaseSpec of the given object to determine the target release @@ -38,9 +38,9 @@ type UninstallOption func(*helmaction.Uninstall) // expected to be done by the caller. In addition, it does not take note of the // action result. The caller is expected to listen to this using a // storage.ObserveFunc, which provides superior access to Helm storage writes. -func Uninstall(_ context.Context, config *helmaction.Configuration, obj *v2.HelmRelease, opts ...UninstallOption) (*helmrelease.UninstallReleaseResponse, error) { +func Uninstall(_ context.Context, config *helmaction.Configuration, obj *v2.HelmRelease, releaseName string, opts ...UninstallOption) (*helmrelease.UninstallReleaseResponse, error) { uninstall := newUninstall(config, obj, opts) - return uninstall.Run(obj.GetReleaseName()) + return uninstall.Run(releaseName) } func newUninstall(config *helmaction.Configuration, obj *v2.HelmRelease, opts []UninstallOption) *helmaction.Uninstall { diff --git a/internal/reconcile/rollback.go b/internal/reconcile/rollback.go index 319f80d..8c4acfc 100644 --- a/internal/reconcile/rollback.go +++ b/internal/reconcile/rollback.go @@ -56,7 +56,7 @@ func (r *Rollback) Reconcile(ctx context.Context, req *Request) error { } // Run rollback action. - if err := action.Rollback(r.configFactory.Build(logBuf.Log, observeRollback(req.Object)), req.Object); err != nil { + if err := action.Rollback(r.configFactory.Build(logBuf.Log, observeRollback(req.Object)), req.Object, cur.Name); err != nil { // Mark failure on object. req.Object.Status.Failures++ conditions.MarkFalse(req.Object, v2.RemediatedCondition, v2.RollbackFailedReason, err.Error()) diff --git a/internal/reconcile/uninstall.go b/internal/reconcile/uninstall.go index c24f2be..1011650 100644 --- a/internal/reconcile/uninstall.go +++ b/internal/reconcile/uninstall.go @@ -49,7 +49,7 @@ func (r *Uninstall) Reconcile(ctx context.Context, req *Request) error { } // Run the uninstall action. - res, err := action.Uninstall(ctx, cfg, req.Object) + res, err := action.Uninstall(ctx, cfg, req.Object, cur.Name) // The Helm uninstall action does always target the latest release. Before // accepting results, we need to confirm this is actually the release we