Skip to content

Commit

Permalink
Merge pull request #29457 from derekwaynecarr/service-node-port-quota…
Browse files Browse the repository at this point in the history
…-fix

Automatic merge from submit-queue

Quota was not counting services with multiple nodeports properly

```release-note
If a service of type node port declares multiple ports, quota on "services.nodeports" will charge for each port in the service.
```

Fixes #29456

/cc @kubernetes/rh-cluster-infra @sdminonne
  • Loading branch information
k8s-merge-robot authored Jul 28, 2016
2 parents 75c93b4 + 305411b commit e008087
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
3 changes: 2 additions & 1 deletion pkg/quota/evaluator/core/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ func ServiceUsageFunc(object runtime.Object) api.ResourceList {
result[api.ResourceServices] = resource.MustParse("1")
switch service.Spec.Type {
case api.ServiceTypeNodePort:
result[api.ResourceServicesNodePorts] = resource.MustParse("1")
value := resource.NewQuantity(int64(len(service.Spec.Ports)), resource.DecimalSI)
result[api.ResourceServicesNodePorts] = *value
case api.ServiceTypeLoadBalancer:
result[api.ResourceServicesLoadBalancers] = resource.MustParse("1")
}
Expand Down
24 changes: 24 additions & 0 deletions pkg/quota/evaluator/core/services_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,37 @@ func TestServiceEvaluatorUsage(t *testing.T) {
service: &api.Service{
Spec: api.ServiceSpec{
Type: api.ServiceTypeNodePort,
Ports: []api.ServicePort{
{
Port: 27443,
},
},
},
},
usage: api.ResourceList{
api.ResourceServices: resource.MustParse("1"),
api.ResourceServicesNodePorts: resource.MustParse("1"),
},
},
"multi-nodeports": {
service: &api.Service{
Spec: api.ServiceSpec{
Type: api.ServiceTypeNodePort,
Ports: []api.ServicePort{
{
Port: 27443,
},
{
Port: 27444,
},
},
},
},
usage: api.ResourceList{
api.ResourceServices: resource.MustParse("1"),
api.ResourceServicesNodePorts: resource.MustParse("2"),
},
},
}
for testName, testCase := range testCases {
actual := evaluator.Usage(testCase.service)
Expand Down
5 changes: 4 additions & 1 deletion plugin/pkg/admission/resourcequota/admission_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,10 @@ func TestAdmitHandlesOldObjects(t *testing.T) {
}
newService := &api.Service{
ObjectMeta: api.ObjectMeta{Name: "service", Namespace: "test"},
Spec: api.ServiceSpec{Type: api.ServiceTypeNodePort},
Spec: api.ServiceSpec{
Type: api.ServiceTypeNodePort,
Ports: []api.ServicePort{{Port: 1234}},
},
}
err := handler.Admit(admission.NewAttributesRecord(newService, oldService, api.Kind("Service").WithVersion("version"), newService.Namespace, newService.Name, api.Resource("services").WithVersion("version"), "", admission.Update, nil))
if err != nil {
Expand Down

0 comments on commit e008087

Please sign in to comment.