@@ -68,6 +68,12 @@ var _ = SIGDescribe("CustomResourcePublishOpenAPI [Privileged:ClusterAdmin]", fu
68
68
framework .Failf ("%v" , err )
69
69
}
70
70
71
+ customServiceShortName := "ksvc"
72
+ crdSvc , err := setupCRDWithShortName (f , schemaCustomService , "service" , customServiceShortName , "v1alpha1" )
73
+ if err != nil {
74
+ framework .Failf ("%v" , err )
75
+ }
76
+
71
77
meta := fmt .Sprintf (metaPattern , crd .Crd .Spec .Names .Kind , crd .Crd .Spec .Group , crd .Crd .Spec .Versions [0 ].Name , "test-foo" )
72
78
ns := fmt .Sprintf ("--namespace=%v" , f .Namespace .Name )
73
79
@@ -120,6 +126,11 @@ var _ = SIGDescribe("CustomResourcePublishOpenAPI [Privileged:ClusterAdmin]", fu
120
126
framework .Failf ("%v" , err )
121
127
}
122
128
129
+ ginkgo .By ("kubectl explain works for CR with the same resource name as built-in object" )
130
+ if err := verifyKubectlExplain (f .Namespace .Name , customServiceShortName + ".spec" , `(?s)DESCRIPTION:.*Specification of CustomService.*FIELDS:.*dummy.*<string>.*Dummy property` ); err != nil {
131
+ framework .Failf ("%v" , err )
132
+ }
133
+
123
134
ginkgo .By ("kubectl explain works to return error when explain is called on property that doesn't exist" )
124
135
if _ , err := framework .RunKubectl (f .Namespace .Name , "explain" , crd .Crd .Spec .Names .Plural + ".spec.bars2" ); err == nil || ! strings .Contains (err .Error (), `field "bars2" does not exist` ) {
125
136
framework .Failf ("unexpected no error when explaining property that doesn't exist: %v" , err )
@@ -128,6 +139,9 @@ var _ = SIGDescribe("CustomResourcePublishOpenAPI [Privileged:ClusterAdmin]", fu
128
139
if err := cleanupCRD (f , crd ); err != nil {
129
140
framework .Failf ("%v" , err )
130
141
}
142
+ if err := cleanupCRD (f , crdSvc ); err != nil {
143
+ framework .Failf ("%v" , err )
144
+ }
131
145
})
132
146
133
147
/*
@@ -476,7 +490,24 @@ func setupCRD(f *framework.Framework, schema []byte, groupSuffix string, version
476
490
return setupCRDAndVerifySchema (f , schema , expect , groupSuffix , versions ... )
477
491
}
478
492
493
+ func setupCRDWithShortName (f * framework.Framework , schema []byte , groupSuffix , shortName string , versions ... string ) (* crd.TestCrd , error ) {
494
+ expect := schema
495
+ if schema == nil {
496
+ // to be backwards compatible, we expect CRD controller to treat
497
+ // CRD with nil schema specially and publish an empty schema
498
+ expect = []byte (`type: object` )
499
+ }
500
+ setShortName := func (crd * apiextensionsv1.CustomResourceDefinition ) {
501
+ crd .Spec .Names .ShortNames = []string {shortName }
502
+ }
503
+ return setupCRDAndVerifySchemaWithOptions (f , schema , expect , groupSuffix , versions , setShortName )
504
+ }
505
+
479
506
func setupCRDAndVerifySchema (f * framework.Framework , schema , expect []byte , groupSuffix string , versions ... string ) (* crd.TestCrd , error ) {
507
+ return setupCRDAndVerifySchemaWithOptions (f , schema , expect , groupSuffix , versions )
508
+ }
509
+
510
+ func setupCRDAndVerifySchemaWithOptions (f * framework.Framework , schema , expect []byte , groupSuffix string , versions []string , options ... crd.Option ) (* crd.TestCrd , error ) {
480
511
group := fmt .Sprintf ("%s-test-%s.example.com" , f .BaseName , groupSuffix )
481
512
if len (versions ) == 0 {
482
513
return nil , fmt .Errorf ("require at least one version for CRD" )
@@ -489,7 +520,7 @@ func setupCRDAndVerifySchema(f *framework.Framework, schema, expect []byte, grou
489
520
}
490
521
}
491
522
492
- crd , err := crd . CreateMultiVersionTestCRD ( f , group , func (crd * apiextensionsv1.CustomResourceDefinition ) {
523
+ options = append ( options , func (crd * apiextensionsv1.CustomResourceDefinition ) {
493
524
var apiVersions []apiextensionsv1.CustomResourceDefinitionVersion
494
525
for i , version := range versions {
495
526
version := apiextensionsv1.CustomResourceDefinitionVersion {
@@ -514,6 +545,7 @@ func setupCRDAndVerifySchema(f *framework.Framework, schema, expect []byte, grou
514
545
}
515
546
crd .Spec .Versions = apiVersions
516
547
})
548
+ crd , err := crd .CreateMultiVersionTestCRD (f , group , options ... )
517
549
if err != nil {
518
550
return nil , fmt .Errorf ("failed to create CRD: %v" , err )
519
551
}
@@ -728,6 +760,18 @@ properties:
728
760
pattern: in-tree|out-of-tree
729
761
type: string` )
730
762
763
+ var schemaCustomService = []byte (`description: CustomService CRD for Testing
764
+ type: object
765
+ properties:
766
+ spec:
767
+ description: Specification of CustomService
768
+ type: object
769
+ properties:
770
+ dummy:
771
+ description: Dummy property.
772
+ type: string
773
+ ` )
774
+
731
775
var schemaWaldo = []byte (`description: Waldo CRD for Testing
732
776
type: object
733
777
properties:
0 commit comments