mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 09:22:44 +00:00
apiextensions: only clone on !s.XEmbeddedResource
This commit is contained in:
parent
a03330fbeb
commit
1c061bb401
@ -23,16 +23,18 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Coerce checks types of embedded ObjectMeta and TypeMeta and prunes unknown fields inside the former.
|
// Coerce checks types of embedded ObjectMeta and TypeMeta and prunes unknown fields inside the former.
|
||||||
// It does coerce ObjectMeta and TypeMeta at the root if includeRoot is true.
|
// It does coerce ObjectMeta and TypeMeta at the root if isResourceRoot is true.
|
||||||
// If dropInvalidFields is true, fields of wrong type will be dropped.
|
// If dropInvalidFields is true, fields of wrong type will be dropped.
|
||||||
func Coerce(pth *field.Path, obj interface{}, s *structuralschema.Structural, includeRoot, dropInvalidFields bool) *field.Error {
|
func Coerce(pth *field.Path, obj interface{}, s *structuralschema.Structural, isResourceRoot, dropInvalidFields bool) *field.Error {
|
||||||
if includeRoot {
|
if isResourceRoot {
|
||||||
if s == nil {
|
if s == nil {
|
||||||
s = &structuralschema.Structural{}
|
s = &structuralschema.Structural{}
|
||||||
}
|
}
|
||||||
clone := *s
|
if !s.XEmbeddedResource {
|
||||||
clone.XEmbeddedResource = true
|
clone := *s
|
||||||
s = &clone
|
clone.XEmbeddedResource = true
|
||||||
|
s = &clone
|
||||||
|
}
|
||||||
}
|
}
|
||||||
c := coercer{dropInvalidFields: dropInvalidFields}
|
c := coercer{dropInvalidFields: dropInvalidFields}
|
||||||
return c.coerce(pth, obj, s)
|
return c.coerce(pth, obj, s)
|
||||||
|
@ -28,15 +28,17 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Validate validates embedded ObjectMeta and TypeMeta.
|
// Validate validates embedded ObjectMeta and TypeMeta.
|
||||||
// It also validate those at the root if includeRoot is true.
|
// It also validate those at the root if isResourceRoot is true.
|
||||||
func Validate(pth *field.Path, obj interface{}, s *structuralschema.Structural, includeRoot bool) field.ErrorList {
|
func Validate(pth *field.Path, obj interface{}, s *structuralschema.Structural, isResourceRoot bool) field.ErrorList {
|
||||||
if includeRoot {
|
if isResourceRoot {
|
||||||
if s == nil {
|
if s == nil {
|
||||||
s = &structuralschema.Structural{}
|
s = &structuralschema.Structural{}
|
||||||
}
|
}
|
||||||
clone := *s
|
if !s.XEmbeddedResource {
|
||||||
clone.XEmbeddedResource = true
|
clone := *s
|
||||||
s = &clone
|
clone.XEmbeddedResource = true
|
||||||
|
s = &clone
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return validate(pth, obj, s)
|
return validate(pth, obj, s)
|
||||||
}
|
}
|
||||||
|
@ -21,15 +21,17 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Prune removes object fields in obj which are not specified in s. It skips TypeMeta and ObjectMeta fields
|
// Prune removes object fields in obj which are not specified in s. It skips TypeMeta and ObjectMeta fields
|
||||||
// if XEmbeddedResource is set to true, or for the root if root=true.
|
// if XEmbeddedResource is set to true, or for the root if isResourceRoot=true.
|
||||||
func Prune(obj interface{}, s *structuralschema.Structural, root bool) {
|
func Prune(obj interface{}, s *structuralschema.Structural, isResourceRoot bool) {
|
||||||
if root {
|
if isResourceRoot {
|
||||||
if s == nil {
|
if s == nil {
|
||||||
s = &structuralschema.Structural{}
|
s = &structuralschema.Structural{}
|
||||||
}
|
}
|
||||||
clone := *s
|
if !s.XEmbeddedResource {
|
||||||
clone.XEmbeddedResource = true
|
clone := *s
|
||||||
s = &clone
|
clone.XEmbeddedResource = true
|
||||||
|
s = &clone
|
||||||
|
}
|
||||||
}
|
}
|
||||||
prune(obj, s)
|
prune(obj, s)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user