Skip to content

Commit 567b134

Browse files
authored
Merge pull request kubernetes#85162 from apelisse/strip-nullable
Strip nullable for Server-side apply
2 parents ba9f741 + 5038f80 commit 567b134

File tree

4 files changed

+23
-2
lines changed

4 files changed

+23
-2
lines changed

staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/customresource_handler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1245,7 +1245,7 @@ func buildOpenAPIModelsForApply(staticOpenAPISpec *spec.Swagger, crd *apiextensi
12451245

12461246
specs := []*spec.Swagger{}
12471247
for _, v := range crd.Spec.Versions {
1248-
s, err := builder.BuildSwagger(crd, v.Name, builder.Options{V2: false, StripDefaults: true, StripValueValidation: true, AllowNonStructural: true})
1248+
s, err := builder.BuildSwagger(crd, v.Name, builder.Options{V2: false, StripDefaults: true, StripValueValidation: true, StripNullable: true, AllowNonStructural: true})
12491249
if err != nil {
12501250
return nil, err
12511251
}

staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/schema/skeleton.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,17 @@ func (s *Structural) StripValueValidations() *Structural {
4949
v.Visit(s)
5050
return s
5151
}
52+
53+
// StripNullable returns a copy without nullable.
54+
func (s *Structural) StripNullable() *Structural {
55+
s = s.DeepCopy()
56+
v := Visitor{
57+
Structural: func(s *Structural) bool {
58+
changed := s.Nullable
59+
s.Nullable = false
60+
return changed
61+
},
62+
}
63+
v.Visit(s)
64+
return s
65+
}

staging/src/k8s.io/apiextensions-apiserver/pkg/controller/openapi/builder/builder.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ type Options struct {
7676
// Strip value validation.
7777
StripValueValidation bool
7878

79+
// Strip nullable.
80+
StripNullable bool
81+
7982
// AllowNonStructural indicates swagger should be built for a schema that fits into the structural type but does not meet all structural invariants
8083
AllowNonStructural bool
8184
}
@@ -101,6 +104,9 @@ func BuildSwagger(crd *apiextensions.CustomResourceDefinition, version string, o
101104
if opts.StripValueValidation {
102105
schema = schema.StripValueValidations()
103106
}
107+
if opts.StripNullable {
108+
schema = schema.StripNullable()
109+
}
104110

105111
schema = schema.Unfold()
106112
}

test/integration/apiserver/apply/apply_crd_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,8 @@ func TestApplyCRDStructuralSchema(t *testing.T) {
190190
"type": "string"
191191
},
192192
"protocol": {
193-
"type": "string"
193+
"type": "string",
194+
"nullable": true
194195
}
195196
},
196197
"required": [

0 commit comments

Comments
 (0)