mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 19:31:44 +00:00
Strip nullable for Server-side apply
This commit is contained in:
parent
eedfb6bc7a
commit
5038f80b45
@ -1245,7 +1245,7 @@ func buildOpenAPIModelsForApply(staticOpenAPISpec *spec.Swagger, crd *apiextensi
|
||||
|
||||
specs := []*spec.Swagger{}
|
||||
for _, v := range crd.Spec.Versions {
|
||||
s, err := builder.BuildSwagger(crd, v.Name, builder.Options{V2: false, StripDefaults: true, StripValueValidation: true, AllowNonStructural: true})
|
||||
s, err := builder.BuildSwagger(crd, v.Name, builder.Options{V2: false, StripDefaults: true, StripValueValidation: true, StripNullable: true, AllowNonStructural: true})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -49,3 +49,17 @@ func (s *Structural) StripValueValidations() *Structural {
|
||||
v.Visit(s)
|
||||
return s
|
||||
}
|
||||
|
||||
// StripNullable returns a copy without nullable.
|
||||
func (s *Structural) StripNullable() *Structural {
|
||||
s = s.DeepCopy()
|
||||
v := Visitor{
|
||||
Structural: func(s *Structural) bool {
|
||||
changed := s.Nullable
|
||||
s.Nullable = false
|
||||
return changed
|
||||
},
|
||||
}
|
||||
v.Visit(s)
|
||||
return s
|
||||
}
|
||||
|
@ -76,6 +76,9 @@ type Options struct {
|
||||
// Strip value validation.
|
||||
StripValueValidation bool
|
||||
|
||||
// Strip nullable.
|
||||
StripNullable bool
|
||||
|
||||
// AllowNonStructural indicates swagger should be built for a schema that fits into the structural type but does not meet all structural invariants
|
||||
AllowNonStructural bool
|
||||
}
|
||||
@ -101,6 +104,9 @@ func BuildSwagger(crd *apiextensions.CustomResourceDefinition, version string, o
|
||||
if opts.StripValueValidation {
|
||||
schema = schema.StripValueValidations()
|
||||
}
|
||||
if opts.StripNullable {
|
||||
schema = schema.StripNullable()
|
||||
}
|
||||
|
||||
schema = schema.Unfold()
|
||||
}
|
||||
|
@ -190,7 +190,8 @@ func TestApplyCRDStructuralSchema(t *testing.T) {
|
||||
"type": "string"
|
||||
},
|
||||
"protocol": {
|
||||
"type": "string"
|
||||
"type": "string",
|
||||
"nullable": true
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
|
Loading…
Reference in New Issue
Block a user