-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
objects with resource policy "keep" should use the annotation-based w…
…atch
- Loading branch information
1 parent
73b36a6
commit ebd3041
Showing
7 changed files
with
134 additions
and
46 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
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,13 @@ | ||
package manifestutil_test | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func TestManifest(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "Manifest Suite") | ||
} |
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,19 @@ | ||
package manifestutil | ||
|
||
import ( | ||
"strings" | ||
|
||
"helm.sh/helm/v3/pkg/kube" | ||
) | ||
|
||
func HasResourcePolicyKeep(annotations map[string]string) bool { | ||
if annotations == nil { | ||
return false | ||
} | ||
resourcePolicyType, ok := annotations[kube.ResourcePolicyAnno] | ||
if !ok { | ||
return false | ||
} | ||
resourcePolicyType = strings.ToLower(strings.TrimSpace(resourcePolicyType)) | ||
return resourcePolicyType == kube.KeepPolicy | ||
} |
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,41 @@ | ||
package manifestutil_test | ||
|
||
import ( | ||
"strings" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
"helm.sh/helm/v3/pkg/kube" | ||
|
||
"github.com/joelanford/helm-operator/pkg/manifestutil" | ||
) | ||
|
||
var _ = Describe("HasResourcePolicyKeep", func() { | ||
It("returns false for nil annotations", func() { | ||
Expect(manifestutil.HasResourcePolicyKeep(nil)).To(BeFalse()) | ||
}) | ||
It("returns true on base case", func() { | ||
annotations := map[string]string{kube.ResourcePolicyAnno: kube.KeepPolicy} | ||
Expect(manifestutil.HasResourcePolicyKeep(annotations)).To(BeTrue()) | ||
}) | ||
It("returns false when annotation key is not found", func() { | ||
annotations := map[string]string{"not-" + kube.ResourcePolicyAnno: kube.KeepPolicy} | ||
Expect(manifestutil.HasResourcePolicyKeep(annotations)).To(BeFalse()) | ||
}) | ||
It("returns false when annotation value is not 'keep'", func() { | ||
annotations := map[string]string{"not-" + kube.ResourcePolicyAnno: "not-" + kube.KeepPolicy} | ||
Expect(manifestutil.HasResourcePolicyKeep(annotations)).To(BeFalse()) | ||
}) | ||
It("returns true when annotation is uppercase", func() { | ||
annotations := map[string]string{kube.ResourcePolicyAnno: strings.ToUpper(kube.KeepPolicy)} | ||
Expect(manifestutil.HasResourcePolicyKeep(annotations)).To(BeTrue()) | ||
}) | ||
It("returns true when annotation is has whitespace prefix and/or suffix", func() { | ||
annotations := map[string]string{kube.ResourcePolicyAnno: " " + kube.KeepPolicy + " "} | ||
Expect(manifestutil.HasResourcePolicyKeep(annotations)).To(BeTrue()) | ||
}) | ||
It("returns true when annotation is uppercase and has whitespace prefix and/or suffix", func() { | ||
annotations := map[string]string{kube.ResourcePolicyAnno: " " + strings.ToUpper(kube.KeepPolicy) + " "} | ||
Expect(manifestutil.HasResourcePolicyKeep(annotations)).To(BeTrue()) | ||
}) | ||
}) |
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