Skip to content

Commit d815449

Browse files
committed
Adjust testing for server-side validation as default
1 parent 36dbecd commit d815449

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

test/e2e/kubectl/kubectl.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1075,7 +1075,7 @@ metadata:
10751075
}
10761076
})
10771077

1078-
ginkgo.It("should create/apply a valid CR with arbitrary-extra properties for CRD with partially-specified validation schema", func() {
1078+
ginkgo.It("should create/apply an invalid/valid CR with arbitrary-extra properties for CRD with partially-specified validation schema", func() {
10791079
ginkgo.By("prepare CRD with partially-specified validation schema")
10801080
crd, err := crd.CreateTestCRD(f, func(crd *apiextensionsv1.CustomResourceDefinition) {
10811081
props := &apiextensionsv1.JSONSchemaProps{}
@@ -1101,6 +1101,15 @@ metadata:
11011101

11021102
meta := fmt.Sprintf(metaPattern, crd.Crd.Spec.Names.Kind, crd.Crd.Spec.Group, crd.Crd.Spec.Versions[0].Name, "test-cr")
11031103

1104+
// XPreserveUnknownFields is defined on the root of the schema so unknown fields within the spec
1105+
// are still considered invalid
1106+
invalidArbitraryCR := fmt.Sprintf(`{%s,"spec":{"bars":[{"name":"test-bar"}],"extraProperty":"arbitrary-value"}}`, meta)
1107+
err = createApplyCustomResource(invalidArbitraryCR, f.Namespace.Name, "test-cr", crd)
1108+
framework.ExpectError(err, "creating custom resource")
1109+
if !strings.Contains(err.Error(), `unknown field "spec.extraProperty"`) {
1110+
framework.Failf("incorrect error from createApplyCustomResource: %v", err)
1111+
}
1112+
11041113
// unknown fields on the root are considered valid
11051114
validArbitraryCR := fmt.Sprintf(`{%s,"spec":{"bars":[{"name":"test-bar"}]},"extraProperty":"arbitrary-value"}`, meta)
11061115
err = createApplyCustomResource(validArbitraryCR, f.Namespace.Name, "test-cr", crd)

0 commit comments

Comments
 (0)