-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix behavior when the kube api might omit some more fields #128
Merged
openshift-merge-robot
merged 4 commits into
open-cluster-management-io:main
from
JustinKuli:5132-omitempty-array
May 1, 2023
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
5778c54
Add test for possibly omitted array
JustinKuli 14a11f9
Use common parent policy creation function
JustinKuli 30d0179
Fix constantly updating objects with an empty list
JustinKuli d7d1e0a
Fix constantly updating objects with a null struct
JustinKuli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,21 +36,8 @@ const ( | |
|
||
var _ = Describe("Testing compliance event formatting", func() { | ||
It("Records the right events for a policy that is always compliant", func() { | ||
By("Creating parent policy " + case15AlwaysCompliantParentName + " on " + testNamespace) | ||
utils.Kubectl("apply", "-f", case15AlwaysCompliantParentYaml, "-n", testNamespace) | ||
parent := utils.GetWithTimeout(clientManagedDynamic, gvrPolicy, | ||
case15AlwaysCompliantParentName, testNamespace, true, defaultTimeoutSeconds) | ||
Expect(parent).NotTo(BeNil()) | ||
|
||
By("Creating compliant policy " + case15AlwaysCompliantName + " on " + testNamespace + " with parent " + | ||
case15AlwaysCompliantParentName) | ||
plcDef := utils.ParseYaml(case15AlwaysCompliantYaml) | ||
ownerRefs := plcDef.GetOwnerReferences() | ||
ownerRefs[0].UID = parent.GetUID() | ||
plcDef.SetOwnerReferences(ownerRefs) | ||
_, err := clientManagedDynamic.Resource(gvrConfigPolicy).Namespace(testNamespace). | ||
Create(context.TODO(), plcDef, metav1.CreateOptions{}) | ||
Expect(err).To(BeNil()) | ||
createConfigPolicyWithParent(case15AlwaysCompliantParentYaml, case15AlwaysCompliantParentName, | ||
case15AlwaysCompliantYaml) | ||
|
||
plc := utils.GetWithTimeout(clientManagedDynamic, gvrConfigPolicy, | ||
case15AlwaysCompliantName, testNamespace, true, defaultTimeoutSeconds) | ||
|
@@ -81,21 +68,8 @@ var _ = Describe("Testing compliance event formatting", func() { | |
Expect(nonCompParentEvents).To(BeEmpty()) | ||
}) | ||
It("Records the right events for a policy that is never compliant", func() { | ||
By("Creating parent policy " + case15NeverCompliantParentName + " on " + testNamespace) | ||
utils.Kubectl("apply", "-f", case15NeverCompliantParentYaml, "-n", testNamespace) | ||
parent := utils.GetWithTimeout(clientManagedDynamic, gvrPolicy, | ||
case15NeverCompliantParentName, testNamespace, true, defaultTimeoutSeconds) | ||
Expect(parent).NotTo(BeNil()) | ||
|
||
By("Creating noncompliant policy " + case15NeverCompliantName + " on " + testNamespace + " with parent " + | ||
case15NeverCompliantParentName) | ||
plcDef := utils.ParseYaml(case15NeverCompliantYaml) | ||
ownerRefs := plcDef.GetOwnerReferences() | ||
ownerRefs[0].UID = parent.GetUID() | ||
plcDef.SetOwnerReferences(ownerRefs) | ||
_, err := clientManagedDynamic.Resource(gvrConfigPolicy).Namespace(testNamespace). | ||
Create(context.TODO(), plcDef, metav1.CreateOptions{}) | ||
Expect(err).To(BeNil()) | ||
createConfigPolicyWithParent(case15NeverCompliantParentYaml, case15NeverCompliantParentName, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. great! createConfigPolicyWithParent |
||
case15NeverCompliantYaml) | ||
|
||
plc := utils.GetWithTimeout(clientManagedDynamic, gvrConfigPolicy, | ||
case15NeverCompliantName, testNamespace, true, defaultTimeoutSeconds) | ||
|
@@ -126,21 +100,8 @@ var _ = Describe("Testing compliance event formatting", func() { | |
Expect(nonCompParentEvents).NotTo(BeEmpty()) | ||
}) | ||
It("Records events for a policy that becomes compliant", func() { | ||
By("Creating parent policy " + case15BecomesCompliantParentName + " on " + testNamespace) | ||
utils.Kubectl("apply", "-f", case15BecomesCompliantParentYaml, "-n", testNamespace) | ||
parent := utils.GetWithTimeout(clientManagedDynamic, gvrPolicy, | ||
case15BecomesCompliantParentName, testNamespace, true, defaultTimeoutSeconds) | ||
Expect(parent).NotTo(BeNil()) | ||
|
||
By("Creating noncompliant policy " + case15BecomesCompliantName + " on " + testNamespace + " with parent " + | ||
case15BecomesCompliantParentName) | ||
plcDef := utils.ParseYaml(case15BecomesCompliantYaml) | ||
ownerRefs := plcDef.GetOwnerReferences() | ||
ownerRefs[0].UID = parent.GetUID() | ||
plcDef.SetOwnerReferences(ownerRefs) | ||
_, err := clientManagedDynamic.Resource(gvrConfigPolicy).Namespace(testNamespace). | ||
Create(context.TODO(), plcDef, metav1.CreateOptions{}) | ||
Expect(err).To(BeNil()) | ||
createConfigPolicyWithParent(case15BecomesCompliantParentYaml, case15BecomesCompliantParentName, | ||
case15BecomesCompliantYaml) | ||
|
||
plc := utils.GetWithTimeout(clientManagedDynamic, gvrConfigPolicy, | ||
case15BecomesCompliantName, testNamespace, true, defaultTimeoutSeconds) | ||
|
@@ -176,21 +137,8 @@ var _ = Describe("Testing compliance event formatting", func() { | |
Expect(compParentEvents).NotTo(BeEmpty()) | ||
}) | ||
It("Records events for a policy that becomes noncompliant", func() { | ||
By("Creating parent policy " + case15BecomesNonCompliantParentName + " on " + testNamespace) | ||
utils.Kubectl("apply", "-f", case15BecomesNonCompliantParentYaml, "-n", testNamespace) | ||
parent := utils.GetWithTimeout(clientManagedDynamic, gvrPolicy, | ||
case15BecomesNonCompliantParentName, testNamespace, true, defaultTimeoutSeconds) | ||
Expect(parent).NotTo(BeNil()) | ||
|
||
By("Creating compliant policy " + case15BecomesNonCompliantName + " on " + testNamespace + " with parent " + | ||
case15BecomesNonCompliantParentName) | ||
plcDef := utils.ParseYaml(case15BecomesNonCompliantYaml) | ||
ownerRefs := plcDef.GetOwnerReferences() | ||
ownerRefs[0].UID = parent.GetUID() | ||
plcDef.SetOwnerReferences(ownerRefs) | ||
_, err := clientManagedDynamic.Resource(gvrConfigPolicy).Namespace(testNamespace). | ||
Create(context.TODO(), plcDef, metav1.CreateOptions{}) | ||
Expect(err).To(BeNil()) | ||
createConfigPolicyWithParent(case15BecomesNonCompliantParentYaml, case15BecomesNonCompliantParentName, | ||
case15BecomesNonCompliantYaml) | ||
|
||
plc := utils.GetWithTimeout(clientManagedDynamic, gvrConfigPolicy, | ||
case15BecomesNonCompliantName, testNamespace, true, defaultTimeoutSeconds) | ||
|
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we need this line 170, 176
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On what was line 170,
case []map[string]interface{}
, the condition here is not necessary, because the length would never be 0. If it was length zero, it would just be[]
, and that doesn't have the required type information to get into that case.I think the rest of the logic in
checkFieldsWithSort
should already cover these cases. At least, that was the intention of a663462, and what I was thinking of adding seems equivalent.