-
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
Make selector immutable for v1beta2 deployment, replicaset and daemonset prior update #50719
Make selector immutable for v1beta2 deployment, replicaset and daemonset prior update #50719
Conversation
// We assume API version is not v1beta2 if no RequestInfo is found | ||
requestInfo, found := genericapirequest.RequestInfoFrom(ctx) | ||
if found && requestInfo.APIVersion == "v1beta2" { | ||
newDeployment.Spec = oldDeployment.Spec |
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.
// update is not allowed to set spec for v1beta2 | ||
// We assume API version is not v1beta2 if no RequestInfo is found | ||
requestInfo, found := genericapirequest.RequestInfoFrom(ctx) | ||
if found && requestInfo.APIVersion == "v1beta2" { |
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.
For now, it affects only v1beta2
API version. In future, we may need to change it to v1
or have a range like greater than v1
.
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.
You can't clear the entire spec, this disallows all relevant changes to the API object. You might be able to clear the selector change. Is this the method that you discussed with @erictune?
950355e
to
7ac5c2f
Compare
// update is not allowed to set Spec.Selector for v1beta2 | ||
// we assume it is not v1beta2 if no API group and/or version is found in RequestInfo | ||
// TODO(#50791): after v1beta1 is retired, move selector immutability check to validation codes | ||
requestInfo, found := genericapirequest.RequestInfoFrom(ctx) |
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.
7ac5c2f
to
387b01a
Compare
387b01a
to
f625dff
Compare
if err != nil { | ||
t.Errorf("Unexpected error for url: %s %v", test.url, err) | ||
} | ||
if !apiRequestInfo.IsResourceRequest { |
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.
@kow3ns
After writing the unit test, i think we can leave out the API group when determining whether to ignore changes to Spec.Selector
. The main reason is due to how RequestInfo
works.
IsResourceRequest
returns true for requests to API resources, like /api/v1/...
, and false for non-resource endpoints like /api
, /healthz
, and /swaggerapi
. In other words, something like /api/v1beta2/...
works, but not /api/apps/v1beta2/...
(additional apps
after api
) or /apps/v1beta2/...
(do not start with api
).
Furthermore, we will have the silent ignore for v1
in future, which will be /api/v1/...
that works perfectly with how RequestInfo
works. Moreover, v1beta2
only exists for apps
group, which does not justify checking the API group.
WDYT?
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.
These controllers never existed in the groupless /api/
prefix, so your test shouldn't expect those inputs to work. Specifically, you want to make sure that /apis/extensions/v1beta1
allows mutation, and /apis/apps/v1beta2
does not. If we decide to plan ahead for /apis/apps/v1
you could test for that too, but I don't know if that's decided yet.
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.
@enisoc Good point! Thanks for the clarification. I will test for /apis/extensions/v1beta1
and /apis/apps/v1beta2
.
// we assume it is not v1beta2 if no API version is found in RequestInfo | ||
// TODO(#50791): after v1beta1 is retired, move selector immutability check to validation codes | ||
requestInfo, found := genericapirequest.RequestInfoFrom(ctx) | ||
if found && requestInfo.APIVersion == "v1beta2" { |
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.
Refer this comment for why checking API group may be unnecessary.
this is definitely worth a release note |
fdc9a9b
to
9929e03
Compare
/lgtm |
/approve Based on discussion in linked issue and general agreement that we can potentially relax / add better changes in the future. |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: crimsonfaith91, enisoc, liggitt, smarterclayton Associated issue: 50808 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 |
Automatic merge from submit-queue (batch tested with PRs 50719, 51216, 50212, 51408, 51381) |
What this PR does / why we need it:
This PR ensures controller selector is immutable for deployment and replicaset prior update by ignoring any change to
Spec
.Which issue this PR fixes (optional, in
fixes #<issue number>(, fixes #<issue_number>, ...)
format, will close that issue when PR gets merged): fixes #50808Special notes for your reviewer:
This will be a breaking change.
Release note: