mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
Merge pull request #109268 from liggitt/pruning-metadata
ServerSideFieldValidation: Fix bug treating metadata fields as unknown fields
This commit is contained in:
commit
6b988c516e
@ -1332,7 +1332,7 @@ func (v *unstructuredSchemaCoercer) apply(u *unstructured.Unstructured) (unknown
|
|||||||
if v.returnUnknownFieldPaths {
|
if v.returnUnknownFieldPaths {
|
||||||
pruneOpts.ReturnPruned = true
|
pruneOpts.ReturnPruned = true
|
||||||
}
|
}
|
||||||
unknownFieldPaths = structuralpruning.PruneWithOptions(u.Object, v.structuralSchemas[gv.Version], false, pruneOpts)
|
unknownFieldPaths = structuralpruning.PruneWithOptions(u.Object, v.structuralSchemas[gv.Version], true, pruneOpts)
|
||||||
structuraldefaulting.PruneNonNullableNullsWithoutDefaults(u.Object, v.structuralSchemas[gv.Version])
|
structuraldefaulting.PruneNonNullableNullsWithoutDefaults(u.Object, v.structuralSchemas[gv.Version])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -383,6 +383,8 @@ func TestPrune(t *testing.T) {
|
|||||||
"kind": "Foo",
|
"kind": "Foo",
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"name": "instance",
|
"name": "instance",
|
||||||
|
"namespace": "myns",
|
||||||
|
"labels":{"foo":"bar"},
|
||||||
"unspecified": "bar"
|
"unspecified": "bar"
|
||||||
},
|
},
|
||||||
"unspecified":"bar",
|
"unspecified":"bar",
|
||||||
@ -392,6 +394,8 @@ func TestPrune(t *testing.T) {
|
|||||||
"unspecified": "bar",
|
"unspecified": "bar",
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"name": "instance",
|
"name": "instance",
|
||||||
|
"namespace": "myns",
|
||||||
|
"labels":{"foo":"bar"},
|
||||||
"unspecified": "bar"
|
"unspecified": "bar"
|
||||||
},
|
},
|
||||||
"spec": {
|
"spec": {
|
||||||
@ -404,6 +408,8 @@ func TestPrune(t *testing.T) {
|
|||||||
"unspecified": "bar",
|
"unspecified": "bar",
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"name": "instance",
|
"name": "instance",
|
||||||
|
"namespace": "myns",
|
||||||
|
"labels":{"foo":"bar"},
|
||||||
"unspecified": "bar"
|
"unspecified": "bar"
|
||||||
},
|
},
|
||||||
"spec": {
|
"spec": {
|
||||||
@ -416,6 +422,8 @@ func TestPrune(t *testing.T) {
|
|||||||
"unspecified": "bar",
|
"unspecified": "bar",
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"name": "instance",
|
"name": "instance",
|
||||||
|
"namespace": "myns",
|
||||||
|
"labels":{"foo":"bar"},
|
||||||
"unspecified": "bar"
|
"unspecified": "bar"
|
||||||
},
|
},
|
||||||
"spec": {
|
"spec": {
|
||||||
@ -426,6 +434,8 @@ func TestPrune(t *testing.T) {
|
|||||||
"unspecified": "bar",
|
"unspecified": "bar",
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"name": "instance",
|
"name": "instance",
|
||||||
|
"namespace": "myns",
|
||||||
|
"labels":{"foo":"bar"},
|
||||||
"unspecified": "bar"
|
"unspecified": "bar"
|
||||||
},
|
},
|
||||||
"spec": {
|
"spec": {
|
||||||
@ -438,12 +448,18 @@ func TestPrune(t *testing.T) {
|
|||||||
`, isResourceRoot: true, schema: &structuralschema.Structural{
|
`, isResourceRoot: true, schema: &structuralschema.Structural{
|
||||||
Generic: structuralschema.Generic{Type: "object"},
|
Generic: structuralschema.Generic{Type: "object"},
|
||||||
Properties: map[string]structuralschema.Structural{
|
Properties: map[string]structuralschema.Structural{
|
||||||
|
"metadata": {
|
||||||
|
Generic: structuralschema.Generic{Type: "object"},
|
||||||
|
},
|
||||||
"pruned": {
|
"pruned": {
|
||||||
Generic: structuralschema.Generic{Type: "object"},
|
Generic: structuralschema.Generic{Type: "object"},
|
||||||
Extensions: structuralschema.Extensions{
|
Extensions: structuralschema.Extensions{
|
||||||
XEmbeddedResource: true,
|
XEmbeddedResource: true,
|
||||||
},
|
},
|
||||||
Properties: map[string]structuralschema.Structural{
|
Properties: map[string]structuralschema.Structural{
|
||||||
|
"metadata": {
|
||||||
|
Generic: structuralschema.Generic{Type: "object"},
|
||||||
|
},
|
||||||
"spec": {
|
"spec": {
|
||||||
Generic: structuralschema.Generic{Type: "object"},
|
Generic: structuralschema.Generic{Type: "object"},
|
||||||
},
|
},
|
||||||
@ -471,6 +487,9 @@ func TestPrune(t *testing.T) {
|
|||||||
XEmbeddedResource: true,
|
XEmbeddedResource: true,
|
||||||
},
|
},
|
||||||
Properties: map[string]structuralschema.Structural{
|
Properties: map[string]structuralschema.Structural{
|
||||||
|
"metadata": {
|
||||||
|
Generic: structuralschema.Generic{Type: "object"},
|
||||||
|
},
|
||||||
"spec": {
|
"spec": {
|
||||||
Generic: structuralschema.Generic{Type: "object"},
|
Generic: structuralschema.Generic{Type: "object"},
|
||||||
},
|
},
|
||||||
@ -487,6 +506,8 @@ func TestPrune(t *testing.T) {
|
|||||||
"kind": "Foo",
|
"kind": "Foo",
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"name": "instance",
|
"name": "instance",
|
||||||
|
"namespace": "myns",
|
||||||
|
"labels": {"foo": "bar"},
|
||||||
"unspecified": "bar"
|
"unspecified": "bar"
|
||||||
},
|
},
|
||||||
"pruned": {
|
"pruned": {
|
||||||
@ -494,6 +515,8 @@ func TestPrune(t *testing.T) {
|
|||||||
"kind": "Foo",
|
"kind": "Foo",
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"name": "instance",
|
"name": "instance",
|
||||||
|
"namespace": "myns",
|
||||||
|
"labels": {"foo": "bar"},
|
||||||
"unspecified": "bar"
|
"unspecified": "bar"
|
||||||
},
|
},
|
||||||
"spec": {
|
"spec": {
|
||||||
@ -505,6 +528,8 @@ func TestPrune(t *testing.T) {
|
|||||||
"unspecified": "bar",
|
"unspecified": "bar",
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"name": "instance",
|
"name": "instance",
|
||||||
|
"namespace": "myns",
|
||||||
|
"labels": {"foo": "bar"},
|
||||||
"unspecified": "bar"
|
"unspecified": "bar"
|
||||||
},
|
},
|
||||||
"spec": {
|
"spec": {
|
||||||
@ -516,6 +541,8 @@ func TestPrune(t *testing.T) {
|
|||||||
"kind": "Foo",
|
"kind": "Foo",
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"name": "instance",
|
"name": "instance",
|
||||||
|
"namespace": "myns",
|
||||||
|
"labels": {"foo": "bar"},
|
||||||
"unspecified": "bar"
|
"unspecified": "bar"
|
||||||
},
|
},
|
||||||
"spec": {
|
"spec": {
|
||||||
@ -524,6 +551,8 @@ func TestPrune(t *testing.T) {
|
|||||||
"kind": "Foo",
|
"kind": "Foo",
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"name": "instance",
|
"name": "instance",
|
||||||
|
"namespace": "myns",
|
||||||
|
"labels": {"foo": "bar"},
|
||||||
"unspecified": "bar"
|
"unspecified": "bar"
|
||||||
},
|
},
|
||||||
"spec": {
|
"spec": {
|
||||||
|
@ -45,8 +45,22 @@ run_crd_tests() {
|
|||||||
"storage": true,
|
"storage": true,
|
||||||
"schema": {
|
"schema": {
|
||||||
"openAPIV3Schema": {
|
"openAPIV3Schema": {
|
||||||
"x-kubernetes-preserve-unknown-fields": true,
|
"type": "object",
|
||||||
"type": "object"
|
"properties": {
|
||||||
|
"metadata": {"type": "object"},
|
||||||
|
"nestedField": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"someSubfield": {"type": "string"},
|
||||||
|
"otherSubfield": {"type": "string"},
|
||||||
|
"newSubfield": {"type": "string"}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"otherField": {"type": "string"},
|
||||||
|
"someField": {"type": "string"},
|
||||||
|
"newField": {"type": "string"},
|
||||||
|
"patched": {"type": "string"}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user