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
🐛 Metadata only objects should always preserve GroupVersionKind #1484
Conversation
/retest |
1 similar comment
/retest |
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.
It occurs to me -- we manually construct a WithoutConversionCodecFactory
, and as per kubernetes/kubernetes#80609, that's the thing, eventually, that's actually stripping the GVK. Could we just construct our own NegotiatedSerializer instead that doesn't do this and just uses the decoder directly?
Something like
cfg.NegotiatedSerializer = WithoutConversionGVKCodecFactory{CodecFactory: codecs}
// then just implement the required methods similarly to the existing codec factory, except without using WithoutVersionDecoder
pkg/builder/controller_test.go
Outdated
if _, err := apiutil.GVKForObject(o, mgr.GetScheme()); err != nil { | ||
Expect(err).NotTo(HaveOccurred()) | ||
} |
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.
nit: don't use the if
if _, err := apiutil.GVKForObject(o, mgr.GetScheme()); err != nil { | |
Expect(err).NotTo(HaveOccurred()) | |
} | |
_, err := apiutil.GVKForObject(o, mgr.GetScheme()) | |
Expect(err).NotTo(HaveOccurred()) |
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.
also, just check directly with GetObjectKind
-- no need for GVKForObject, because we shouldn't need to use the scheme.
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.
(and add a note as to why you're checking)
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.
also, assertions in other goroutines need defer GinkgoRecover()
at the top, but it's probably better to check check this when we pull it off the channel, or add a explict test case for it to better describe the desired behavior:
Context("when requesting For, Owns, and Watches as metadata", func() {
It("should watch in metadata-only form", func() { /* existing test */ })
It("should have GVK set on the metadata passed to the handlers", func() { /* new test */ })
})
pkg/handler/metadata_wrapper.go
Outdated
// WrapPartialObjectMetadataHandler wraps an event handler for partial metadata objects | ||
// which restores the GVK for PartialObjectMetadata objects which loses this information when | ||
// events come from the informer code. | ||
func WrapPartialObjectMetadataHandler(o *metav1.PartialObjectMetadata, hdl EventHandler) EventHandler { |
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'm not sure I'm comfortable exposing this in our public API -- it seems a bit hacky, and I don't want to guarantee it'll stick around as the exact implementation.
4553e57
to
927d2bc
Compare
@DirectXMan12 @alvaroaleman A little update on this issue, while the NegotiatedSerializer would have been a good solution to explore, it's way too complicated and there are limitations coming from client-go and how the serializers are being used; moreover, the api-server when querying for a metadata object returns TypeMeta filled as:
Which seems to be the expected behavior described in the associated KEP. For this reason, I updated this PR to follow a different approach: in the client and cache code we now make sure to always preserve the type information coming from the client. We were already doing something similar for Patch/Update on all calls in The only one discrepancy I can think about between the metadata client and the unstructured one is for Note: The unstructured client already behaves properly and its default (forced) serializer makes sure to not clear the TypeMeta information. |
/hold cancel |
pkg/client/apiutil/apimachinery.go
Outdated
return rest.RESTClientFor(createRestConfig(gvk, isUnstructured, baseConfig, codecs)) | ||
} | ||
|
||
// SerializerWithDecodedGVK is a CodecFactory that overrides the DecoderToVersion of a WithoutConversionCodecFactory |
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.
Can we unexport this? IMHO it is an implementation detail and doesn't really have any use for others or does it?
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.
Done!
Signed-off-by: Vince Prignano <vincepri@vmware.com>
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.
/lgtm
/approve
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: alvaroaleman, vincepri 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 |
/milestone v0.9.x |
Currently we have a bug that GVK information is not passed into mapping
functions when using the OnlyMetadata option in the builder. This patch
adds a wrapper that preserves the GVK information when events come in.
This issue is most likely caused by kubernetes/kubernetes#80609
which we have been bumping into every once in a while here and there.
Signed-off-by: Vince Prignano vincepri@vmware.com
/hold
for further review