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 <hello@hidde.co>
This commit is contained in:
parent
9812286bb4
commit
026fd45c2c
|
|
@ -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
|
// 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
|
// action result. The caller is expected to listen to this using a
|
||||||
// storage.ObserveFunc, which provides superior access to Helm storage writes.
|
// 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)
|
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 {
|
func newRollback(config *helmaction.Configuration, obj *v2.HelmRelease, opts []RollbackOption) *helmaction.Rollback {
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ import (
|
||||||
// UninstallOption can be used to modify Helm's action.Uninstall after the
|
// UninstallOption can be used to modify Helm's action.Uninstall after the
|
||||||
// instructions from the v2beta2.HelmRelease have been applied. This is for
|
// instructions from the v2beta2.HelmRelease have been applied. This is for
|
||||||
// example useful to enable the dry-run setting as a CLI.
|
// 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
|
// Uninstall runs the Helm uninstall action with the provided config, using the
|
||||||
// v2beta2.HelmReleaseSpec of the given object to determine the target release
|
// 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
|
// 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
|
// action result. The caller is expected to listen to this using a
|
||||||
// storage.ObserveFunc, which provides superior access to Helm storage writes.
|
// 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)
|
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 {
|
func newUninstall(config *helmaction.Configuration, obj *v2.HelmRelease, opts []UninstallOption) *helmaction.Uninstall {
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,7 @@ func (r *Rollback) Reconcile(ctx context.Context, req *Request) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run rollback action.
|
// 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.
|
// Mark failure on object.
|
||||||
req.Object.Status.Failures++
|
req.Object.Status.Failures++
|
||||||
conditions.MarkFalse(req.Object, v2.RemediatedCondition, v2.RollbackFailedReason, err.Error())
|
conditions.MarkFalse(req.Object, v2.RemediatedCondition, v2.RollbackFailedReason, err.Error())
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@ func (r *Uninstall) Reconcile(ctx context.Context, req *Request) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run the uninstall action.
|
// 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
|
// The Helm uninstall action does always target the latest release. Before
|
||||||
// accepting results, we need to confirm this is actually the release we
|
// accepting results, we need to confirm this is actually the release we
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue