mirror of
				https://github.com/k3s-io/kubernetes.git
				synced 2025-11-03 23:40:03 +00:00 
			
		
		
		
	apiextensions: add pruning e2e & integration tests for admission webhooks
This commit is contained in:
		@@ -210,9 +210,14 @@ var _ = SIGDescribe("AdmissionWebhook", func() {
 | 
			
		||||
				OpenAPIV3Schema: &apiextensionsv1beta1.JSONSchemaProps{
 | 
			
		||||
					Type: "object",
 | 
			
		||||
					Properties: map[string]apiextensionsv1beta1.JSONSchemaProps{
 | 
			
		||||
						"mutation-start":   {Type: "string"},
 | 
			
		||||
						"mutation-stage-1": {Type: "string"},
 | 
			
		||||
						// mutation-stage-2 is intentionally missing such that it is pruned
 | 
			
		||||
						"data": {
 | 
			
		||||
							Type: "object",
 | 
			
		||||
							Properties: map[string]apiextensionsv1beta1.JSONSchemaProps{
 | 
			
		||||
								"mutation-start":   {Type: "string"},
 | 
			
		||||
								"mutation-stage-1": {Type: "string"},
 | 
			
		||||
								// mutation-stage-2 is intentionally missing such that it is pruned
 | 
			
		||||
							},
 | 
			
		||||
						},
 | 
			
		||||
					},
 | 
			
		||||
				},
 | 
			
		||||
			}
 | 
			
		||||
 
 | 
			
		||||
@@ -113,6 +113,9 @@ var (
 | 
			
		||||
		gvr("", "v1", "nodes/proxy"):    {"*": testSubresourceProxy},
 | 
			
		||||
		gvr("", "v1", "pods/proxy"):     {"*": testSubresourceProxy},
 | 
			
		||||
		gvr("", "v1", "services/proxy"): {"*": testSubresourceProxy},
 | 
			
		||||
 | 
			
		||||
		gvr("random.numbers.com", "v1", "integers"): {"create": testPruningRandomNumbers},
 | 
			
		||||
		gvr("custom.fancy.com", "v2", "pants"):      {"create": testNoPruningCustomFancy},
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// admissionExemptResources lists objects which are exempt from admission validation/mutation,
 | 
			
		||||
@@ -931,6 +934,46 @@ func testSubresourceProxy(c *testContext) {
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func testPruningRandomNumbers(c *testContext) {
 | 
			
		||||
	testResourceCreate(c)
 | 
			
		||||
 | 
			
		||||
	cr2pant, err := c.client.Resource(c.gvr).Get("fortytwo", metav1.GetOptions{})
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		c.t.Error(err)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	foo, found, err := unstructured.NestedString(cr2pant.Object, "foo")
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		c.t.Error(err)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	if found {
 | 
			
		||||
		c.t.Errorf("expected .foo to be pruned, but got: %s", foo)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func testNoPruningCustomFancy(c *testContext) {
 | 
			
		||||
	testResourceCreate(c)
 | 
			
		||||
 | 
			
		||||
	cr2pant, err := c.client.Resource(c.gvr).Get("cr2pant", metav1.GetOptions{})
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		c.t.Error(err)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	foo, _, err := unstructured.NestedString(cr2pant.Object, "foo")
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		c.t.Error(err)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// check that no pruning took place
 | 
			
		||||
	if expected, got := "test", foo; expected != got {
 | 
			
		||||
		c.t.Errorf("expected /foo to be %q, got: %q", expected, got)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//
 | 
			
		||||
// utility methods
 | 
			
		||||
//
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user