-
Notifications
You must be signed in to change notification settings - Fork 40k
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 Unstructured field accessor #48065
Fix Unstructured field accessor #48065
Conversation
@@ -136,8 +136,8 @@ func getNestedInt64(obj map[string]interface{}, fields ...string) int64 { | |||
} | |||
|
|||
func getNestedInt64Pointer(obj map[string]interface{}, fields ...string) *int64 { | |||
if str, ok := getNestedField(obj, fields...).(*int64); ok { | |||
return str | |||
if str, ok := getNestedField(obj, fields...).(int64); ok { |
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.
This would correctly handle reading null
?
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.
@@ -136,8 +136,8 @@ func getNestedInt64(obj map[string]interface{}, fields ...string) int64 { | |||
} | |||
|
|||
func getNestedInt64Pointer(obj map[string]interface{}, fields ...string) *int64 { | |||
if str, ok := getNestedField(obj, fields...).(*int64); ok { |
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.
this works as long as our number-preserving json unmarshaler is used (stdlib turns numbers into float64)
also, getNestedSlice and getNestedMap assume values are strings and silently drop non-strings... the names should at least be updated so callers know their assumptions
}`, | ||
verify: func(u Unstructured) { | ||
assertEqual("test", u.GetName(), "name") | ||
assertNil(u.GetDeletionGracePeriodSeconds(), "deletionGracePeriodSeconds") |
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.
ah, I see. ok.
what does SetDeletionTimestamp() do? It looks like it stores a string in the unstructured object, which would mean GetDeletionTimestamp() would not be able to read a value set with SetDeletionTimestamp(). Should make sure that the getters/setters work together with both null and present values. |
Oh boy, good catch. Hrm. |
Turns out the problem runs a little deeper: DeletionGracePeriodSeconds is stored as a value type when the Unstructured data is marshalled from JSON, while a pointer type is stored via SetDeletionGracePeriodSeconds. Working on a fix for this as well as reflective unit test coverage for all the |
This is similar to #46683. |
Thanks, had no idea about that test file. How should I proceed? Should I add coverage to the existing tests?
|
I've moved my test code over to the existing suite. |
@ironcladlou I have no idea why those tests are in two separate places - I've had the same question :) |
Looks like this integration test was inadvertently working around the grace period accessor bug. Fixed the test in d5d9c37dea97be5ef3bc2d6f41be6e98dc45ab90. |
@ash2k mind reviewing this? |
@ironcladlou wow, just read the comment from your last commit - this is the behaviour I was actually expecting when I initially wrote this test. See the comment from @deads2k #46439 (comment) - it implies that the final delete is necessary to actually remove the object after all finalizers have been cleared. And I thought it is something else (other controller?) that does this normally, but not during integration tests. |
@ironcladlou maybe it is better to remove the field when the pointer is nil? This will be consistent with how unmarshaling works - it does not create a field with |
In this case I think delete-on-update depends primarily on whether GC is enabled for a given type of registry. In the integration tests right now, GC is definitely enabled for the CRD I could also be totally wrong and missing something 😁 /cc @deads2k |
I agree with you, but I think we're already dealing with some internal inconsistency in that regard: SetOwnerReferences adheres to your proposed omission behavior, while SetInitializers, SetLabels, SetAnnotations, and SetDeletionTimestamp will retain keys and assign If we all agree that /cc @deads2k |
Hmmm... These have gone through numerous iterations and the original namespace code issued a second delete. I actually can't be sure it wasn't a side-effect of a bug. The rest of this code looks correct, so we'll merge note the bug fix. @ironcladlou add a release-note for it in this pull please. |
I think this moves in the right direction. I'm open to changing the nil values for consistency with normal marshalling, but I see that as a followup (open an issue to track, please). lgtm, squash up a bit for merge. |
d5d9c37
to
4f91c4b
Compare
Fix the Unstructured GetDeletionGracePeriodSeconds accessor which was always returning nil regardless of the underlying stored value. The field value always appearing nil prevents Custom Resource instances from being deleted when garbage collection is enabled for CRs and when DeletePropagationOrphan is used. More generally, this fix means that delete-on-update now works for CR instances. Add some test coverage for Unstructured metadata deserialization. The Unstructured DeletionGracePeriodSeconds field marshals as a value type from JSON and as a pointer type via SetDeletionGracePeriodSeconds. The GetDeletionGracePeriodSeconds method now supports handling both int64 and *int64 values so that either underlying value can be returned. Add a reflection-based unit test which attempts to exercise all the Object Get/Set methods for nil handling.
4f91c4b
to
547d820
Compare
/lgtm |
/retest |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: deads2k, ironcladlou Assign the PR to them by writing Associated issue requirement bypassed by: deads2k The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these OWNERS Files:
You can indicate your approval by writing |
Split out #48211 to track refactoring nil handling for Object related fields. |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: deads2k, ironcladlou Assign the PR to them by writing Associated issue requirement bypassed by: deads2k The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these OWNERS Files:
You can indicate your approval by writing |
4 similar comments
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: deads2k, ironcladlou Assign the PR to them by writing Associated issue requirement bypassed by: deads2k The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these OWNERS Files:
You can indicate your approval by writing |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: deads2k, ironcladlou Assign the PR to them by writing Associated issue requirement bypassed by: deads2k The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these OWNERS Files:
You can indicate your approval by writing |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: deads2k, ironcladlou Assign the PR to them by writing Associated issue requirement bypassed by: deads2k The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these OWNERS Files:
You can indicate your approval by writing |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: deads2k, ironcladlou Assign the PR to them by writing Associated issue requirement bypassed by: deads2k The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these OWNERS Files:
You can indicate your approval by writing |
@k8s-bot its the old apimachinery tests. Stop freaking out. |
@ironcladlou that package of old tests exists because we had some tests which relied on kube API types. I think that @sttts gave us an alternative test group in apimachinery since, but I we haven't revisited it. @shiywang if you're interested in un-cycling those and moving them into apimachinery, let me know. |
Automatic merge from submit-queue (batch tested with PRs 48183, 45611, 48065) |
@deads2k I would like to work on that. checking now : ) |
Automatic merge from submit-queue (batch tested with PRs 47700, 48464, 48502) Add a refreshing discovery client Introduce a discovery client (implementing `CachedDiscoveryInterface`) which caches discovery information in memory and which can be actively refreshed by the user. This implementation fetches from discovery upon refresh and could later be improved to maintain updates from a watch. Extracted from #47665 and #46000 to help reduce the scope of #48065. ```release-note NONE ```
Automatic merge from submit-queue (batch tested with PRs 49538, 49708, 47665, 49750, 49528) Enable garbage collection of custom resources Enhance the garbage collector to periodically refresh the resources it monitors (via discovery) to enable custom resource definition GC (addressing #44507 and reverting #47432). This is a replacement for #46000. /cc @lavalamp @deads2k @sttts @caesarxuchao /ref #48065 ```release-note The garbage collector now supports custom APIs added via CustomeResourceDefinition or aggregated apiservers. Note that the garbage collector controller refreshes periodically, so there is a latency between when the API is added and when the garbage collector starts to manage it. ```
Fix the Unstructured GetDeletionGracePeriodSeconds accessor which was
always returning nil regardless of the underlying stored value. The
field value always appearing nil prevents Custom Resource instances
from being deleted when garbage collection is enabled for CRs and
when DeletePropagationOrphan is used. More generally, this fix means that
delete-on-update now works for CR instances.
Add some test coverage for Unstructured metadata deserialization.
The Unstructured DeletionGracePeriodSeconds field marshals as a value
type from JSON and as a pointer type via SetDeletionGracePeriodSeconds.
The GetDeletionGracePeriodSeconds method now supports handling both
int64 and *int64 values so that either underlying value can be returned.
Add a reflection-based unit test which attempts to exercise all the
Object Get/Set methods for nil handling.