Added logic to rollback command

Signed-off-by: Jakub Domanski <vegetto_sys@yahoo.com>
pull/12518/head
Jakub Domanski 2 years ago
parent 740ed760cc
commit 32ae564f15

@ -85,6 +85,7 @@ func newRollbackCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
f.BoolVar(&client.WaitForJobs, "wait-for-jobs", false, "if set and --wait enabled, will wait until all Jobs have been completed before marking the release as successful. It will wait for as long as --timeout")
f.BoolVar(&client.CleanupOnFail, "cleanup-on-fail", false, "allow deletion of new resources created in this rollback when rollback fails")
f.IntVar(&client.MaxHistory, "history-max", settings.MaxHistory, "limit the maximum number of revisions saved per release. Use 0 for no limit")
f.BoolVar(&client.RecreateImmutableResources, "recreate-immutable-resources", false, "On status code 422, try to delete and create the resource again")
return cmd
}

@ -76,6 +76,11 @@ func TestRollbackCmd(t *testing.T) {
golden: "output/rollback-no-args.txt",
rels: rels,
wantError: true,
}, {
name: "rollback a release with recreate-immutable-resources option ",
cmd: "rollback funny-honey 1 --recreate-immutable-resources",
golden: "output/rollback.txt",
rels: rels,
}}
runTestCmd(t, tests)
}

@ -35,16 +35,17 @@ import (
type Rollback struct {
cfg *Configuration
Version int
Timeout time.Duration
Wait bool
WaitForJobs bool
DisableHooks bool
DryRun bool
Recreate bool // will (if true) recreate pods after a rollback.
Force bool // will (if true) force resource upgrade through uninstall/recreate if needed
CleanupOnFail bool
MaxHistory int // MaxHistory limits the maximum number of revisions saved per release
Version int
Timeout time.Duration
Wait bool
WaitForJobs bool
DisableHooks bool
DryRun bool
Recreate bool // will (if true) recreate pods after a rollback.
Force bool // will (if true) force resource upgrade through uninstall/recreate if needed
CleanupOnFail bool
MaxHistory int // MaxHistory limits the maximum number of revisions saved per release
RecreateImmutableResources bool // will (if true) try to delete and recreate immutable resources on 422 status code
}
// NewRollback creates a new Rollback object with the given configuration.
@ -187,7 +188,7 @@ func (r *Rollback) performRollback(currentRelease, targetRelease *release.Releas
if err != nil {
return targetRelease, errors.Wrap(err, "unable to set metadata visitor from target release")
}
results, err := r.cfg.KubeClient.Update(current, target, r.Force, false)
results, err := r.cfg.KubeClient.Update(current, target, r.Force, r.RecreateImmutableResources)
if err != nil {
msg := fmt.Sprintf("Rollback %q failed: %s", targetRelease.Name, err)

@ -513,6 +513,7 @@ func (u *Upgrade) failRelease(rel *release.Release, created kube.ResourceList, e
rollin.Recreate = u.Recreate
rollin.Force = u.Force
rollin.Timeout = u.Timeout
rollin.RecreateImmutableResources = u.RecreateImmutableResources
if rollErr := rollin.Run(rel.Name); rollErr != nil {
return rel, errors.Wrapf(rollErr, "an error occurred while rolling back the release. original upgrade error: %s", err)
}

Loading…
Cancel
Save