Skip to content

Commit d83805c

Browse files
authored
Merge pull request kubernetes#78194 from roycaihw/crd-openapi-e2e
Fix alpha CRD openapi e2e
2 parents d1d6f64 + 629bdf5 commit d83805c

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

test/e2e/apimachinery/crd_publish_openapi.go

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
3333
"k8s.io/apiextensions-apiserver/pkg/apiserver/validation"
3434
apiequality "k8s.io/apimachinery/pkg/api/equality"
35+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3536
"k8s.io/apimachinery/pkg/types"
3637
utilversion "k8s.io/apimachinery/pkg/util/version"
3738
"k8s.io/apimachinery/pkg/util/wait"
@@ -309,6 +310,10 @@ var _ = SIGDescribe("CustomResourcePublishOpenAPI [Feature:CustomResourcePublish
309310
}
310311

311312
ginkgo.By("mark a version not serverd")
313+
crd.Crd, err = crd.APIExtensionClient.ApiextensionsV1beta1().CustomResourceDefinitions().Get(crd.Crd.Name, metav1.GetOptions{})
314+
if err != nil {
315+
framework.Failf("%v", err)
316+
}
312317
crd.Crd.Spec.Versions[1].Served = false
313318
crd.Crd, err = crd.APIExtensionClient.ApiextensionsV1beta1().CustomResourceDefinitions().Update(crd.Crd)
314319
if err != nil {
@@ -336,12 +341,16 @@ func setupCRD(f *framework.Framework, schema []byte, groupSuffix string, version
336341
return nil, fmt.Errorf("require at least one version for CRD")
337342
}
338343

339-
if schema == nil {
340-
schema = []byte(`type: object`)
341-
}
344+
expect := schema
342345
props := &v1beta1.JSONSchemaProps{}
343-
if err := yaml.Unmarshal(schema, props); err != nil {
344-
return nil, err
346+
if schema == nil {
347+
// to be backwards compatible, we expect CRD controller to treat
348+
// CRD with nil schema specially and publish an empty schema
349+
expect = []byte(`type: object`)
350+
} else {
351+
if err := yaml.Unmarshal(schema, props); err != nil {
352+
return nil, err
353+
}
345354
}
346355

347356
crd, err := crd.CreateMultiVersionTestCRD(f, group, func(crd *v1beta1.CustomResourceDefinition) {
@@ -355,16 +364,19 @@ func setupCRD(f *framework.Framework, schema []byte, groupSuffix string, version
355364
}
356365
crd.Spec.Versions = apiVersions
357366

358-
crd.Spec.Validation = &v1beta1.CustomResourceValidation{
359-
OpenAPIV3Schema: props,
367+
// set up validation when input schema isn't nil
368+
if schema != nil {
369+
crd.Spec.Validation = &v1beta1.CustomResourceValidation{
370+
OpenAPIV3Schema: props,
371+
}
360372
}
361373
})
362374
if err != nil {
363375
return nil, fmt.Errorf("failed to create CRD: %v", err)
364376
}
365377

366378
for _, v := range crd.Crd.Spec.Versions {
367-
if err := waitForDefinition(f.ClientSet, definitionName(crd, v.Name), schema); err != nil {
379+
if err := waitForDefinition(f.ClientSet, definitionName(crd, v.Name), expect); err != nil {
368380
return nil, fmt.Errorf("%v", err)
369381
}
370382
}
@@ -579,9 +591,11 @@ properties:
579591
properties:
580592
dummy:
581593
description: Dummy property.
594+
type: object
582595
status:
583596
description: Status of Waldo
584597
type: object
585598
properties:
586599
bars:
587-
description: List of Bars and their statuses.`)
600+
description: List of Bars and their statuses.
601+
type: array`)

0 commit comments

Comments
 (0)