Add the cleanup-on-fail flag to upgrade command (#969)
* Adding the cleanup-on-fail flag to upgrade command * Adding tests and making the flag optional * Updating readme with new flag details * go fmt
This commit is contained in:
parent
25599eae89
commit
04379cee80
|
|
@ -74,6 +74,7 @@ helmDefaults:
|
|||
tillerNamespace: tiller-namespace #dedicated default key for tiller-namespace
|
||||
tillerless: false #dedicated default key for tillerless
|
||||
kubeContext: kube-context #dedicated default key for kube-context (--kube-context)
|
||||
cleanup-on-fail: false #dedicated default key for helm flag --cleanup-on-fail
|
||||
# additional and global args passed to helm
|
||||
args:
|
||||
- "--set k=v"
|
||||
|
|
@ -157,6 +158,8 @@ releases:
|
|||
installed: true
|
||||
# restores previous state in case of failed release
|
||||
atomic: true
|
||||
# when true, cleans up any new resources created during a failed release
|
||||
cleanup-on-fail: false
|
||||
# name of the tiller namespace
|
||||
tillerNamespace: vault
|
||||
# if true, will use the helm-tiller plugin
|
||||
|
|
|
|||
|
|
@ -101,6 +101,8 @@ type HelmSpec struct {
|
|||
Force bool `yaml:"force"`
|
||||
// Atomic, when set to true, restore previous state in case of a failed install/upgrade attempt
|
||||
Atomic bool `yaml:"atomic"`
|
||||
// CleanupOnFail, when set to true, the --cleanup-on-fail helm flag is passed to the upgrade command
|
||||
CleanupOnFail bool `yaml:"cleanup-on-fail,omitempty"`
|
||||
|
||||
TLS bool `yaml:"tls"`
|
||||
TLSCACert string `yaml:"tlsCACert,omitempty"`
|
||||
|
|
@ -139,6 +141,8 @@ type ReleaseSpec struct {
|
|||
Installed *bool `yaml:"installed,omitempty"`
|
||||
// Atomic, when set to true, restore previous state in case of a failed install/upgrade attempt
|
||||
Atomic *bool `yaml:"atomic,omitempty"`
|
||||
// CleanupOnFail, when set to true, the --cleanup-on-fail helm flag is passed to the upgrade command
|
||||
CleanupOnFail *bool `yaml:"cleanup-on-fail,omitempty"`
|
||||
|
||||
// MissingFileHandler is set to either "Error" or "Warn". "Error" instructs helmfile to fail when unable to find a values or secrets file. When "Warn", it prints the file and continues.
|
||||
// The default value for MissingFileHandler is "Error".
|
||||
|
|
@ -1546,6 +1550,10 @@ func (st *HelmState) flagsForUpgrade(helm helmexec.Interface, release *ReleaseSp
|
|||
flags = append(flags, "--atomic")
|
||||
}
|
||||
|
||||
if release.CleanupOnFail != nil && *release.CleanupOnFail || release.CleanupOnFail == nil && st.HelmDefaults.CleanupOnFail {
|
||||
flags = append(flags, "--cleanup-on-fail")
|
||||
}
|
||||
|
||||
flags = st.appendConnectionFlags(flags, release)
|
||||
|
||||
var err error
|
||||
|
|
|
|||
|
|
@ -448,6 +448,58 @@ func TestHelmState_flagsForUpgrade(t *testing.T) {
|
|||
"--namespace", "test-namespace",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "cleanup-on-fail",
|
||||
defaults: HelmSpec{
|
||||
CleanupOnFail: false,
|
||||
},
|
||||
release: &ReleaseSpec{
|
||||
Chart: "test/chart",
|
||||
Version: "0.1",
|
||||
CleanupOnFail: &enable,
|
||||
Name: "test-charts",
|
||||
Namespace: "test-namespace",
|
||||
},
|
||||
want: []string{
|
||||
"--version", "0.1",
|
||||
"--cleanup-on-fail",
|
||||
"--namespace", "test-namespace",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "cleanup-on-fail-override-default",
|
||||
defaults: HelmSpec{
|
||||
CleanupOnFail: true,
|
||||
},
|
||||
release: &ReleaseSpec{
|
||||
Chart: "test/chart",
|
||||
Version: "0.1",
|
||||
CleanupOnFail: &disable,
|
||||
Name: "test-charts",
|
||||
Namespace: "test-namespace",
|
||||
},
|
||||
want: []string{
|
||||
"--version", "0.1",
|
||||
"--namespace", "test-namespace",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "cleanup-on-fail-from-default",
|
||||
defaults: HelmSpec{
|
||||
CleanupOnFail: true,
|
||||
},
|
||||
release: &ReleaseSpec{
|
||||
Chart: "test/chart",
|
||||
Version: "0.1",
|
||||
Name: "test-charts",
|
||||
Namespace: "test-namespace",
|
||||
},
|
||||
want: []string{
|
||||
"--version", "0.1",
|
||||
"--cleanup-on-fail",
|
||||
"--namespace", "test-namespace",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "tiller",
|
||||
defaults: HelmSpec{},
|
||||
|
|
|
|||
Loading…
Reference in New Issue