-
Notifications
You must be signed in to change notification settings - Fork 39.6k
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
apiextensions: validate list-type map+set uniqueness in CRs #84920
apiextensions: validate list-type map+set uniqueness in CRs #84920
Conversation
590c837
to
5cc374e
Compare
5cc374e
to
7be2000
Compare
7be2000
to
26b38de
Compare
/assign |
This PR may require API review. If so, when the changes are ready, complete the pre-review checklist and request an API review. Status of requested reviews is tracked in the API Review project. |
staging/src/k8s.io/apiextensions-apiserver/pkg/registry/customresource/strategy.go
Show resolved
Hide resolved
staging/src/k8s.io/apiextensions-apiserver/test/integration/listtype_test.go
Outdated
Show resolved
Hide resolved
staging/src/k8s.io/apiextensions-apiserver/test/integration/listtype_test.go
Outdated
Show resolved
Hide resolved
staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/schema/listtype/validation_test.go
Show resolved
Hide resolved
staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/schema/listtype/validation.go
Outdated
Show resolved
Hide resolved
staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/schema/listtype/validation.go
Show resolved
Hide resolved
staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/schema/listtype/validation.go
Show resolved
Hide resolved
staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/schema/listtype/validation.go
Show resolved
Hide resolved
staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/schema/listtype/validation.go
Outdated
Show resolved
Hide resolved
staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/schema/listtype/validation.go
Show resolved
Hide resolved
staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/schema/listtype/validation.go
Show resolved
Hide resolved
staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/schema/listtype/validation.go
Outdated
Show resolved
Hide resolved
staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/schema/listtype/validation.go
Show resolved
Hide resolved
staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/schema/listtype/validation.go
Show resolved
Hide resolved
staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/schema/listtype/validation.go
Show resolved
Hide resolved
staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/schema/listtype/validation_test.go
Show resolved
Hide resolved
staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/schema/listtype/validation_test.go
Outdated
Show resolved
Hide resolved
staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/schema/listtype/validation_test.go
Outdated
Show resolved
Hide resolved
@apelisse addressed your comments. |
0965aee
to
5c82b80
Compare
return nil, nil | ||
} | ||
if len(obj) == 2 { | ||
if reflect.DeepEqual(obj[0], obj[1]) { |
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.
are there cases where this would return false for complex array or map objects, but json-marshalling and comparing would be identical?
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.
json.Marshal
is the inverse of json.Unmarshal
. If both values are the result of json.Unmarshal
then this will not happen.
What do you have in mind? Our patch logic?
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.
more issues like json-iterator/go#323, where json-iterator normalizes on marshal as opposed to encoding/json normalizing on both unmarshal/marshal
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.
ic. Suggestion? Marshal again?
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 is definitely simpler to reason about; that's what I would do to start
I have a couple of additional comments. I'm really not convinced that we want Second, I was discussion ratcheting with Daniel, and forcing the created objects to pass this validation only works if we assume that no controller/system is currently creating invalid objects. This change would break such a controller? |
All this is done via ratcheting validation, i.e. we enforce required or a default. We forbid nullable: #88076. Please review. |
This is what we always do in those cases, ratcheting validation. It is the very reason why this issue is marked urgent for months. The more we wait (1.18 is around the corner) the more controllers will exist. I bet the number is zero today. |
Anyone defining a CRD that uses list-type: map/set must be able to rely on the documented semantics (we rely on them ourselves in server-side-apply). It is very important we not allow data that violates those semantics, and do so as soon as possible. |
That's what we settled on. Disallowing nullable and making the key attributes either be required or defaulted gives this set validation reasonable inputs to work with, and allows evolution or recovery from underspecified key sets (e.g. an underspecified item schema for a port realizes in the future it needs a protocol field that should be added to the item key specification, and needs to provide a default for existing persisted data that lacked that field). |
66f5e8c
to
99b4ec1
Compare
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: liggitt, sttts 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 |
99b4ec1
to
ea45da7
Compare
New changes are detected. LGTM label has been removed. |
/retest Review the full test history for this PR. Silence the bot with an |
1 similar comment
/retest Review the full test history for this PR. Silence the bot with an |
/kind api-change
/kind bug
Fixes #84724.