From b9fb9b82f363b6e77d32dd33fc4de45c5cd8bbb8 Mon Sep 17 00:00:00 2001 From: knight42 Date: Mon, 27 Apr 2020 11:24:01 +0800 Subject: [PATCH] test(kubectl::explain): move the flaky test out of conformance Signed-off-by: knight42 --- test/e2e/apimachinery/crd_publish_openapi.go | 59 ++++++++++---------- 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/test/e2e/apimachinery/crd_publish_openapi.go b/test/e2e/apimachinery/crd_publish_openapi.go index 591a7f043df..1431e5388ef 100644 --- a/test/e2e/apimachinery/crd_publish_openapi.go +++ b/test/e2e/apimachinery/crd_publish_openapi.go @@ -28,7 +28,9 @@ import ( "github.com/go-openapi/spec" "github.com/onsi/ginkgo" + openapiutil "k8s.io/kube-openapi/pkg/util" "k8s.io/utils/pointer" + "sigs.k8s.io/yaml" "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions" apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" @@ -39,10 +41,8 @@ import ( "k8s.io/apimachinery/pkg/util/wait" k8sclientset "k8s.io/client-go/kubernetes" "k8s.io/client-go/rest" - openapiutil "k8s.io/kube-openapi/pkg/util" "k8s.io/kubernetes/test/e2e/framework" "k8s.io/kubernetes/test/utils/crd" - "sigs.k8s.io/yaml" ) var ( @@ -68,12 +68,6 @@ var _ = SIGDescribe("CustomResourcePublishOpenAPI [Privileged:ClusterAdmin]", fu framework.Failf("%v", err) } - customServiceShortName := "ksvc" - crdSvc, err := setupCRDWithShortName(f, schemaCustomService, "service", customServiceShortName, "v1alpha1") - if err != nil { - framework.Failf("%v", err) - } - meta := fmt.Sprintf(metaPattern, crd.Crd.Spec.Names.Kind, crd.Crd.Spec.Group, crd.Crd.Spec.Versions[0].Name, "test-foo") ns := fmt.Sprintf("--namespace=%v", f.Namespace.Name) @@ -126,11 +120,6 @@ var _ = SIGDescribe("CustomResourcePublishOpenAPI [Privileged:ClusterAdmin]", fu framework.Failf("%v", err) } - ginkgo.By("kubectl explain works for CR with the same resource name as built-in object") - if err := verifyKubectlExplain(f.Namespace.Name, customServiceShortName+".spec", `(?s)DESCRIPTION:.*Specification of CustomService.*FIELDS:.*dummy.*.*Dummy property`); err != nil { - framework.Failf("%v", err) - } - ginkgo.By("kubectl explain works to return error when explain is called on property that doesn't exist") 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`) { framework.Failf("unexpected no error when explaining property that doesn't exist: %v", err) @@ -139,9 +128,6 @@ var _ = SIGDescribe("CustomResourcePublishOpenAPI [Privileged:ClusterAdmin]", fu if err := cleanupCRD(f, crd); err != nil { framework.Failf("%v", err) } - if err := cleanupCRD(f, crdSvc); err != nil { - framework.Failf("%v", err) - } }) /* @@ -478,6 +464,34 @@ var _ = SIGDescribe("CustomResourcePublishOpenAPI [Privileged:ClusterAdmin]", fu framework.Failf("%v", err) } }) + + // Marked as flaky until https://github.com/kubernetes/kubernetes/issues/65517 is solved. + ginkgo.It("[Flaky] kubectl explain works for CR with the same resource name as built-in object.", func() { + customServiceShortName := fmt.Sprintf("ksvc-%d", time.Now().Unix()) // make short name unique + opt := func(crd *apiextensionsv1.CustomResourceDefinition) { + crd.ObjectMeta = metav1.ObjectMeta{Name: "services." + crd.Spec.Group} + crd.Spec.Names = apiextensionsv1.CustomResourceDefinitionNames{ + Plural: "services", + Singular: "service", + ListKind: "ServiceList", + Kind: "Service", + ShortNames: []string{customServiceShortName}, + } + } + crdSvc, err := setupCRDAndVerifySchemaWithOptions(f, schemaCustomService, schemaCustomService, "service", []string{"v1"}, opt) + if err != nil { + framework.Failf("%v", err) + } + + if err := verifyKubectlExplain(f.Namespace.Name, customServiceShortName+".spec", `(?s)DESCRIPTION:.*Specification of CustomService.*FIELDS:.*dummy.*.*Dummy property`); err != nil { + _ = cleanupCRD(f, crdSvc) // need to remove the crd since its name is unchanged + framework.Failf("%v", err) + } + + if err := cleanupCRD(f, crdSvc); err != nil { + framework.Failf("%v", err) + } + }) }) 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 return setupCRDAndVerifySchema(f, schema, expect, groupSuffix, versions...) } -func setupCRDWithShortName(f *framework.Framework, schema []byte, groupSuffix, shortName string, versions ...string) (*crd.TestCrd, error) { - expect := schema - if schema == nil { - // to be backwards compatible, we expect CRD controller to treat - // CRD with nil schema specially and publish an empty schema - expect = []byte(`type: object`) - } - setShortName := func(crd *apiextensionsv1.CustomResourceDefinition) { - crd.Spec.Names.ShortNames = []string{shortName} - } - return setupCRDAndVerifySchemaWithOptions(f, schema, expect, groupSuffix, versions, setShortName) -} - func setupCRDAndVerifySchema(f *framework.Framework, schema, expect []byte, groupSuffix string, versions ...string) (*crd.TestCrd, error) { return setupCRDAndVerifySchemaWithOptions(f, schema, expect, groupSuffix, versions) }