-
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
Fix behavior when the kube api might omit some more fields #128
Conversation
This is another situation where the kube api server may omit "empty" values in some of the default kubernetes objects. This commit also refactors the test code for re-use. Refs: - https://issues.redhat.com/browse/ACM-5132 Signed-off-by: Justin Kulikauskas <jkulikau@redhat.com>
Creating a configuration policy that "belongs" to a parent policy is slightly tricky, because it needs an owner reference with a UID. A common function makes this a bit easier. Signed-off-by: Justin Kulikauskas <jkulikau@redhat.com>
Similar to some other fixes we had for empty bools, strings, and ints. Refs: - https://issues.redhat.com/browse/ACM-5132 Signed-off-by: Justin Kulikauskas <jkulikau@redhat.com>
/hold Looking for any maps to see if omitempty is handled nicely there |
@@ -115,6 +115,10 @@ func equalObjWithSort(mergedObj interface{}, oldObj interface{}) (areEqual bool) | |||
// this includes the case where oldObj is nil | |||
return false | |||
case []interface{}: | |||
if len(mergedObj) == 0 && oldObj == nil { |
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.
_, 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 comment
The reason will be displayed to describe this comment to others. Learn more.
great! createConfigPolicyWithParent
Interesting, the kube validation of events must have changed between kubernetes versions. On 1.19, the test runs into this:
For anyone curious, the change was in kube 1.20, compare:
So creating the event in namespace "default" only sometimes works (1.20+). But "kube-system" will work on older versions and newer versions. |
It was tricky to find an example of this. Most optional structs I found would get populated with some default values, meaning they wouldn't be omitted by the kube api. Signed-off-by: Justin Kulikauskas <jkulikau@redhat.com>
2b96a71
to
d7d1e0a
Compare
/unhold I'm happy with this now |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: JustinKuli, yiraeChristineKim The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
These are two more situations where the kube api server may omit "empty" values in some of the default kubernetes objects.
https://issues.redhat.com/browse/ACM-5132