Skip to content

Commit b9fb9b8

Browse files
committed
test(kubectl::explain): move the flaky test out of conformance
Signed-off-by: knight42 <[email protected]>
1 parent d3d870f commit b9fb9b8

File tree

1 file changed

+30
-29
lines changed

1 file changed

+30
-29
lines changed

test/e2e/apimachinery/crd_publish_openapi.go

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ import (
2828

2929
"github.com/go-openapi/spec"
3030
"github.com/onsi/ginkgo"
31+
openapiutil "k8s.io/kube-openapi/pkg/util"
3132
"k8s.io/utils/pointer"
33+
"sigs.k8s.io/yaml"
3234

3335
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions"
3436
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
@@ -39,10 +41,8 @@ import (
3941
"k8s.io/apimachinery/pkg/util/wait"
4042
k8sclientset "k8s.io/client-go/kubernetes"
4143
"k8s.io/client-go/rest"
42-
openapiutil "k8s.io/kube-openapi/pkg/util"
4344
"k8s.io/kubernetes/test/e2e/framework"
4445
"k8s.io/kubernetes/test/utils/crd"
45-
"sigs.k8s.io/yaml"
4646
)
4747

4848
var (
@@ -68,12 +68,6 @@ var _ = SIGDescribe("CustomResourcePublishOpenAPI [Privileged:ClusterAdmin]", fu
6868
framework.Failf("%v", err)
6969
}
7070

71-
customServiceShortName := "ksvc"
72-
crdSvc, err := setupCRDWithShortName(f, schemaCustomService, "service", customServiceShortName, "v1alpha1")
73-
if err != nil {
74-
framework.Failf("%v", err)
75-
}
76-
7771
meta := fmt.Sprintf(metaPattern, crd.Crd.Spec.Names.Kind, crd.Crd.Spec.Group, crd.Crd.Spec.Versions[0].Name, "test-foo")
7872
ns := fmt.Sprintf("--namespace=%v", f.Namespace.Name)
7973

@@ -126,11 +120,6 @@ var _ = SIGDescribe("CustomResourcePublishOpenAPI [Privileged:ClusterAdmin]", fu
126120
framework.Failf("%v", err)
127121
}
128122

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-
134123
ginkgo.By("kubectl explain works to return error when explain is called on property that doesn't exist")
135124
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`) {
136125
framework.Failf("unexpected no error when explaining property that doesn't exist: %v", err)
@@ -139,9 +128,6 @@ var _ = SIGDescribe("CustomResourcePublishOpenAPI [Privileged:ClusterAdmin]", fu
139128
if err := cleanupCRD(f, crd); err != nil {
140129
framework.Failf("%v", err)
141130
}
142-
if err := cleanupCRD(f, crdSvc); err != nil {
143-
framework.Failf("%v", err)
144-
}
145131
})
146132

147133
/*
@@ -478,6 +464,34 @@ var _ = SIGDescribe("CustomResourcePublishOpenAPI [Privileged:ClusterAdmin]", fu
478464
framework.Failf("%v", err)
479465
}
480466
})
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+
})
481495
})
482496

483497
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
490504
return setupCRDAndVerifySchema(f, schema, expect, groupSuffix, versions...)
491505
}
492506

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-
506507
func setupCRDAndVerifySchema(f *framework.Framework, schema, expect []byte, groupSuffix string, versions ...string) (*crd.TestCrd, error) {
507508
return setupCRDAndVerifySchemaWithOptions(f, schema, expect, groupSuffix, versions)
508509
}

0 commit comments

Comments
 (0)