Chore: cleanup whitespaces

This commit is contained in:
mowangdk 2023-04-25 10:55:52 +08:00
parent 3d8f7233da
commit 06993afdd6

View File

@ -178,47 +178,41 @@ func TestSyncLoadBalancerIfNeeded(t *testing.T) {
expectDeleteAttempt bool expectDeleteAttempt bool
expectPatchStatus bool expectPatchStatus bool
expectPatchFinalizer bool expectPatchFinalizer bool
}{ }{{
{
desc: "service doesn't want LB", desc: "service doesn't want LB",
service: newService("no-external-balancer", v1.ServiceTypeClusterIP), service: newService("no-external-balancer", v1.ServiceTypeClusterIP),
expectOp: deleteLoadBalancer, expectOp: deleteLoadBalancer,
expectPatchStatus: false, expectPatchStatus: false,
}, }, {
{
desc: "udp service that wants LB", desc: "udp service that wants LB",
service: newService("udp-service", v1.ServiceTypeLoadBalancer, tweakAddPorts(v1.ProtocolUDP, 0)), service: newService("udp-service", v1.ServiceTypeLoadBalancer, tweakAddPorts(v1.ProtocolUDP, 0)),
expectOp: ensureLoadBalancer, expectOp: ensureLoadBalancer,
expectCreateAttempt: true, expectCreateAttempt: true,
expectPatchStatus: true, expectPatchStatus: true,
expectPatchFinalizer: true, expectPatchFinalizer: true,
}, }, {
{
desc: "tcp service that wants LB", desc: "tcp service that wants LB",
service: newService("basic-service1", v1.ServiceTypeLoadBalancer, tweakAddPorts(v1.ProtocolTCP, 0)), service: newService("basic-service1", v1.ServiceTypeLoadBalancer, tweakAddPorts(v1.ProtocolTCP, 0)),
expectOp: ensureLoadBalancer, expectOp: ensureLoadBalancer,
expectCreateAttempt: true, expectCreateAttempt: true,
expectPatchStatus: true, expectPatchStatus: true,
expectPatchFinalizer: true, expectPatchFinalizer: true,
}, }, {
{
desc: "sctp service that wants LB", desc: "sctp service that wants LB",
service: newService("sctp-service", v1.ServiceTypeLoadBalancer, tweakAddPorts(v1.ProtocolSCTP, 0)), service: newService("sctp-service", v1.ServiceTypeLoadBalancer, tweakAddPorts(v1.ProtocolSCTP, 0)),
expectOp: ensureLoadBalancer, expectOp: ensureLoadBalancer,
expectCreateAttempt: true, expectCreateAttempt: true,
expectPatchStatus: true, expectPatchStatus: true,
expectPatchFinalizer: true, expectPatchFinalizer: true,
}, }, {
{
desc: "service specifies loadBalancerClass", desc: "service specifies loadBalancerClass",
service: newService("with-external-balancer", v1.ServiceTypeLoadBalancer, tweakAddLBClass(utilpointer.String("custom-loadbalancer"))), service: newService("with-external-balancer", v1.ServiceTypeLoadBalancer, tweakAddLBClass(utilpointer.String("custom-loadbalancer"))),
expectOp: deleteLoadBalancer, expectOp: deleteLoadBalancer,
expectCreateAttempt: false, expectCreateAttempt: false,
expectPatchStatus: false, expectPatchStatus: false,
expectPatchFinalizer: false, expectPatchFinalizer: false,
}, }, {
// Finalizer test cases below. // Finalizer test cases below.
{
desc: "service with finalizer that no longer wants LB", desc: "service with finalizer that no longer wants LB",
service: newService("no-external-balancer", v1.ServiceTypeClusterIP, tweakAddLBIngress("8.8.8.8"), tweakAddFinalizers(servicehelper.LoadBalancerCleanupFinalizer)), service: newService("no-external-balancer", v1.ServiceTypeClusterIP, tweakAddLBIngress("8.8.8.8"), tweakAddFinalizers(servicehelper.LoadBalancerCleanupFinalizer)),
lbExists: true, lbExists: true,
@ -226,8 +220,7 @@ func TestSyncLoadBalancerIfNeeded(t *testing.T) {
expectDeleteAttempt: true, expectDeleteAttempt: true,
expectPatchStatus: true, expectPatchStatus: true,
expectPatchFinalizer: true, expectPatchFinalizer: true,
}, }, {
{
desc: "service that needs cleanup", desc: "service that needs cleanup",
service: newService("basic-service1", v1.ServiceTypeLoadBalancer, tweakAddLBIngress("8.8.8.8"), tweakAddPorts(v1.ProtocolTCP, 0), tweakAddFinalizers(servicehelper.LoadBalancerCleanupFinalizer), tweakAddDeletionTimestamp(time.Now())), service: newService("basic-service1", v1.ServiceTypeLoadBalancer, tweakAddLBIngress("8.8.8.8"), tweakAddPorts(v1.ProtocolTCP, 0), tweakAddFinalizers(servicehelper.LoadBalancerCleanupFinalizer), tweakAddDeletionTimestamp(time.Now())),
lbExists: true, lbExists: true,
@ -235,16 +228,14 @@ func TestSyncLoadBalancerIfNeeded(t *testing.T) {
expectDeleteAttempt: true, expectDeleteAttempt: true,
expectPatchStatus: true, expectPatchStatus: true,
expectPatchFinalizer: true, expectPatchFinalizer: true,
}, }, {
{
desc: "service with finalizer that wants LB", desc: "service with finalizer that wants LB",
service: newService("basic-service1", v1.ServiceTypeLoadBalancer, tweakAddPorts(v1.ProtocolTCP, 0), tweakAddFinalizers(servicehelper.LoadBalancerCleanupFinalizer)), service: newService("basic-service1", v1.ServiceTypeLoadBalancer, tweakAddPorts(v1.ProtocolTCP, 0), tweakAddFinalizers(servicehelper.LoadBalancerCleanupFinalizer)),
expectOp: ensureLoadBalancer, expectOp: ensureLoadBalancer,
expectCreateAttempt: true, expectCreateAttempt: true,
expectPatchStatus: true, expectPatchStatus: true,
expectPatchFinalizer: false, expectPatchFinalizer: false,
}, }}
}
for _, tc := range testCases { for _, tc := range testCases {
t.Run(tc.desc, func(t *testing.T) { t.Run(tc.desc, func(t *testing.T) {
@ -346,14 +337,12 @@ func TestUpdateNodesInExternalLoadBalancer(t *testing.T) {
services []*v1.Service services []*v1.Service
expectedUpdateCalls []fakecloud.UpdateBalancerCall expectedUpdateCalls []fakecloud.UpdateBalancerCall
workers int workers int
}{ }{{
{
desc: "No services present: no calls should be made.", desc: "No services present: no calls should be made.",
services: []*v1.Service{}, services: []*v1.Service{},
expectedUpdateCalls: nil, expectedUpdateCalls: nil,
workers: 1, workers: 1,
}, }, {
{
desc: "Services do not have external load balancers: no calls should be made.", desc: "Services do not have external load balancers: no calls should be made.",
services: []*v1.Service{ services: []*v1.Service{
newService("s0", v1.ServiceTypeClusterIP), newService("s0", v1.ServiceTypeClusterIP),
@ -361,8 +350,7 @@ func TestUpdateNodesInExternalLoadBalancer(t *testing.T) {
}, },
expectedUpdateCalls: nil, expectedUpdateCalls: nil,
workers: 2, workers: 2,
}, }, {
{
desc: "Services does have an external load balancer: one call should be made.", desc: "Services does have an external load balancer: one call should be made.",
services: []*v1.Service{ services: []*v1.Service{
newService("s0", v1.ServiceTypeLoadBalancer), newService("s0", v1.ServiceTypeLoadBalancer),
@ -371,8 +359,7 @@ func TestUpdateNodesInExternalLoadBalancer(t *testing.T) {
{Service: newService("s0", v1.ServiceTypeLoadBalancer), Hosts: nodes}, {Service: newService("s0", v1.ServiceTypeLoadBalancer), Hosts: nodes},
}, },
workers: 3, workers: 3,
}, }, {
{
desc: "Three services have an external load balancer: three calls.", desc: "Three services have an external load balancer: three calls.",
services: []*v1.Service{ services: []*v1.Service{
newService("s0", v1.ServiceTypeLoadBalancer), newService("s0", v1.ServiceTypeLoadBalancer),
@ -385,8 +372,7 @@ func TestUpdateNodesInExternalLoadBalancer(t *testing.T) {
{Service: newService("s2", v1.ServiceTypeLoadBalancer), Hosts: nodes}, {Service: newService("s2", v1.ServiceTypeLoadBalancer), Hosts: nodes},
}, },
workers: 4, workers: 4,
}, }, {
{
desc: "Two services have an external load balancer and two don't: two calls.", desc: "Two services have an external load balancer and two don't: two calls.",
services: []*v1.Service{ services: []*v1.Service{
newService("s0", v1.ServiceTypeNodePort), newService("s0", v1.ServiceTypeNodePort),
@ -399,8 +385,7 @@ func TestUpdateNodesInExternalLoadBalancer(t *testing.T) {
{Service: newService("s3", v1.ServiceTypeLoadBalancer), Hosts: nodes}, {Service: newService("s3", v1.ServiceTypeLoadBalancer), Hosts: nodes},
}, },
workers: 5, workers: 5,
}, }, {
{
desc: "One service has an external load balancer and one is nil: one call.", desc: "One service has an external load balancer and one is nil: one call.",
services: []*v1.Service{ services: []*v1.Service{
newService("s0", v1.ServiceTypeLoadBalancer), newService("s0", v1.ServiceTypeLoadBalancer),
@ -410,8 +395,7 @@ func TestUpdateNodesInExternalLoadBalancer(t *testing.T) {
{Service: newService("s0", v1.ServiceTypeLoadBalancer), Hosts: nodes}, {Service: newService("s0", v1.ServiceTypeLoadBalancer), Hosts: nodes},
}, },
workers: 6, workers: 6,
}, }, {
{
desc: "Four services have external load balancer with only 2 workers", desc: "Four services have external load balancer with only 2 workers",
services: []*v1.Service{ services: []*v1.Service{
newService("s0", v1.ServiceTypeLoadBalancer), newService("s0", v1.ServiceTypeLoadBalancer),
@ -426,8 +410,7 @@ func TestUpdateNodesInExternalLoadBalancer(t *testing.T) {
{Service: newService("s4", v1.ServiceTypeLoadBalancer), Hosts: nodes}, {Service: newService("s4", v1.ServiceTypeLoadBalancer), Hosts: nodes},
}, },
workers: 2, workers: 2,
}, }}
}
for _, item := range table { for _, item := range table {
t.Run(item.desc, func(t *testing.T) { t.Run(item.desc, func(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
@ -468,8 +451,7 @@ func TestNodeChangesForExternalTrafficPolicyLocalServices(t *testing.T) {
expectedUpdateCalls []fakecloud.UpdateBalancerCall expectedUpdateCalls []fakecloud.UpdateBalancerCall
stateChanges []stateChanges stateChanges []stateChanges
initialState []*v1.Node initialState []*v1.Node
}{ }{{
{
desc: "No node changes", desc: "No node changes",
initialState: []*v1.Node{node1, node2, node3}, initialState: []*v1.Node{node1, node2, node3},
stateChanges: []stateChanges{ stateChanges: []stateChanges{
@ -478,8 +460,7 @@ func TestNodeChangesForExternalTrafficPolicyLocalServices(t *testing.T) {
}, },
}, },
expectedUpdateCalls: []fakecloud.UpdateBalancerCall{}, expectedUpdateCalls: []fakecloud.UpdateBalancerCall{},
}, }, {
{
desc: "1 new node gets added", desc: "1 new node gets added",
initialState: []*v1.Node{node1, node2}, initialState: []*v1.Node{node1, node2},
stateChanges: []stateChanges{ stateChanges: []stateChanges{
@ -492,8 +473,7 @@ func TestNodeChangesForExternalTrafficPolicyLocalServices(t *testing.T) {
{Service: etpLocalservice2, Hosts: []*v1.Node{node1, node2, node3}}, {Service: etpLocalservice2, Hosts: []*v1.Node{node1, node2, node3}},
{Service: service3, Hosts: []*v1.Node{node1, node2, node3}}, {Service: service3, Hosts: []*v1.Node{node1, node2, node3}},
}, },
}, }, {
{
desc: "1 new node gets added - with retries", desc: "1 new node gets added - with retries",
initialState: []*v1.Node{node1, node2}, initialState: []*v1.Node{node1, node2},
stateChanges: []stateChanges{ stateChanges: []stateChanges{
@ -510,8 +490,7 @@ func TestNodeChangesForExternalTrafficPolicyLocalServices(t *testing.T) {
{Service: etpLocalservice2, Hosts: []*v1.Node{node1, node2, node3}}, {Service: etpLocalservice2, Hosts: []*v1.Node{node1, node2, node3}},
{Service: service3, Hosts: []*v1.Node{node1, node2, node3}}, {Service: service3, Hosts: []*v1.Node{node1, node2, node3}},
}, },
}, }, {
{
desc: "1 node goes NotReady", desc: "1 node goes NotReady",
initialState: []*v1.Node{node1, node2, node3}, initialState: []*v1.Node{node1, node2, node3},
stateChanges: []stateChanges{ stateChanges: []stateChanges{
@ -522,8 +501,7 @@ func TestNodeChangesForExternalTrafficPolicyLocalServices(t *testing.T) {
expectedUpdateCalls: []fakecloud.UpdateBalancerCall{ expectedUpdateCalls: []fakecloud.UpdateBalancerCall{
{Service: service3, Hosts: []*v1.Node{node1, node3}}, {Service: service3, Hosts: []*v1.Node{node1, node3}},
}, },
}, }, {
{
desc: "1 node gets Tainted", desc: "1 node gets Tainted",
initialState: []*v1.Node{node1, node2, node3}, initialState: []*v1.Node{node1, node2, node3},
stateChanges: []stateChanges{ stateChanges: []stateChanges{
@ -536,8 +514,7 @@ func TestNodeChangesForExternalTrafficPolicyLocalServices(t *testing.T) {
{Service: etpLocalservice2, Hosts: []*v1.Node{node1, node3}}, {Service: etpLocalservice2, Hosts: []*v1.Node{node1, node3}},
{Service: service3, Hosts: []*v1.Node{node1, node3}}, {Service: service3, Hosts: []*v1.Node{node1, node3}},
}, },
}, }, {
{
desc: "1 node goes Ready", desc: "1 node goes Ready",
initialState: []*v1.Node{node1, node2NotReady, node3}, initialState: []*v1.Node{node1, node2NotReady, node3},
stateChanges: []stateChanges{ stateChanges: []stateChanges{
@ -548,8 +525,7 @@ func TestNodeChangesForExternalTrafficPolicyLocalServices(t *testing.T) {
expectedUpdateCalls: []fakecloud.UpdateBalancerCall{ expectedUpdateCalls: []fakecloud.UpdateBalancerCall{
{Service: service3, Hosts: []*v1.Node{node1, node2, node3}}, {Service: service3, Hosts: []*v1.Node{node1, node2, node3}},
}, },
}, }, {
{
desc: "1 node get excluded", desc: "1 node get excluded",
initialState: []*v1.Node{node1, node2, node3}, initialState: []*v1.Node{node1, node2, node3},
stateChanges: []stateChanges{ stateChanges: []stateChanges{
@ -562,8 +538,7 @@ func TestNodeChangesForExternalTrafficPolicyLocalServices(t *testing.T) {
{Service: etpLocalservice2, Hosts: []*v1.Node{node1, node3}}, {Service: etpLocalservice2, Hosts: []*v1.Node{node1, node3}},
{Service: service3, Hosts: []*v1.Node{node1, node3}}, {Service: service3, Hosts: []*v1.Node{node1, node3}},
}, },
}, }, {
{
desc: "1 old node gets deleted", desc: "1 old node gets deleted",
initialState: []*v1.Node{node1, node2, node3}, initialState: []*v1.Node{node1, node2, node3},
stateChanges: []stateChanges{ stateChanges: []stateChanges{
@ -576,8 +551,7 @@ func TestNodeChangesForExternalTrafficPolicyLocalServices(t *testing.T) {
{Service: etpLocalservice2, Hosts: []*v1.Node{node1, node2}}, {Service: etpLocalservice2, Hosts: []*v1.Node{node1, node2}},
{Service: service3, Hosts: []*v1.Node{node1, node2}}, {Service: service3, Hosts: []*v1.Node{node1, node2}},
}, },
}, }, {
{
desc: "1 spurious node update", desc: "1 spurious node update",
initialState: []*v1.Node{node1, node2, node3}, initialState: []*v1.Node{node1, node2, node3},
stateChanges: []stateChanges{ stateChanges: []stateChanges{
@ -586,8 +560,7 @@ func TestNodeChangesForExternalTrafficPolicyLocalServices(t *testing.T) {
}, },
}, },
expectedUpdateCalls: []fakecloud.UpdateBalancerCall{}, expectedUpdateCalls: []fakecloud.UpdateBalancerCall{},
}, }} {
} {
t.Run(tc.desc, func(t *testing.T) { t.Run(tc.desc, func(t *testing.T) {
controller, cloud, _ := newController() controller, cloud, _ := newController()
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
@ -641,8 +614,7 @@ func TestNodeChangesForStableNodeSetEnabled(t *testing.T) {
expectedUpdateCalls []fakecloud.UpdateBalancerCall expectedUpdateCalls []fakecloud.UpdateBalancerCall
stateChanges []stateChanges stateChanges []stateChanges
initialState []*v1.Node initialState []*v1.Node
}{ }{{
{
desc: "No node changes", desc: "No node changes",
initialState: []*v1.Node{node1, node2, node3}, initialState: []*v1.Node{node1, node2, node3},
stateChanges: []stateChanges{ stateChanges: []stateChanges{
@ -651,8 +623,7 @@ func TestNodeChangesForStableNodeSetEnabled(t *testing.T) {
}, },
}, },
expectedUpdateCalls: []fakecloud.UpdateBalancerCall{}, expectedUpdateCalls: []fakecloud.UpdateBalancerCall{},
}, }, {
{
desc: "1 new node gets added", desc: "1 new node gets added",
initialState: []*v1.Node{node1, node2}, initialState: []*v1.Node{node1, node2},
stateChanges: []stateChanges{ stateChanges: []stateChanges{
@ -665,8 +636,7 @@ func TestNodeChangesForStableNodeSetEnabled(t *testing.T) {
{Service: etpLocalservice2, Hosts: []*v1.Node{node1, node2, node3}}, {Service: etpLocalservice2, Hosts: []*v1.Node{node1, node2, node3}},
{Service: service3, Hosts: []*v1.Node{node1, node2, node3}}, {Service: service3, Hosts: []*v1.Node{node1, node2, node3}},
}, },
}, }, {
{
desc: "1 new node gets added - with retries", desc: "1 new node gets added - with retries",
initialState: []*v1.Node{node1, node2}, initialState: []*v1.Node{node1, node2},
stateChanges: []stateChanges{ stateChanges: []stateChanges{
@ -683,8 +653,7 @@ func TestNodeChangesForStableNodeSetEnabled(t *testing.T) {
{Service: etpLocalservice2, Hosts: []*v1.Node{node1, node2, node3}}, {Service: etpLocalservice2, Hosts: []*v1.Node{node1, node2, node3}},
{Service: service3, Hosts: []*v1.Node{node1, node2, node3}}, {Service: service3, Hosts: []*v1.Node{node1, node2, node3}},
}, },
}, }, {
{
desc: "1 node goes NotReady", desc: "1 node goes NotReady",
initialState: []*v1.Node{node1, node2, node3}, initialState: []*v1.Node{node1, node2, node3},
stateChanges: []stateChanges{ stateChanges: []stateChanges{
@ -693,8 +662,7 @@ func TestNodeChangesForStableNodeSetEnabled(t *testing.T) {
}, },
}, },
expectedUpdateCalls: []fakecloud.UpdateBalancerCall{}, expectedUpdateCalls: []fakecloud.UpdateBalancerCall{},
}, }, {
{
desc: "1 node gets Tainted", desc: "1 node gets Tainted",
initialState: []*v1.Node{node1, node2, node3}, initialState: []*v1.Node{node1, node2, node3},
stateChanges: []stateChanges{ stateChanges: []stateChanges{
@ -707,8 +675,7 @@ func TestNodeChangesForStableNodeSetEnabled(t *testing.T) {
{Service: etpLocalservice2, Hosts: []*v1.Node{node1, node3}}, {Service: etpLocalservice2, Hosts: []*v1.Node{node1, node3}},
{Service: service3, Hosts: []*v1.Node{node1, node3}}, {Service: service3, Hosts: []*v1.Node{node1, node3}},
}, },
}, }, {
{
desc: "1 node goes Ready", desc: "1 node goes Ready",
initialState: []*v1.Node{node1, node2NotReady, node3}, initialState: []*v1.Node{node1, node2NotReady, node3},
stateChanges: []stateChanges{ stateChanges: []stateChanges{
@ -717,8 +684,7 @@ func TestNodeChangesForStableNodeSetEnabled(t *testing.T) {
}, },
}, },
expectedUpdateCalls: []fakecloud.UpdateBalancerCall{}, expectedUpdateCalls: []fakecloud.UpdateBalancerCall{},
}, }, {
{
desc: "1 node get excluded", desc: "1 node get excluded",
initialState: []*v1.Node{node1, node2, node3}, initialState: []*v1.Node{node1, node2, node3},
stateChanges: []stateChanges{ stateChanges: []stateChanges{
@ -731,8 +697,7 @@ func TestNodeChangesForStableNodeSetEnabled(t *testing.T) {
{Service: etpLocalservice2, Hosts: []*v1.Node{node1, node3}}, {Service: etpLocalservice2, Hosts: []*v1.Node{node1, node3}},
{Service: service3, Hosts: []*v1.Node{node1, node3}}, {Service: service3, Hosts: []*v1.Node{node1, node3}},
}, },
}, }, {
{
desc: "1 old node gets deleted", desc: "1 old node gets deleted",
initialState: []*v1.Node{node1, node2, node3}, initialState: []*v1.Node{node1, node2, node3},
stateChanges: []stateChanges{ stateChanges: []stateChanges{
@ -745,8 +710,7 @@ func TestNodeChangesForStableNodeSetEnabled(t *testing.T) {
{Service: etpLocalservice2, Hosts: []*v1.Node{node1, node2}}, {Service: etpLocalservice2, Hosts: []*v1.Node{node1, node2}},
{Service: service3, Hosts: []*v1.Node{node1, node2}}, {Service: service3, Hosts: []*v1.Node{node1, node2}},
}, },
}, }, {
{
desc: "1 node marked for deletion", desc: "1 node marked for deletion",
initialState: []*v1.Node{node1, node2, node3}, initialState: []*v1.Node{node1, node2, node3},
stateChanges: []stateChanges{ stateChanges: []stateChanges{
@ -759,8 +723,7 @@ func TestNodeChangesForStableNodeSetEnabled(t *testing.T) {
{Service: etpLocalservice2, Hosts: []*v1.Node{node1, node3}}, {Service: etpLocalservice2, Hosts: []*v1.Node{node1, node3}},
{Service: service3, Hosts: []*v1.Node{node1, node3}}, {Service: service3, Hosts: []*v1.Node{node1, node3}},
}, },
}, }, {
{
desc: "1 spurious node update", desc: "1 spurious node update",
initialState: []*v1.Node{node1, node2, node3}, initialState: []*v1.Node{node1, node2, node3},
stateChanges: []stateChanges{ stateChanges: []stateChanges{
@ -769,8 +732,7 @@ func TestNodeChangesForStableNodeSetEnabled(t *testing.T) {
}, },
}, },
expectedUpdateCalls: []fakecloud.UpdateBalancerCall{}, expectedUpdateCalls: []fakecloud.UpdateBalancerCall{},
}, }} {
} {
t.Run(tc.desc, func(t *testing.T) { t.Run(tc.desc, func(t *testing.T) {
controller, cloud, _ := newController() controller, cloud, _ := newController()
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
@ -824,8 +786,7 @@ func TestNodeChangesInExternalLoadBalancer(t *testing.T) {
worker int worker int
nodeListerErr error nodeListerErr error
expectedRetryServices sets.String expectedRetryServices sets.String
}{ }{{
{
desc: "only 1 node", desc: "only 1 node",
nodes: []*v1.Node{node1}, nodes: []*v1.Node{node1},
expectedUpdateCalls: []fakecloud.UpdateBalancerCall{ expectedUpdateCalls: []fakecloud.UpdateBalancerCall{
@ -837,8 +798,7 @@ func TestNodeChangesInExternalLoadBalancer(t *testing.T) {
worker: 3, worker: 3,
nodeListerErr: nil, nodeListerErr: nil,
expectedRetryServices: sets.NewString(), expectedRetryServices: sets.NewString(),
}, }, {
{
desc: "2 nodes", desc: "2 nodes",
nodes: []*v1.Node{node1, node2}, nodes: []*v1.Node{node1, node2},
expectedUpdateCalls: []fakecloud.UpdateBalancerCall{ expectedUpdateCalls: []fakecloud.UpdateBalancerCall{
@ -850,8 +810,7 @@ func TestNodeChangesInExternalLoadBalancer(t *testing.T) {
worker: 1, worker: 1,
nodeListerErr: nil, nodeListerErr: nil,
expectedRetryServices: sets.NewString(), expectedRetryServices: sets.NewString(),
}, }, {
{
desc: "4 nodes", desc: "4 nodes",
nodes: []*v1.Node{node1, node2, node3, node4}, nodes: []*v1.Node{node1, node2, node3, node4},
expectedUpdateCalls: []fakecloud.UpdateBalancerCall{ expectedUpdateCalls: []fakecloud.UpdateBalancerCall{
@ -863,24 +822,21 @@ func TestNodeChangesInExternalLoadBalancer(t *testing.T) {
worker: 3, worker: 3,
nodeListerErr: nil, nodeListerErr: nil,
expectedRetryServices: sets.NewString(), expectedRetryServices: sets.NewString(),
}, }, {
{
desc: "error occur during sync", desc: "error occur during sync",
nodes: []*v1.Node{node1, node2, node3, node4}, nodes: []*v1.Node{node1, node2, node3, node4},
expectedUpdateCalls: []fakecloud.UpdateBalancerCall{}, expectedUpdateCalls: []fakecloud.UpdateBalancerCall{},
worker: 3, worker: 3,
nodeListerErr: fmt.Errorf("random error"), nodeListerErr: fmt.Errorf("random error"),
expectedRetryServices: serviceNames, expectedRetryServices: serviceNames,
}, }, {
{
desc: "error occur during sync with 1 workers", desc: "error occur during sync with 1 workers",
nodes: []*v1.Node{node1, node2, node3, node4}, nodes: []*v1.Node{node1, node2, node3, node4},
expectedUpdateCalls: []fakecloud.UpdateBalancerCall{}, expectedUpdateCalls: []fakecloud.UpdateBalancerCall{},
worker: 1, worker: 1,
nodeListerErr: fmt.Errorf("random error"), nodeListerErr: fmt.Errorf("random error"),
expectedRetryServices: serviceNames, expectedRetryServices: serviceNames,
}, }} {
} {
t.Run(tc.desc, func(t *testing.T) { t.Run(tc.desc, func(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
defer cancel() defer cancel()
@ -930,8 +886,7 @@ func TestProcessServiceCreateOrUpdate(t *testing.T) {
updateFn func(*v1.Service) *v1.Service //Manipulate the structure updateFn func(*v1.Service) *v1.Service //Manipulate the structure
svc *v1.Service svc *v1.Service
expectedFn func(*v1.Service, error) error //Error comparison function expectedFn func(*v1.Service, error) error //Error comparison function
}{ }{{
{
testName: "If updating a valid service", testName: "If updating a valid service",
key: "validKey", key: "validKey",
svc: defaultExternalService(), svc: defaultExternalService(),
@ -944,8 +899,7 @@ func TestProcessServiceCreateOrUpdate(t *testing.T) {
expectedFn: func(svc *v1.Service, err error) error { expectedFn: func(svc *v1.Service, err error) error {
return err return err
}, },
}, }, {
{
testName: "If Updating Loadbalancer IP", testName: "If Updating Loadbalancer IP",
key: "default/sync-test-name", key: "default/sync-test-name",
svc: newService("sync-test-name", v1.ServiceTypeLoadBalancer), svc: newService("sync-test-name", v1.ServiceTypeLoadBalancer),
@ -990,8 +944,7 @@ func TestProcessServiceCreateOrUpdate(t *testing.T) {
} }
return nil return nil
}, },
}, }}
}
for _, tc := range testCases { for _, tc := range testCases {
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
@ -1019,18 +972,15 @@ func TestProcessServiceCreateOrUpdateK8sError(t *testing.T) {
desc string desc string
k8sErr error k8sErr error
expectErr error expectErr error
}{ }{{
{
desc: "conflict error", desc: "conflict error",
k8sErr: conflictErr, k8sErr: conflictErr,
expectErr: fmt.Errorf("failed to update load balancer status: %v", conflictErr), expectErr: fmt.Errorf("failed to update load balancer status: %v", conflictErr),
}, }, {
{
desc: "not found error", desc: "not found error",
k8sErr: notFoundErr, k8sErr: notFoundErr,
expectErr: nil, expectErr: nil,
}, }}
}
for _, tc := range testCases { for _, tc := range testCases {
t.Run(tc.desc, func(t *testing.T) { t.Run(tc.desc, func(t *testing.T) {
@ -1161,8 +1111,7 @@ func TestProcessServiceDeletion(t *testing.T) {
testName string testName string
updateFn func(*Controller) // Update function used to manipulate srv and controller values updateFn func(*Controller) // Update function used to manipulate srv and controller values
expectedFn func(svcErr error) error // Function to check if the returned value is expected expectedFn func(svcErr error) error // Function to check if the returned value is expected
}{ }{{
{
testName: "If a non-existent service is deleted", testName: "If a non-existent service is deleted",
updateFn: func(controller *Controller) { updateFn: func(controller *Controller) {
// Does not do anything // Does not do anything
@ -1170,8 +1119,7 @@ func TestProcessServiceDeletion(t *testing.T) {
expectedFn: func(svcErr error) error { expectedFn: func(svcErr error) error {
return svcErr return svcErr
}, },
}, }, {
{
testName: "If cloudprovided failed to delete the service", testName: "If cloudprovided failed to delete the service",
updateFn: func(controller *Controller) { updateFn: func(controller *Controller) {
@ -1190,8 +1138,7 @@ func TestProcessServiceDeletion(t *testing.T) {
return nil return nil
}, },
}, }, {
{
testName: "If delete was successful", testName: "If delete was successful",
updateFn: func(controller *Controller) { updateFn: func(controller *Controller) {
@ -1215,8 +1162,7 @@ func TestProcessServiceDeletion(t *testing.T) {
return nil return nil
}, },
}, }}
}
for _, tc := range testCases { for _, tc := range testCases {
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
@ -1249,13 +1195,11 @@ func TestNeedsCleanup(t *testing.T) {
desc string desc string
svc *v1.Service svc *v1.Service
expectNeedsCleanup bool expectNeedsCleanup bool
}{ }{{
{
desc: "service without finalizer", desc: "service without finalizer",
svc: &v1.Service{}, svc: &v1.Service{},
expectNeedsCleanup: false, expectNeedsCleanup: false,
}, }, {
{
desc: "service with finalizer without timestamp without LB", desc: "service with finalizer without timestamp without LB",
svc: &v1.Service{ svc: &v1.Service{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
@ -1266,8 +1210,7 @@ func TestNeedsCleanup(t *testing.T) {
}, },
}, },
expectNeedsCleanup: true, expectNeedsCleanup: true,
}, }, {
{
desc: "service with finalizer without timestamp with LB", desc: "service with finalizer without timestamp with LB",
svc: &v1.Service{ svc: &v1.Service{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
@ -1278,8 +1221,7 @@ func TestNeedsCleanup(t *testing.T) {
}, },
}, },
expectNeedsCleanup: false, expectNeedsCleanup: false,
}, }, {
{
desc: "service with finalizer with timestamp", desc: "service with finalizer with timestamp",
svc: &v1.Service{ svc: &v1.Service{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
@ -1290,8 +1232,7 @@ func TestNeedsCleanup(t *testing.T) {
}, },
}, },
expectNeedsCleanup: true, expectNeedsCleanup: true,
}, }}
}
for _, tc := range testCases { for _, tc := range testCases {
t.Run(tc.desc, func(t *testing.T) { t.Run(tc.desc, func(t *testing.T) {
@ -1312,8 +1253,7 @@ func TestNeedsUpdate(t *testing.T) {
updateFn func() //Function to update the service object updateFn func() //Function to update the service object
expectedNeedsUpdate bool //needsupdate always returns bool expectedNeedsUpdate bool //needsupdate always returns bool
}{ }{{
{
testName: "If the service type is changed from LoadBalancer to ClusterIP", testName: "If the service type is changed from LoadBalancer to ClusterIP",
updateFn: func() { updateFn: func() {
oldSvc = defaultExternalService() oldSvc = defaultExternalService()
@ -1321,8 +1261,7 @@ func TestNeedsUpdate(t *testing.T) {
newSvc.Spec.Type = v1.ServiceTypeClusterIP newSvc.Spec.Type = v1.ServiceTypeClusterIP
}, },
expectedNeedsUpdate: true, expectedNeedsUpdate: true,
}, }, {
{
testName: "If the Ports are different", testName: "If the Ports are different",
updateFn: func() { updateFn: func() {
oldSvc = defaultExternalService() oldSvc = defaultExternalService()
@ -1352,8 +1291,7 @@ func TestNeedsUpdate(t *testing.T) {
}, },
expectedNeedsUpdate: true, expectedNeedsUpdate: true,
}, }, {
{
testName: "If external ip counts are different", testName: "If external ip counts are different",
updateFn: func() { updateFn: func() {
oldSvc = defaultExternalService() oldSvc = defaultExternalService()
@ -1362,8 +1300,7 @@ func TestNeedsUpdate(t *testing.T) {
newSvc.Spec.ExternalIPs = []string{"new.IP.1", "new.IP.2"} newSvc.Spec.ExternalIPs = []string{"new.IP.1", "new.IP.2"}
}, },
expectedNeedsUpdate: true, expectedNeedsUpdate: true,
}, }, {
{
testName: "If external ips are different", testName: "If external ips are different",
updateFn: func() { updateFn: func() {
oldSvc = defaultExternalService() oldSvc = defaultExternalService()
@ -1372,8 +1309,7 @@ func TestNeedsUpdate(t *testing.T) {
newSvc.Spec.ExternalIPs = []string{"new.IP.1", "new.IP.2"} newSvc.Spec.ExternalIPs = []string{"new.IP.1", "new.IP.2"}
}, },
expectedNeedsUpdate: true, expectedNeedsUpdate: true,
}, }, {
{
testName: "If UID is different", testName: "If UID is different",
updateFn: func() { updateFn: func() {
oldSvc = defaultExternalService() oldSvc = defaultExternalService()
@ -1382,8 +1318,7 @@ func TestNeedsUpdate(t *testing.T) {
newSvc.UID = types.UID("UID new") newSvc.UID = types.UID("UID new")
}, },
expectedNeedsUpdate: true, expectedNeedsUpdate: true,
}, }, {
{
testName: "If ExternalTrafficPolicy is different", testName: "If ExternalTrafficPolicy is different",
updateFn: func() { updateFn: func() {
oldSvc = defaultExternalService() oldSvc = defaultExternalService()
@ -1391,8 +1326,7 @@ func TestNeedsUpdate(t *testing.T) {
newSvc.Spec.ExternalTrafficPolicy = v1.ServiceExternalTrafficPolicyLocal newSvc.Spec.ExternalTrafficPolicy = v1.ServiceExternalTrafficPolicyLocal
}, },
expectedNeedsUpdate: true, expectedNeedsUpdate: true,
}, }, {
{
testName: "If HealthCheckNodePort is different", testName: "If HealthCheckNodePort is different",
updateFn: func() { updateFn: func() {
oldSvc = defaultExternalService() oldSvc = defaultExternalService()
@ -1400,8 +1334,7 @@ func TestNeedsUpdate(t *testing.T) {
newSvc.Spec.HealthCheckNodePort = 30123 newSvc.Spec.HealthCheckNodePort = 30123
}, },
expectedNeedsUpdate: true, expectedNeedsUpdate: true,
}, }, {
{
testName: "If TargetGroup is different 1", testName: "If TargetGroup is different 1",
updateFn: func() { updateFn: func() {
oldSvc = newService("tcp-service", v1.ServiceTypeLoadBalancer, tweakAddPorts(v1.ProtocolTCP, 20)) oldSvc = newService("tcp-service", v1.ServiceTypeLoadBalancer, tweakAddPorts(v1.ProtocolTCP, 20))
@ -1409,8 +1342,7 @@ func TestNeedsUpdate(t *testing.T) {
newSvc.Spec.Ports[0].TargetPort = intstr.Parse("21") newSvc.Spec.Ports[0].TargetPort = intstr.Parse("21")
}, },
expectedNeedsUpdate: true, expectedNeedsUpdate: true,
}, }, {
{
testName: "If TargetGroup is different 2", testName: "If TargetGroup is different 2",
updateFn: func() { updateFn: func() {
oldSvc = newService("tcp-service", v1.ServiceTypeLoadBalancer, tweakAddPorts(v1.ProtocolTCP, 22)) oldSvc = newService("tcp-service", v1.ServiceTypeLoadBalancer, tweakAddPorts(v1.ProtocolTCP, 22))
@ -1418,38 +1350,14 @@ func TestNeedsUpdate(t *testing.T) {
newSvc.Spec.Ports[0].TargetPort = intstr.Parse("dns") newSvc.Spec.Ports[0].TargetPort = intstr.Parse("dns")
}, },
expectedNeedsUpdate: true, expectedNeedsUpdate: true,
}, }, {
{
testName: "If appProtocol is the same", testName: "If appProtocol is the same",
updateFn: func() { updateFn: func() {
oldSvc = newService("tcp-service", v1.ServiceTypeLoadBalancer, tweakAddPorts(v1.ProtocolTCP, 22)) oldSvc = newService("tcp-service", v1.ServiceTypeLoadBalancer, tweakAddPorts(v1.ProtocolTCP, 22))
newSvc = oldSvc.DeepCopy() newSvc = oldSvc.DeepCopy()
}, },
expectedNeedsUpdate: false, expectedNeedsUpdate: false,
}, }, {
{
testName: "If appProtocol is set when previously unset",
updateFn: func() {
oldSvc = newService("tcp-service", v1.ServiceTypeLoadBalancer, tweakAddPorts(v1.ProtocolTCP, 22))
newSvc = oldSvc.DeepCopy()
protocol := "http"
newSvc.Spec.Ports[0].AppProtocol = &protocol
},
expectedNeedsUpdate: true,
},
{
testName: "If appProtocol is set to a different value",
updateFn: func() {
protocol := "http"
oldSvc = newService("tcp-service", v1.ServiceTypeLoadBalancer, tweakAddPorts(v1.ProtocolTCP, 22))
oldSvc.Spec.Ports[0].AppProtocol = &protocol
newSvc = oldSvc.DeepCopy()
newProtocol := "tcp"
newSvc.Spec.Ports[0].AppProtocol = &newProtocol
},
expectedNeedsUpdate: true,
},
{
testName: "If service IPFamilies from single stack to dual stack", testName: "If service IPFamilies from single stack to dual stack",
updateFn: func() { updateFn: func() {
protocol := "http" protocol := "http"
@ -1473,8 +1381,7 @@ func TestNeedsUpdate(t *testing.T) {
newSvc.Spec.IPFamilies = []v1.IPFamily{v1.IPv4Protocol, v1.IPv6Protocol} newSvc.Spec.IPFamilies = []v1.IPFamily{v1.IPv4Protocol, v1.IPv6Protocol}
}, },
expectedNeedsUpdate: true, expectedNeedsUpdate: true,
}, }, {
{
testName: "If service IPFamilies from dual stack to single stack", testName: "If service IPFamilies from dual stack to single stack",
updateFn: func() { updateFn: func() {
protocol := "http" protocol := "http"
@ -1498,8 +1405,7 @@ func TestNeedsUpdate(t *testing.T) {
newSvc.Spec.IPFamilies = []v1.IPFamily{v1.IPv4Protocol} newSvc.Spec.IPFamilies = []v1.IPFamily{v1.IPv4Protocol}
}, },
expectedNeedsUpdate: true, expectedNeedsUpdate: true,
}, }, {
{
testName: "If service IPFamilies not change", testName: "If service IPFamilies not change",
updateFn: func() { updateFn: func() {
protocol := "http" protocol := "http"
@ -1522,8 +1428,27 @@ func TestNeedsUpdate(t *testing.T) {
newSvc = oldSvc.DeepCopy() newSvc = oldSvc.DeepCopy()
}, },
expectedNeedsUpdate: false, expectedNeedsUpdate: false,
}, {
testName: "If appProtocol is set when previously unset",
updateFn: func() {
oldSvc = newService("tcp-service", v1.ServiceTypeLoadBalancer, tweakAddPorts(v1.ProtocolTCP, 22))
newSvc = oldSvc.DeepCopy()
protocol := "http"
newSvc.Spec.Ports[0].AppProtocol = &protocol
}, },
} expectedNeedsUpdate: true,
}, {
testName: "If appProtocol is set to a different value",
updateFn: func() {
protocol := "http"
oldSvc = newService("tcp-service", v1.ServiceTypeLoadBalancer, tweakAddPorts(v1.ProtocolTCP, 22))
oldSvc.Spec.Ports[0].AppProtocol = &protocol
newSvc = oldSvc.DeepCopy()
newProtocol := "tcp"
newSvc.Spec.Ports[0].AppProtocol = &newProtocol
},
expectedNeedsUpdate: true,
}}
controller, _, _ := newController() controller, _, _ := newController()
for _, tc := range testCases { for _, tc := range testCases {
@ -1548,8 +1473,7 @@ func TestServiceCache(t *testing.T) {
testName string testName string
setCacheFn func() setCacheFn func()
checkCacheFn func() error checkCacheFn func() error
}{ }{{
{
testName: "Add", testName: "Add",
setCacheFn: func() { setCacheFn: func() {
cS := sc.getOrCreate("addTest") cS := sc.getOrCreate("addTest")
@ -1562,8 +1486,7 @@ func TestServiceCache(t *testing.T) {
} }
return nil return nil
}, },
}, }, {
{
testName: "Del", testName: "Del",
setCacheFn: func() { setCacheFn: func() {
sc.delete("addTest") sc.delete("addTest")
@ -1576,8 +1499,7 @@ func TestServiceCache(t *testing.T) {
} }
return nil return nil
}, },
}, }, {
{
testName: "Set and Get", testName: "Set and Get",
setCacheFn: func() { setCacheFn: func() {
sc.set("addTest", &cachedService{state: defaultExternalService()}) sc.set("addTest", &cachedService{state: defaultExternalService()})
@ -1593,8 +1515,7 @@ func TestServiceCache(t *testing.T) {
} }
return nil return nil
}, },
}, }, {
{
testName: "ListKeys", testName: "ListKeys",
setCacheFn: func() { setCacheFn: func() {
//Add one more entry here //Add one more entry here
@ -1608,8 +1529,7 @@ func TestServiceCache(t *testing.T) {
} }
return nil return nil
}, },
}, }, {
{
testName: "GetbyKeys", testName: "GetbyKeys",
setCacheFn: nil, //Nothing to set setCacheFn: nil, //Nothing to set
checkCacheFn: func() error { checkCacheFn: func() error {
@ -1620,8 +1540,7 @@ func TestServiceCache(t *testing.T) {
} }
return nil return nil
}, },
}, }, {
{
testName: "allServices", testName: "allServices",
setCacheFn: nil, //Nothing to set setCacheFn: nil, //Nothing to set
checkCacheFn: func() error { checkCacheFn: func() error {
@ -1632,8 +1551,7 @@ func TestServiceCache(t *testing.T) {
} }
return nil return nil
}, },
}, }}
}
for _, tc := range testCases { for _, tc := range testCases {
if tc.setCacheFn != nil { if tc.setCacheFn != nil {
@ -1652,8 +1570,7 @@ func TestAddFinalizer(t *testing.T) {
desc string desc string
svc *v1.Service svc *v1.Service
expectPatch bool expectPatch bool
}{ }{{
{
desc: "no-op add finalizer", desc: "no-op add finalizer",
svc: &v1.Service{ svc: &v1.Service{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
@ -1662,8 +1579,7 @@ func TestAddFinalizer(t *testing.T) {
}, },
}, },
expectPatch: false, expectPatch: false,
}, }, {
{
desc: "add finalizer", desc: "add finalizer",
svc: &v1.Service{ svc: &v1.Service{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
@ -1671,8 +1587,7 @@ func TestAddFinalizer(t *testing.T) {
}, },
}, },
expectPatch: true, expectPatch: true,
}, }}
}
for _, tc := range testCases { for _, tc := range testCases {
t.Run(tc.desc, func(t *testing.T) { t.Run(tc.desc, func(t *testing.T) {
@ -1708,8 +1623,7 @@ func TestRemoveFinalizer(t *testing.T) {
desc string desc string
svc *v1.Service svc *v1.Service
expectPatch bool expectPatch bool
}{ }{{
{
desc: "no-op remove finalizer", desc: "no-op remove finalizer",
svc: &v1.Service{ svc: &v1.Service{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
@ -1717,8 +1631,7 @@ func TestRemoveFinalizer(t *testing.T) {
}, },
}, },
expectPatch: false, expectPatch: false,
}, }, {
{
desc: "remove finalizer", desc: "remove finalizer",
svc: &v1.Service{ svc: &v1.Service{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
@ -1727,8 +1640,7 @@ func TestRemoveFinalizer(t *testing.T) {
}, },
}, },
expectPatch: true, expectPatch: true,
}, }}
}
for _, tc := range testCases { for _, tc := range testCases {
t.Run(tc.desc, func(t *testing.T) { t.Run(tc.desc, func(t *testing.T) {
@ -1765,8 +1677,7 @@ func TestPatchStatus(t *testing.T) {
svc *v1.Service svc *v1.Service
newStatus *v1.LoadBalancerStatus newStatus *v1.LoadBalancerStatus
expectPatch bool expectPatch bool
}{ }{{
{
desc: "no-op add status", desc: "no-op add status",
svc: &v1.Service{ svc: &v1.Service{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
@ -1786,8 +1697,7 @@ func TestPatchStatus(t *testing.T) {
}, },
}, },
expectPatch: false, expectPatch: false,
}, }, {
{
desc: "add status", desc: "add status",
svc: &v1.Service{ svc: &v1.Service{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
@ -1801,8 +1711,7 @@ func TestPatchStatus(t *testing.T) {
}, },
}, },
expectPatch: true, expectPatch: true,
}, }, {
{
desc: "no-op clear status", desc: "no-op clear status",
svc: &v1.Service{ svc: &v1.Service{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
@ -1812,8 +1721,7 @@ func TestPatchStatus(t *testing.T) {
}, },
newStatus: &v1.LoadBalancerStatus{}, newStatus: &v1.LoadBalancerStatus{},
expectPatch: false, expectPatch: false,
}, }, {
{
desc: "clear status", desc: "clear status",
svc: &v1.Service{ svc: &v1.Service{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
@ -1829,8 +1737,7 @@ func TestPatchStatus(t *testing.T) {
}, },
newStatus: &v1.LoadBalancerStatus{}, newStatus: &v1.LoadBalancerStatus{},
expectPatch: true, expectPatch: true,
}, }}
}
for _, tc := range testCases { for _, tc := range testCases {
t.Run(tc.desc, func(t *testing.T) { t.Run(tc.desc, func(t *testing.T) {
@ -1911,29 +1818,25 @@ func TestListWithPredicate(t *testing.T) {
name string name string
predicate NodeConditionPredicate predicate NodeConditionPredicate
expect []*v1.Node expect []*v1.Node
}{ }{{
{
name: "ListWithPredicate filter Running node", name: "ListWithPredicate filter Running node",
predicate: func(node *v1.Node) bool { predicate: func(node *v1.Node) bool {
return node.Status.Phase == v1.NodeRunning return node.Status.Phase == v1.NodeRunning
}, },
expect: []*v1.Node{nodes[1], nodes[3]}, expect: []*v1.Node{nodes[1], nodes[3]},
}, }, {
{
name: "ListWithPredicate filter Pending node", name: "ListWithPredicate filter Pending node",
predicate: func(node *v1.Node) bool { predicate: func(node *v1.Node) bool {
return node.Status.Phase == v1.NodePending return node.Status.Phase == v1.NodePending
}, },
expect: []*v1.Node{nodes[0], nodes[2], nodes[4]}, expect: []*v1.Node{nodes[0], nodes[2], nodes[4]},
}, }, {
{
name: "ListWithPredicate filter Terminated node", name: "ListWithPredicate filter Terminated node",
predicate: func(node *v1.Node) bool { predicate: func(node *v1.Node) bool {
return node.Status.Phase == v1.NodeTerminated return node.Status.Phase == v1.NodeTerminated
}, },
expect: nil, expect: nil,
}, }}
}
for _, test := range tests { for _, test := range tests {
t.Run(test.name, func(t *testing.T) { t.Run(test.name, func(t *testing.T) {
get, err := listWithPredicates(fakeInformerFactory.Core().V1().Nodes().Lister(), test.predicate) get, err := listWithPredicates(fakeInformerFactory.Core().V1().Nodes().Lister(), test.predicate)