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

🐛 Add XPreserveUnknownFields to runtime.RawExtension #683

Merged
merged 4 commits into from Jun 14, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 2 additions & 1 deletion pkg/crd/known_types.go
Expand Up @@ -74,7 +74,8 @@ var KnownPackages = map[string]PackageOverride{
"k8s.io/apimachinery/pkg/runtime": func(p *Parser, pkg *loader.Package) {
p.Schemata[TypeIdent{Name: "RawExtension", Package: pkg}] = apiext.JSONSchemaProps{
// TODO(directxman12): regexp validation for this (or get kube to support it as a format value)
Type: "object",
Type: "object",
XPreserveUnknownFields: boolPtr(true),
}
p.AddPackage(pkg) // get the rest of the types
},
Expand Down
5 changes: 4 additions & 1 deletion pkg/crd/testdata/testdata.kubebuilder.io_cronjobs.yaml
Expand Up @@ -134,6 +134,7 @@ spec:
embeddedResource:
type: object
x-kubernetes-embedded-resource: true
x-kubernetes-preserve-unknown-fields: true
failedJobsHistoryLimit:
description: The number of failed finished jobs to retain. This is
a pointer to distinguish between explicit zero and not specified.
Expand Down Expand Up @@ -7340,9 +7341,11 @@ spec:
minLength: 4
type: string
unprunedEmbeddedResource:
allOf:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks strange, not sure where I should look at.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joelanford @alvaroaleman do you have an idea where I should look in the code to find why this gets transformed into allOf ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I understand it happens in the flattener. I’m a bit lost in the code though. Any hint would be appreciated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it happens when kubebuilder:pruning:PreserveUnknownFields is present on a field and the target type. I can reproduce with any struct. Is this a bug ? Should both markers get merged together when generating the CRD ?
cc @alvaroaleman @joelanford

- x-kubernetes-preserve-unknown-fields: true
- x-kubernetes-preserve-unknown-fields: true
type: object
x-kubernetes-embedded-resource: true
x-kubernetes-preserve-unknown-fields: true
unprunedFomType:
description: This tests that a type-level pruning maker works.
type: object
Expand Down