-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
✨add CodecFactoryOptionsMutators for codecfactory #3048
base: main
Are you sure you want to change the base?
Conversation
Welcome @Chaunceyctx! |
Hi @Chaunceyctx. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
/ping gently @vincepri @sbueringer PTAL, thanks a lot :) |
4fff6e3
to
6d063ae
Compare
/ping gently @troy0820 |
pkg/client/client.go
Outdated
@@ -150,7 +153,7 @@ func newClient(config *rest.Config, options Options) (*client, error) { | |||
config: config, | |||
scheme: options.Scheme, | |||
mapper: options.Mapper, | |||
codecs: serializer.NewCodecFactory(options.Scheme), | |||
codecs: serializer.NewCodecFactory(options.Scheme, options.CodecFactoryOptionsMutators...), |
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.
What is the user-facing difference in impact between configuring strict here vs. using client.WithFieldValdation to set FieldValidation in the Options structs?
Is it that the latter only affects Create/Update/patch?
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.
What is the user-facing difference in impact between configuring strict here vs. using client.WithFieldValdation to set FieldValidation in the Options structs?
Is it that the latter only affects Create/Update/patch?
@sbueringer thanks a lot for feedback :) Yes, FieldValidation
will be used in CreateOptions/UpdateOptions/PatchOptions. And these Options will tell apiserver how to select mode of decodeSerializer(strict or not strict), like: https://github.com/kubernetes/kubernetes/blob/6746df77f2376c6bc1fd0de767d2a94e6bd6cec1/staging/src/k8s.io/apiserver/pkg/endpoints/handlers/update.go#L109
So client also need to know how to select mode of decodeSerializer and use strict mode of decodeSerializer to avoid the aforementioned issue.
I will address failed ci job.
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.
That seems like a pretty big footgun though, because you became unable to tolerate any skew between the CRD and the controller, even for backwards-compatible changes?
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.
@alvaroaleman thanks for your comment :). IMO, these options can be true or false which depends on the user's use case. For my scenario described above, I have deployed a workload similar to StatefulSet
and used ControllerRevision
to record the workload.spec
. If the workload.spec
changes (some fields have been dropped in the v2 workload controller), it will lead to rolling update of the workload, impacting production. Therefore, I need to explicitly use the strict deserializer and any field added/dropped should not be permitted. For other scenarios, it's not necessary to set these options.
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.
Yeah but this is a cache-wide setting, using errors in the cache deserialization as a marker just seems like a very brittle approach
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 makes sense. I will find other approaches to implement it like ByObject
field:)
/ok-to-test |
@sbueringer excuse me, could you give me some hints to address this failed ci job? I am a noob for go-apidiff tool |
08062e5
to
5749d97
Compare
/retest |
fields added need to be comparable. @sbueringer PTAL again, thanks a lot :) |
5749d97
to
7d5d248
Compare
Do we need to add any tests for this @sbueringer ? |
pkg/cache/cache.go
Outdated
@@ -140,6 +140,10 @@ type Options struct { | |||
// Scheme is the scheme to use for mapping objects to GroupVersionKinds | |||
Scheme *runtime.Scheme | |||
|
|||
// CodecFactoryStrict/CodecFactoryPretty are used to indicate whether enable Strict/Pretty mode of CodecFactory | |||
CodecFactoryStrict bool | |||
CodecFactoryPretty bool |
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.
What is the point of CodecFactoryPretty
, when would someone want this?
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.
"strict" and "pretty" are both options of Codecfactory, so for the sake of completeness, I added these two variables together. But I indeed didn't think of practical scenarios for "pretty".
pkg/client/client.go
Outdated
@@ -150,7 +153,7 @@ func newClient(config *rest.Config, options Options) (*client, error) { | |||
config: config, | |||
scheme: options.Scheme, | |||
mapper: options.Mapper, | |||
codecs: serializer.NewCodecFactory(options.Scheme), | |||
codecs: serializer.NewCodecFactory(options.Scheme, options.CodecFactoryOptionsMutators...), |
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.
That seems like a pretty big footgun though, because you became unable to tolerate any skew between the CRD and the controller, even for backwards-compatible changes?
7d5d248
to
caa3e39
Compare
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: Chaunceyctx The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
caa3e39
to
330bbcc
Compare
I have changed the implementation so that the strict mode of codec is restricted to a specific GroupVersionKind (GVK) instead of applying to the cache-level. @alvaroaleman PTAL, thank you so much :) |
@Chaunceyctx: The following test failed, say
Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here. |
What does this do, and why do we need it?
we have a production scenario:
the struct corresponding to crd declared in the v1 version of the controller includes
field A
. However, when we upgrade the v1 controller to v2,field A
is removed from the struct, like:v1 struct:
v2 struct:
So we want the controller to realize this error during data deserialization, so we need to switch the corresponding serializer to
strict
mode.