diff --git a/test/cmd/create.sh b/test/cmd/create.sh index bf9bf4ebb61..77cfe25fea9 100755 --- a/test/cmd/create.sh +++ b/test/cmd/create.sh @@ -72,18 +72,6 @@ run_kubectl_create_error_tests() { # Passing no arguments to create is an error ! kubectl create || exit 1 - ## kubectl create should not panic on empty string lists in a template - ERROR_FILE="${KUBE_TEMP}/validation-error" - kubectl create -f hack/testdata/invalid-rc-with-empty-args.yaml "${kube_flags[@]}" 2> "${ERROR_FILE}" || true - # Post-condition: should get an error reporting the empty string - if grep -q "unknown object type \"nil\" in ReplicationController" "${ERROR_FILE}"; then - kube::log::status "\"kubectl create with empty string list returns error as expected: $(cat "${ERROR_FILE}")" - else - kube::log::status "\"kubectl create with empty string list returns unexpected error or non-error: $(cat "${ERROR_FILE}")" - exit 1 - fi - rm "${ERROR_FILE}" - # Posting a pod to namespaces should fail. Also tests --raw forcing the post location grep -q 'the object provided is unrecognized (must be of type Namespace)' <<< "$( kubectl create "${kube_flags[@]}" --raw /api/v1/namespaces -f test/fixtures/doc-yaml/admin/limitrange/valid-pod.yaml --v=8 2>&1 )" diff --git a/test/e2e/apimachinery/crd_publish_openapi.go b/test/e2e/apimachinery/crd_publish_openapi.go index 1aa3b49a69a..4558840c1d8 100644 --- a/test/e2e/apimachinery/crd_publish_openapi.go +++ b/test/e2e/apimachinery/crd_publish_openapi.go @@ -95,19 +95,19 @@ var _ = SIGDescribe("CustomResourcePublishOpenAPI [Privileged:ClusterAdmin]", fu ginkgo.By("client-side validation (kubectl create and apply) rejects request with unknown properties when disallowed by the schema") unknownCR := fmt.Sprintf(`{%s,"spec":{"foo":true}}`, meta) - if _, err := framework.RunKubectlInput(f.Namespace.Name, unknownCR, ns, "create", "-f", "-"); err == nil || !strings.Contains(err.Error(), `unknown field "foo"`) { + if _, err := framework.RunKubectlInput(f.Namespace.Name, unknownCR, ns, "create", "-f", "-"); err == nil || (!strings.Contains(err.Error(), `unknown field "foo"`) && !strings.Contains(err.Error(), `unknown field "spec.foo"`)) { framework.Failf("unexpected no error when creating CR with unknown field: %v", err) } - if _, err := framework.RunKubectlInput(f.Namespace.Name, unknownCR, ns, "apply", "-f", "-"); err == nil || !strings.Contains(err.Error(), `unknown field "foo"`) { + if _, err := framework.RunKubectlInput(f.Namespace.Name, unknownCR, ns, "apply", "-f", "-"); err == nil || (!strings.Contains(err.Error(), `unknown field "foo"`) && !strings.Contains(err.Error(), `unknown field "spec.foo"`)) { framework.Failf("unexpected no error when applying CR with unknown field: %v", err) } ginkgo.By("client-side validation (kubectl create and apply) rejects request without required properties") noRequireCR := fmt.Sprintf(`{%s,"spec":{"bars":[{"age":"10"}]}}`, meta) - if _, err := framework.RunKubectlInput(f.Namespace.Name, noRequireCR, ns, "create", "-f", "-"); err == nil || !strings.Contains(err.Error(), `missing required field "name"`) { + if _, err := framework.RunKubectlInput(f.Namespace.Name, noRequireCR, ns, "create", "-f", "-"); err == nil || (!strings.Contains(err.Error(), `missing required field "name"`) && !strings.Contains(err.Error(), `spec.bars[0].name: Required value`)) { framework.Failf("unexpected no error when creating CR without required field: %v", err) } - if _, err := framework.RunKubectlInput(f.Namespace.Name, noRequireCR, ns, "apply", "-f", "-"); err == nil || !strings.Contains(err.Error(), `missing required field "name"`) { + if _, err := framework.RunKubectlInput(f.Namespace.Name, noRequireCR, ns, "apply", "-f", "-"); err == nil || (!strings.Contains(err.Error(), `missing required field "name"`) && !strings.Contains(err.Error(), `spec.bars[0].name: Required value`)) { framework.Failf("unexpected no error when applying CR without required field: %v", err) } diff --git a/test/e2e/kubectl/kubectl.go b/test/e2e/kubectl/kubectl.go index 8d20b02279b..6fcc8fde06f 100644 --- a/test/e2e/kubectl/kubectl.go +++ b/test/e2e/kubectl/kubectl.go @@ -1071,7 +1071,9 @@ metadata: framework.ExpectNotEqual(schema, nil, "retrieving a schema for the crd") meta := fmt.Sprintf(metaPattern, crd.Crd.Spec.Names.Kind, crd.Crd.Spec.Group, crd.Crd.Spec.Versions[0].Name, "test-cr") - validArbitraryCR := fmt.Sprintf(`{%s,"spec":{"bars":[{"name":"test-bar"}],"extraProperty":"arbitrary-value"}}`, meta) + + // unknown fields on the root are considered valid + validArbitraryCR := fmt.Sprintf(`{%s,"spec":{"bars":[{"name":"test-bar"}]},"extraProperty":"arbitrary-value"}`, meta) err = createApplyCustomResource(validArbitraryCR, f.Namespace.Name, "test-cr", crd) framework.ExpectNoError(err, "creating custom resource") })