Skip to content
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

🐛 Allow setting PreserveUnknownFields at both type and field level #689

Merged
merged 1 commit into from Jun 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions pkg/crd/flatten.go
Expand Up @@ -143,6 +143,8 @@ func flattenAllOfInto(dst *apiext.JSONSchemaProps, src apiext.JSONSchemaProps, e
dstProps.Schema = &apiext.JSONSchemaProps{}
}
flattenAllOfInto(dstProps.Schema, *srcProps.Schema, errRec)
case "XPreserveUnknownFields":
dstField.Set(srcField)
// NB(directxman12): no need to explicitly handle nullable -- false is considered to be the zero value
// TODO(directxman12): src isn't necessarily the field value -- it's just the most recent allOf entry
default:
Expand Down
6 changes: 5 additions & 1 deletion pkg/crd/testdata/cronjob_types.go
Expand Up @@ -134,9 +134,13 @@ type CronJobSpec struct {
// +kubebuilder:validation:nullable
UnprunedEmbeddedResource runtime.RawExtension `json:"unprunedEmbeddedResource"`

// This tests that a type-level pruning maker works.
// This tests that a type-level pruning marker works.
UnprunedFromType Preserved `json:"unprunedFomType"`

// This tests that a type-level pruning marker combined with a field-level pruning marker works.
// +kubebuilder:pruning:PreserveUnknownFields
UnprunedFromTypeAndField Preserved `json:"unprunedFomTypeAndField"`

// This tests that associative lists work.
// +listType=map
// +listMapKey=name
Expand Down
8 changes: 7 additions & 1 deletion pkg/crd/testdata/testdata.kubebuilder.io_cronjobs.yaml
Expand Up @@ -7344,7 +7344,12 @@ spec:
x-kubernetes-embedded-resource: true
x-kubernetes-preserve-unknown-fields: true
unprunedFomType:
description: This tests that a type-level pruning maker works.
description: This tests that a type-level pruning marker works.
type: object
x-kubernetes-preserve-unknown-fields: true
unprunedFomTypeAndField:
description: This tests that a type-level pruning marker combined
with a field-level pruning marker works.
type: object
x-kubernetes-preserve-unknown-fields: true
unprunedJSON:
Expand Down Expand Up @@ -7381,6 +7386,7 @@ spec:
- twoOfAKindPart1
- unprunedEmbeddedResource
- unprunedFomType
- unprunedFomTypeAndField
- unprunedJSON
type: object
status:
Expand Down