support for resize subresource in ResourceQuota admission.
Kubernetes-commit: 1b98fe6079059cb1d7bfda4f4b318f614449fee5
This commit is contained in:
		
							parent
							
								
									04fa4ade1a
								
							
						
					
					
						commit
						cb02f4a386
					
				|  | @ -155,10 +155,6 @@ func (a *QuotaAdmission) ValidateInitialization() error { | |||
| 
 | ||||
| // Validate makes admission decisions while enforcing quota
 | ||||
| func (a *QuotaAdmission) Validate(ctx context.Context, attr admission.Attributes, o admission.ObjectInterfaces) (err error) { | ||||
| 	// ignore all operations that correspond to sub-resource actions
 | ||||
| 	if attr.GetSubresource() != "" { | ||||
| 		return nil | ||||
| 	} | ||||
| 	// ignore all operations that are not namespaced or creation of namespaces
 | ||||
| 	if attr.GetNamespace() == "" || isNamespaceCreation(attr) { | ||||
| 		return nil | ||||
|  |  | |||
|  | @ -143,10 +143,6 @@ func TestExcludedOperations(t *testing.T) { | |||
| 		desc string | ||||
| 		attr admission.Attributes | ||||
| 	}{ | ||||
| 		{ | ||||
| 			"subresource", | ||||
| 			admission.NewAttributesRecord(nil, nil, schema.GroupVersionKind{}, "namespace", "name", schema.GroupVersionResource{}, "subresource", admission.Create, nil, false, nil), | ||||
| 		}, | ||||
| 		{ | ||||
| 			"non-namespaced resource", | ||||
| 			admission.NewAttributesRecord(nil, nil, schema.GroupVersionKind{}, "", "namespace", schema.GroupVersionResource{}, "", admission.Create, nil, false, nil), | ||||
|  |  | |||
|  | @ -250,6 +250,9 @@ func (o *objectCountEvaluator) Constraints(required []corev1.ResourceName, item | |||
| 
 | ||||
| // Handles returns true if the object count evaluator needs to track this attributes.
 | ||||
| func (o *objectCountEvaluator) Handles(a admission.Attributes) bool { | ||||
| 	if a.GetSubresource() != "" { | ||||
| 		return false | ||||
| 	} | ||||
| 	operation := a.GetOperation() | ||||
| 	return operation == admission.Create | ||||
| } | ||||
|  |  | |||
|  | @ -22,6 +22,8 @@ import ( | |||
| 
 | ||||
| 	"k8s.io/apimachinery/pkg/labels" | ||||
| 	"k8s.io/apimachinery/pkg/runtime" | ||||
| 	"k8s.io/apimachinery/pkg/runtime/schema" | ||||
| 	"k8s.io/apiserver/pkg/admission" | ||||
| 	"k8s.io/client-go/tools/cache" | ||||
| ) | ||||
| 
 | ||||
|  | @ -129,3 +131,52 @@ func (f *fakeLister) Get(name string) (runtime.Object, error) { | |||
| func (f *fakeLister) ByNamespace(namespace string) cache.GenericNamespaceLister { | ||||
| 	panic("not implemented") | ||||
| } | ||||
| 
 | ||||
| func TestObjectCountEvaluatorHandles(t *testing.T) { | ||||
| 	evaluator := objectCountEvaluator{} | ||||
| 	testCases := []struct { | ||||
| 		name  string | ||||
| 		attrs admission.Attributes | ||||
| 		want  bool | ||||
| 	}{ | ||||
| 		{ | ||||
| 			name:  "create", | ||||
| 			attrs: admission.NewAttributesRecord(nil, nil, schema.GroupVersionKind{Group: "core", Version: "v1", Kind: "Pod"}, "", "", schema.GroupVersionResource{Group: "core", Version: "v1", Resource: "pods"}, "", admission.Create, nil, false, nil), | ||||
| 			want:  true, | ||||
| 		}, | ||||
| 		{ | ||||
| 			name:  "update", | ||||
| 			attrs: admission.NewAttributesRecord(nil, nil, schema.GroupVersionKind{Group: "core", Version: "v1", Kind: "Pod"}, "", "", schema.GroupVersionResource{Group: "core", Version: "v1", Resource: "pods"}, "", admission.Update, nil, false, nil), | ||||
| 			want:  false, | ||||
| 		}, | ||||
| 		{ | ||||
| 			name:  "delete", | ||||
| 			attrs: admission.NewAttributesRecord(nil, nil, schema.GroupVersionKind{Group: "core", Version: "v1", Kind: "Pod"}, "", "", schema.GroupVersionResource{Group: "core", Version: "v1", Resource: "pods"}, "", admission.Delete, nil, false, nil), | ||||
| 			want:  false, | ||||
| 		}, | ||||
| 		{ | ||||
| 			name:  "connect", | ||||
| 			attrs: admission.NewAttributesRecord(nil, nil, schema.GroupVersionKind{Group: "core", Version: "v1", Kind: "Pod"}, "", "", schema.GroupVersionResource{Group: "core", Version: "v1", Resource: "pods"}, "", admission.Connect, nil, false, nil), | ||||
| 			want:  false, | ||||
| 		}, | ||||
| 		{ | ||||
| 			name:  "create-subresource", | ||||
| 			attrs: admission.NewAttributesRecord(nil, nil, schema.GroupVersionKind{Group: "core", Version: "v1", Kind: "Pod"}, "", "", schema.GroupVersionResource{Group: "core", Version: "v1", Resource: "pods"}, "subresource", admission.Create, nil, false, nil), | ||||
| 			want:  false, | ||||
| 		}, | ||||
| 		{ | ||||
| 			name:  "update-subresource", | ||||
| 			attrs: admission.NewAttributesRecord(nil, nil, schema.GroupVersionKind{Group: "core", Version: "v1", Kind: "Pod"}, "", "", schema.GroupVersionResource{Group: "core", Version: "v1", Resource: "pods"}, "subresource", admission.Update, nil, false, nil), | ||||
| 			want:  false, | ||||
| 		}, | ||||
| 	} | ||||
| 	for _, tc := range testCases { | ||||
| 		t.Run(tc.name, func(t *testing.T) { | ||||
| 			actual := evaluator.Handles(tc.attrs) | ||||
| 
 | ||||
| 			if tc.want != actual { | ||||
| 				t.Errorf("%s expected:\n%v\n, actual:\n%v", tc.name, tc.want, actual) | ||||
| 			} | ||||
| 		}) | ||||
| 	} | ||||
| } | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue