-
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 (#83)
- Loading branch information
1 parent
73b36a6
commit c5c2a0b
Showing
7 changed files
with
182 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,29 @@ | ||
/* | ||
Copyright 2021 The Operator-SDK Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
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,35 @@ | ||
/* | ||
Copyright 2021 The Operator-SDK Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
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,57 @@ | ||
/* | ||
Copyright 2021 The Operator-SDK Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
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