From 79b6df96fc6a47c94f35f2cb9e6bbe9d8eddf43b Mon Sep 17 00:00:00 2001 From: Hanlin Shi Date: Thu, 8 Apr 2021 19:29:40 +0000 Subject: [PATCH] Add tests for LB type service 1. create LB type svc with nodeport allocation set to false 1. create LB type svc with nodeport allocation unset 3. update LB type svc's nodeport allocation field Signed-off-by: Hanlin Shi --- pkg/apis/core/validation/validation_test.go | 35 +++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/pkg/apis/core/validation/validation_test.go b/pkg/apis/core/validation/validation_test.go index 6f5b6571cc8..2975b8ac712 100644 --- a/pkg/apis/core/validation/validation_test.go +++ b/pkg/apis/core/validation/validation_test.go @@ -10956,6 +10956,21 @@ func TestValidateServiceCreate(t *testing.T) { }, numErrs: 0, }, + { + name: "valid type - loadbalancer with allocateLoadBalancerNodePorts=false", + tweakSvc: func(s *core.Service) { + s.Spec.Type = core.ServiceTypeLoadBalancer + s.Spec.AllocateLoadBalancerNodePorts = utilpointer.BoolPtr(false) + }, + numErrs: 0, + }, + { + name: "invalid type - missing AllocateLoadBalancerNodePorts for loadbalancer type", + tweakSvc: func(s *core.Service) { + s.Spec.Type = core.ServiceTypeLoadBalancer + }, + numErrs: 1, + }, { name: "valid type loadbalancer 2 ports", tweakSvc: func(s *core.Service) { @@ -13529,6 +13544,26 @@ func TestValidateServiceUpdate(t *testing.T) { }, numErrs: 0, }, + { + name: "Service with LoadBalancer type can change its AllocateLoadBalancerNodePorts from true to false", + tweakSvc: func(oldSvc, newSvc *core.Service) { + oldSvc.Spec.Type = core.ServiceTypeLoadBalancer + oldSvc.Spec.AllocateLoadBalancerNodePorts = utilpointer.BoolPtr(true) + newSvc.Spec.Type = core.ServiceTypeLoadBalancer + newSvc.Spec.AllocateLoadBalancerNodePorts = utilpointer.BoolPtr(false) + }, + numErrs: 0, + }, + { + name: "Service with LoadBalancer type can change its AllocateLoadBalancerNodePorts from false to true", + tweakSvc: func(oldSvc, newSvc *core.Service) { + oldSvc.Spec.Type = core.ServiceTypeLoadBalancer + oldSvc.Spec.AllocateLoadBalancerNodePorts = utilpointer.BoolPtr(false) + newSvc.Spec.Type = core.ServiceTypeLoadBalancer + newSvc.Spec.AllocateLoadBalancerNodePorts = utilpointer.BoolPtr(true) + }, + numErrs: 0, + }, { name: "Service with NodePort type cannot change its set ClusterIP", tweakSvc: func(oldSvc, newSvc *core.Service) {