@@ -28,7 +28,9 @@ import (
28
28
29
29
"github.com/go-openapi/spec"
30
30
"github.com/onsi/ginkgo"
31
+ openapiutil "k8s.io/kube-openapi/pkg/util"
31
32
"k8s.io/utils/pointer"
33
+ "sigs.k8s.io/yaml"
32
34
33
35
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions"
34
36
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
@@ -39,10 +41,8 @@ import (
39
41
"k8s.io/apimachinery/pkg/util/wait"
40
42
k8sclientset "k8s.io/client-go/kubernetes"
41
43
"k8s.io/client-go/rest"
42
- openapiutil "k8s.io/kube-openapi/pkg/util"
43
44
"k8s.io/kubernetes/test/e2e/framework"
44
45
"k8s.io/kubernetes/test/utils/crd"
45
- "sigs.k8s.io/yaml"
46
46
)
47
47
48
48
var (
@@ -68,12 +68,6 @@ 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
-
77
71
meta := fmt .Sprintf (metaPattern , crd .Crd .Spec .Names .Kind , crd .Crd .Spec .Group , crd .Crd .Spec .Versions [0 ].Name , "test-foo" )
78
72
ns := fmt .Sprintf ("--namespace=%v" , f .Namespace .Name )
79
73
@@ -126,11 +120,6 @@ var _ = SIGDescribe("CustomResourcePublishOpenAPI [Privileged:ClusterAdmin]", fu
126
120
framework .Failf ("%v" , err )
127
121
}
128
122
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
-
134
123
ginkgo .By ("kubectl explain works to return error when explain is called on property that doesn't exist" )
135
124
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` ) {
136
125
framework .Failf ("unexpected no error when explaining property that doesn't exist: %v" , err )
@@ -139,9 +128,6 @@ var _ = SIGDescribe("CustomResourcePublishOpenAPI [Privileged:ClusterAdmin]", fu
139
128
if err := cleanupCRD (f , crd ); err != nil {
140
129
framework .Failf ("%v" , err )
141
130
}
142
- if err := cleanupCRD (f , crdSvc ); err != nil {
143
- framework .Failf ("%v" , err )
144
- }
145
131
})
146
132
147
133
/*
@@ -478,6 +464,34 @@ var _ = SIGDescribe("CustomResourcePublishOpenAPI [Privileged:ClusterAdmin]", fu
478
464
framework .Failf ("%v" , err )
479
465
}
480
466
})
467
+
468
+ // Marked as flaky until https://github.com/kubernetes/kubernetes/issues/65517 is solved.
469
+ ginkgo .It ("[Flaky] kubectl explain works for CR with the same resource name as built-in object." , func () {
470
+ customServiceShortName := fmt .Sprintf ("ksvc-%d" , time .Now ().Unix ()) // make short name unique
471
+ opt := func (crd * apiextensionsv1.CustomResourceDefinition ) {
472
+ crd .ObjectMeta = metav1.ObjectMeta {Name : "services." + crd .Spec .Group }
473
+ crd .Spec .Names = apiextensionsv1.CustomResourceDefinitionNames {
474
+ Plural : "services" ,
475
+ Singular : "service" ,
476
+ ListKind : "ServiceList" ,
477
+ Kind : "Service" ,
478
+ ShortNames : []string {customServiceShortName },
479
+ }
480
+ }
481
+ crdSvc , err := setupCRDAndVerifySchemaWithOptions (f , schemaCustomService , schemaCustomService , "service" , []string {"v1" }, opt )
482
+ if err != nil {
483
+ framework .Failf ("%v" , err )
484
+ }
485
+
486
+ if err := verifyKubectlExplain (f .Namespace .Name , customServiceShortName + ".spec" , `(?s)DESCRIPTION:.*Specification of CustomService.*FIELDS:.*dummy.*<string>.*Dummy property` ); err != nil {
487
+ _ = cleanupCRD (f , crdSvc ) // need to remove the crd since its name is unchanged
488
+ framework .Failf ("%v" , err )
489
+ }
490
+
491
+ if err := cleanupCRD (f , crdSvc ); err != nil {
492
+ framework .Failf ("%v" , err )
493
+ }
494
+ })
481
495
})
482
496
483
497
func setupCRD (f * framework.Framework , schema []byte , groupSuffix string , versions ... string ) (* crd.TestCrd , error ) {
@@ -490,19 +504,6 @@ func setupCRD(f *framework.Framework, schema []byte, groupSuffix string, version
490
504
return setupCRDAndVerifySchema (f , schema , expect , groupSuffix , versions ... )
491
505
}
492
506
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
-
506
507
func setupCRDAndVerifySchema (f * framework.Framework , schema , expect []byte , groupSuffix string , versions ... string ) (* crd.TestCrd , error ) {
507
508
return setupCRDAndVerifySchemaWithOptions (f , schema , expect , groupSuffix , versions )
508
509
}
0 commit comments