Skip to content

Commit

Permalink
Fix bug in node port counting in quota not counting multi-node ports
Browse files Browse the repository at this point in the history
  • Loading branch information
derekwaynecarr committed Jul 22, 2016
1 parent e20dbc0 commit 305411b
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 305411b

Please sign in to comment.