-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add annotation to prevent uninstalling helm chart of Job/App (#231)
Sometimes we want to remove App/Job CR but keep their helm chart running, it is a kind of soft self-uninstalling) To handle this use-case, ketch-controller looks for theketch.io/dont-uninstall-helm-chart=true annotation. If it is present on an App/Job CR and kuberentes has marked the CR for deletion, ketch controller doesn't uninstall its helm chart.
- Loading branch information
1 parent
31f7ff1
commit 4b313a6
Showing
8 changed files
with
141 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package v1beta1 | ||
|
||
import "fmt" | ||
|
||
// DontUninstallHelmChartAnnotation returns an annotation that prevents | ||
// ketch-controller from uninstalling helm chart of Application or Job. | ||
func DontUninstallHelmChartAnnotation(group string) string { | ||
return fmt.Sprintf("%s/dont-uninstall-helm-chart", group) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package controllers | ||
|
||
import ( | ||
"strconv" | ||
|
||
ketchv1 "github.com/theketchio/ketch/internal/api/v1beta1" | ||
) | ||
|
||
// uninstallHelmChart checks if there is a special annotation that | ||
// prevents ketch-controller from uninstalling helm chart of App/Job. | ||
func uninstallHelmChart(group string, annotations map[string]string) bool { | ||
if len(annotations) == 0 { | ||
return true | ||
} | ||
value, ok := annotations[ketchv1.DontUninstallHelmChartAnnotation(group)] | ||
if !ok { | ||
return true | ||
} | ||
keepChart, err := strconv.ParseBool(value) | ||
if err != nil { | ||
return true | ||
} | ||
return !keepChart | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package controllers | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func Test_uninstallHelmChart(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
group string | ||
annotations map[string]string | ||
wantUninstall bool | ||
}{ | ||
{ | ||
name: "dont uninstall", | ||
group: "theketch.io", | ||
annotations: map[string]string{ | ||
"theketch.io/dont-uninstall-helm-chart": "true", | ||
}, | ||
wantUninstall: false, | ||
}, | ||
{ | ||
name: "uninstall", | ||
group: "theketch.io", | ||
annotations: map[string]string{ | ||
"theketch.io/dont-uninstall-helm-chart": "some-value", | ||
}, | ||
wantUninstall: true, | ||
}, | ||
{ | ||
name: "no annotation - uninstall", | ||
group: "theketch.io", | ||
annotations: map[string]string{}, | ||
wantUninstall: true, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
uninstall := uninstallHelmChart(tt.group, tt.annotations) | ||
require.Equal(t, tt.wantUninstall, uninstall) | ||
}) | ||
} | ||
} |