mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 14:37:00 +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.
|
||||
// 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.
|
||||
func Coerce(pth *field.Path, obj interface{}, s *structuralschema.Structural, includeRoot, dropInvalidFields bool) *field.Error {
|
||||
if includeRoot {
|
||||
func Coerce(pth *field.Path, obj interface{}, s *structuralschema.Structural, isResourceRoot, dropInvalidFields bool) *field.Error {
|
||||
if isResourceRoot {
|
||||
if s == nil {
|
||||
s = &structuralschema.Structural{}
|
||||
}
|
||||
clone := *s
|
||||
clone.XEmbeddedResource = true
|
||||
s = &clone
|
||||
if !s.XEmbeddedResource {
|
||||
clone := *s
|
||||
clone.XEmbeddedResource = true
|
||||
s = &clone
|
||||
}
|
||||
}
|
||||
c := coercer{dropInvalidFields: dropInvalidFields}
|
||||
return c.coerce(pth, obj, s)
|
||||
|
@ -28,15 +28,17 @@ import (
|
||||
)
|
||||
|
||||
// Validate validates embedded ObjectMeta and TypeMeta.
|
||||
// It also validate those at the root if includeRoot is true.
|
||||
func Validate(pth *field.Path, obj interface{}, s *structuralschema.Structural, includeRoot bool) field.ErrorList {
|
||||
if includeRoot {
|
||||
// It also validate those at the root if isResourceRoot is true.
|
||||
func Validate(pth *field.Path, obj interface{}, s *structuralschema.Structural, isResourceRoot bool) field.ErrorList {
|
||||
if isResourceRoot {
|
||||
if s == nil {
|
||||
s = &structuralschema.Structural{}
|
||||
}
|
||||
clone := *s
|
||||
clone.XEmbeddedResource = true
|
||||
s = &clone
|
||||
if !s.XEmbeddedResource {
|
||||
clone := *s
|
||||
clone.XEmbeddedResource = true
|
||||
s = &clone
|
||||
}
|
||||
}
|
||||
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
|
||||
// if XEmbeddedResource is set to true, or for the root if root=true.
|
||||
func Prune(obj interface{}, s *structuralschema.Structural, root bool) {
|
||||
if root {
|
||||
// if XEmbeddedResource is set to true, or for the root if isResourceRoot=true.
|
||||
func Prune(obj interface{}, s *structuralschema.Structural, isResourceRoot bool) {
|
||||
if isResourceRoot {
|
||||
if s == nil {
|
||||
s = &structuralschema.Structural{}
|
||||
}
|
||||
clone := *s
|
||||
clone.XEmbeddedResource = true
|
||||
s = &clone
|
||||
if !s.XEmbeddedResource {
|
||||
clone := *s
|
||||
clone.XEmbeddedResource = true
|
||||
s = &clone
|
||||
}
|
||||
}
|
||||
prune(obj, s)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user