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 <shihanlin9@gmail.com>
This commit is contained in:
Hanlin Shi 2021-04-08 19:29:40 +00:00
parent 24592ca989
commit 79b6df96fc

View File

@ -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) {