Skip to content

Commit c671245

Browse files
committed
apiextensions: add pruning e2e & integration tests for admission webhooks
1 parent 77bfdda commit c671245

File tree

2 files changed

+51
-3
lines changed

2 files changed

+51
-3
lines changed

test/e2e/apimachinery/webhook.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,14 @@ var _ = SIGDescribe("AdmissionWebhook", func() {
210210
OpenAPIV3Schema: &apiextensionsv1beta1.JSONSchemaProps{
211211
Type: "object",
212212
Properties: map[string]apiextensionsv1beta1.JSONSchemaProps{
213-
"mutation-start": {Type: "string"},
214-
"mutation-stage-1": {Type: "string"},
215-
// mutation-stage-2 is intentionally missing such that it is pruned
213+
"data": {
214+
Type: "object",
215+
Properties: map[string]apiextensionsv1beta1.JSONSchemaProps{
216+
"mutation-start": {Type: "string"},
217+
"mutation-stage-1": {Type: "string"},
218+
// mutation-stage-2 is intentionally missing such that it is pruned
219+
},
220+
},
216221
},
217222
},
218223
}

test/integration/apiserver/admissionwebhook/admission_test.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ var (
113113
gvr("", "v1", "nodes/proxy"): {"*": testSubresourceProxy},
114114
gvr("", "v1", "pods/proxy"): {"*": testSubresourceProxy},
115115
gvr("", "v1", "services/proxy"): {"*": testSubresourceProxy},
116+
117+
gvr("random.numbers.com", "v1", "integers"): {"create": testPruningRandomNumbers},
118+
gvr("custom.fancy.com", "v2", "pants"): {"create": testNoPruningCustomFancy},
116119
}
117120

118121
// admissionExemptResources lists objects which are exempt from admission validation/mutation,
@@ -931,6 +934,46 @@ func testSubresourceProxy(c *testContext) {
931934
}
932935
}
933936

937+
func testPruningRandomNumbers(c *testContext) {
938+
testResourceCreate(c)
939+
940+
cr2pant, err := c.client.Resource(c.gvr).Get("fortytwo", metav1.GetOptions{})
941+
if err != nil {
942+
c.t.Error(err)
943+
return
944+
}
945+
946+
foo, found, err := unstructured.NestedString(cr2pant.Object, "foo")
947+
if err != nil {
948+
c.t.Error(err)
949+
return
950+
}
951+
if found {
952+
c.t.Errorf("expected .foo to be pruned, but got: %s", foo)
953+
}
954+
}
955+
956+
func testNoPruningCustomFancy(c *testContext) {
957+
testResourceCreate(c)
958+
959+
cr2pant, err := c.client.Resource(c.gvr).Get("cr2pant", metav1.GetOptions{})
960+
if err != nil {
961+
c.t.Error(err)
962+
return
963+
}
964+
965+
foo, _, err := unstructured.NestedString(cr2pant.Object, "foo")
966+
if err != nil {
967+
c.t.Error(err)
968+
return
969+
}
970+
971+
// check that no pruning took place
972+
if expected, got := "test", foo; expected != got {
973+
c.t.Errorf("expected /foo to be %q, got: %q", expected, got)
974+
}
975+
}
976+
934977
//
935978
// utility methods
936979
//

0 commit comments

Comments
 (0)