@@ -2200,7 +2200,7 @@ func TestAdmitZeroDeltaUsageWithoutCoveringQuota(t *testing.T) {
2200
2200
LimitedResources : []resourcequotaapi.LimitedResource {
2201
2201
{
2202
2202
Resource : "services" ,
2203
- MatchContains : []string {"services" },
2203
+ MatchContains : []string {"services.loadbalancers " },
2204
2204
},
2205
2205
},
2206
2206
}
@@ -2227,8 +2227,8 @@ func TestAdmitZeroDeltaUsageWithoutCoveringQuota(t *testing.T) {
2227
2227
}
2228
2228
}
2229
2229
2230
- // TestAdmitRejectDeltaUsageWithoutCoveringQuota verifies that resource quota is required for non zero delta requests.
2231
- func TestAdmitRejectDeltaUsageWithoutCoveringQuota (t * testing.T ) {
2230
+ // TestAdmitRejectIncreaseUsageWithoutCoveringQuota verifies that resource quota is required for delta requests that increase usage .
2231
+ func TestAdmitRejectIncreaseUsageWithoutCoveringQuota (t * testing.T ) {
2232
2232
kubeClient := fake .NewSimpleClientset ()
2233
2233
stopCh := make (chan struct {})
2234
2234
defer close (stopCh )
@@ -2243,7 +2243,53 @@ func TestAdmitRejectDeltaUsageWithoutCoveringQuota(t *testing.T) {
2243
2243
LimitedResources : []resourcequotaapi.LimitedResource {
2244
2244
{
2245
2245
Resource : "services" ,
2246
- MatchContains : []string {"services" },
2246
+ MatchContains : []string {"services.loadbalancers" },
2247
+ },
2248
+ },
2249
+ }
2250
+ quotaConfiguration := install .NewQuotaConfigurationForAdmission ()
2251
+ evaluator := NewQuotaEvaluator (quotaAccessor , quotaConfiguration .IgnoredResources (), generic .NewRegistry (quotaConfiguration .Evaluators ()), nil , config , 5 , stopCh )
2252
+
2253
+ handler := & QuotaAdmission {
2254
+ Handler : admission .NewHandler (admission .Create , admission .Update ),
2255
+ evaluator : evaluator ,
2256
+ }
2257
+
2258
+ existingService := & api.Service {
2259
+ ObjectMeta : metav1.ObjectMeta {Name : "service" , Namespace : "test" , ResourceVersion : "1" },
2260
+ Spec : api.ServiceSpec {
2261
+ Type : api .ServiceTypeNodePort ,
2262
+ Ports : []api.ServicePort {{Port : 1234 }},
2263
+ },
2264
+ }
2265
+ newService := & api.Service {
2266
+ ObjectMeta : metav1.ObjectMeta {Name : "service" , Namespace : "test" },
2267
+ Spec : api.ServiceSpec {Type : api .ServiceTypeLoadBalancer },
2268
+ }
2269
+
2270
+ err := handler .Validate (admission .NewAttributesRecord (newService , existingService , api .Kind ("Service" ).WithVersion ("version" ), newService .Namespace , newService .Name , corev1 .Resource ("services" ).WithVersion ("version" ), "" , admission .Update , false , nil ), nil )
2271
+ if err == nil {
2272
+ t .Errorf ("Expected an error for consuming a limited resource without quota." )
2273
+ }
2274
+ }
2275
+
2276
+ // TestAdmitAllowDecreaseUsageWithoutCoveringQuota verifies that resource quota is not required for delta requests that decrease usage.
2277
+ func TestAdmitAllowDecreaseUsageWithoutCoveringQuota (t * testing.T ) {
2278
+ kubeClient := fake .NewSimpleClientset ()
2279
+ stopCh := make (chan struct {})
2280
+ defer close (stopCh )
2281
+
2282
+ informerFactory := informers .NewSharedInformerFactory (kubeClient , controller .NoResyncPeriodFunc ())
2283
+ quotaAccessor , _ := newQuotaAccessor ()
2284
+ quotaAccessor .client = kubeClient
2285
+ quotaAccessor .lister = informerFactory .Core ().V1 ().ResourceQuotas ().Lister ()
2286
+
2287
+ // disable services unless there is a covering quota.
2288
+ config := & resourcequotaapi.Configuration {
2289
+ LimitedResources : []resourcequotaapi.LimitedResource {
2290
+ {
2291
+ Resource : "services" ,
2292
+ MatchContains : []string {"services.loadbalancers" },
2247
2293
},
2248
2294
},
2249
2295
}
@@ -2268,7 +2314,7 @@ func TestAdmitRejectDeltaUsageWithoutCoveringQuota(t *testing.T) {
2268
2314
}
2269
2315
2270
2316
err := handler .Validate (admission .NewAttributesRecord (newService , existingService , api .Kind ("Service" ).WithVersion ("version" ), newService .Namespace , newService .Name , corev1 .Resource ("services" ).WithVersion ("version" ), "" , admission .Update , false , nil ), nil )
2271
- if err = = nil {
2272
- t .Errorf ("Expected an error for consuming a limited resource without quota." )
2317
+ if err ! = nil {
2318
+ t .Errorf ("Expected no error for decreasing a limited resource without quota, got %v" , err )
2273
2319
}
2274
2320
}
0 commit comments