mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 03:41:45 +00:00
Merge pull request #96369 from gautierdelorme/fix-objects-preserve-unknown-fields
Fix kubectl CRD validation with preserve-unknown-fields objects
This commit is contained in:
commit
eb7bc22b95
@ -172,8 +172,7 @@ func TestNewBuilder(t *testing.T) {
|
||||
},
|
||||
"embedded-object": {
|
||||
"x-kubernetes-embedded-resource": true,
|
||||
"x-kubernetes-preserve-unknown-fields": true,
|
||||
"type":"object"
|
||||
"x-kubernetes-preserve-unknown-fields": true
|
||||
}
|
||||
},
|
||||
"x-kubernetes-group-version-kind":[{"group":"bar.k8s.io","kind":"Foo","version":"v1"}]
|
||||
|
@ -81,6 +81,13 @@ func ToStructuralOpenAPIV2(in *structuralschema.Structural) *structuralschema.St
|
||||
changed = true
|
||||
}
|
||||
|
||||
if s.XPreserveUnknownFields && s.Type == "object" {
|
||||
// similar as above, kubectl doesn't properly handle object fields with `x-kubernetes-preserve-unknown-fields: true`
|
||||
s.Type = ""
|
||||
|
||||
changed = true
|
||||
}
|
||||
|
||||
for f, fs := range s.Properties {
|
||||
if fs.Nullable {
|
||||
s.ValueValidation.Required, changed = filterOut(s.ValueValidation.Required, f)
|
||||
|
@ -666,8 +666,7 @@ func Test_ConvertJSONSchemaPropsToOpenAPIv2SchemaByType(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
expected: withVendorExtensions(new(spec.Schema), "x-kubernetes-preserve-unknown-fields", true).
|
||||
Typed("object", ""),
|
||||
expected: withVendorExtensions(new(spec.Schema), "x-kubernetes-preserve-unknown-fields", true),
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -231,7 +231,7 @@ var _ = SIGDescribe("CustomResourcePublishOpenAPI [Privileged:ClusterAdmin]", fu
|
||||
ns := fmt.Sprintf("--namespace=%v", f.Namespace.Name)
|
||||
|
||||
ginkgo.By("client-side validation (kubectl create and apply) allows request with any unknown properties")
|
||||
randomCR := fmt.Sprintf(`{%s,"spec":{"b":[{"c":"d"}]}}`, meta)
|
||||
randomCR := fmt.Sprintf(`{%s,"spec":{"a":null,"b":[{"c":"d"}]}}`, meta)
|
||||
if _, err := framework.RunKubectlInput(f.Namespace.Name, randomCR, ns, "create", "-f", "-"); err != nil {
|
||||
framework.Failf("failed to create random CR %s for CRD that allows unknown properties in a nested object: %v", randomCR, err)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user