Fix bug in node port counting in quota not counting multi-node ports
This commit is contained in:
		@@ -57,7 +57,8 @@ func ServiceUsageFunc(object runtime.Object) api.ResourceList {
 | 
				
			|||||||
		result[api.ResourceServices] = resource.MustParse("1")
 | 
							result[api.ResourceServices] = resource.MustParse("1")
 | 
				
			||||||
		switch service.Spec.Type {
 | 
							switch service.Spec.Type {
 | 
				
			||||||
		case api.ServiceTypeNodePort:
 | 
							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:
 | 
							case api.ServiceTypeLoadBalancer:
 | 
				
			||||||
			result[api.ResourceServicesLoadBalancers] = resource.MustParse("1")
 | 
								result[api.ResourceServicesLoadBalancers] = resource.MustParse("1")
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -71,6 +71,11 @@ func TestServiceEvaluatorUsage(t *testing.T) {
 | 
				
			|||||||
			service: &api.Service{
 | 
								service: &api.Service{
 | 
				
			||||||
				Spec: api.ServiceSpec{
 | 
									Spec: api.ServiceSpec{
 | 
				
			||||||
					Type: api.ServiceTypeNodePort,
 | 
										Type: api.ServiceTypeNodePort,
 | 
				
			||||||
 | 
										Ports: []api.ServicePort{
 | 
				
			||||||
 | 
											{
 | 
				
			||||||
 | 
												Port: 27443,
 | 
				
			||||||
 | 
											},
 | 
				
			||||||
 | 
										},
 | 
				
			||||||
				},
 | 
									},
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			usage: api.ResourceList{
 | 
								usage: api.ResourceList{
 | 
				
			||||||
@@ -78,6 +83,25 @@ func TestServiceEvaluatorUsage(t *testing.T) {
 | 
				
			|||||||
				api.ResourceServicesNodePorts: 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 {
 | 
						for testName, testCase := range testCases {
 | 
				
			||||||
		actual := evaluator.Usage(testCase.service)
 | 
							actual := evaluator.Usage(testCase.service)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -292,7 +292,10 @@ func TestAdmitHandlesOldObjects(t *testing.T) {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
	newService := &api.Service{
 | 
						newService := &api.Service{
 | 
				
			||||||
		ObjectMeta: api.ObjectMeta{Name: "service", Namespace: "test"},
 | 
							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))
 | 
						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 {
 | 
						if err != nil {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user