This ports the functionality of cleanup on fail to v3 as introduced in #4871. This has been tested manually
and would be a good candidate for a new acceptance test.
Signed-off-by: Taylor Thomas <taylor.thomas@microsoft.com>
f.BoolVar(&client.DisableHooks,"no-hooks",false,"prevent hooks from running during rollback")
f.DurationVar(&client.Timeout,"timeout",300*time.Second,"time to wait for any individual Kubernetes operation (like Jobs for hooks)")
f.BoolVar(&client.Wait,"wait",false,"if set, will wait until all Pods, PVCs, Services, and minimum number of Pods of a Deployment, StatefulSet, or ReplicaSet are in a ready state 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.BoolVar(&client.Wait,"wait",false,"if set, will wait until all Pods, PVCs, Services, and minimum number of Pods of a Deployment, StatefulSet, or ReplicaSet are in a ready state before marking the release as successful. It will wait for as long as --timeout")
f.BoolVar(&client.Atomic,"atomic",false,"if set, upgrade process rolls back changes made in case of failed upgrade. The --wait flag will be set automatically if --atomic is used")
f.IntVar(&client.MaxHistory,"history-max",10,"limit the maximum number of revisions saved per release. Use 0 for no limit.")
f.BoolVar(&client.CleanupOnFail,"cleanup-on-fail",false,"allow deletion of new resources created in this upgrade when upgrade fails")
r.cfg.Log("Cleanup on fail set, cleaning up %d resources",len(results.Created))
_,errs:=r.cfg.KubeClient.Delete(results.Created)
iferrs!=nil{
varerrorList[]string
for_,e:=rangeerrs{
errorList=append(errorList,e.Error())
}
returntargetRelease,errors.Wrapf(fmt.Errorf("unable to cleanup resources: %s",strings.Join(errorList,", ")),"an error occurred while cleaning up resources. original rollback error: %s",err)
u.cfg.Log("Cleanup on fail set, cleaning up %d resources",len(created))
_,errs:=u.cfg.KubeClient.Delete(created)
iferrs!=nil{
varerrorList[]string
for_,e:=rangeerrs{
errorList=append(errorList,e.Error())
}
returnrel,errors.Wrapf(fmt.Errorf("unable to cleanup resources: %s",strings.Join(errorList,", ")),"an error occurred while cleaning up resources. original upgrade error: %s",err)
}
u.cfg.Log("Resource cleanup complete")
}
ifu.Atomic{
u.cfg.Log("Upgrade failed and atomic is set, rolling back to last successful release")