Skip to content

Commit 3f960e6

Browse files
authored
Return nil when VirtualMachineService is not found (#1551)
Currently when virtualmachineservice is not found, an err is returned and cloud provider reports err and won't able to delete LB Service anymore. Actually CPI should return nil in this case.
1 parent c7d6a2d commit 3f960e6

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

pkg/cloudprovider/vsphereparavirtual/loadbalancer.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,11 @@ func (l *loadBalancer) GetLoadBalancer(ctx context.Context, clusterName string,
6868
return nil, false, err
6969
}
7070

71+
// When err is nil and vmService is nil, it indicates VirtualMachineService not found, but it's not an error.
72+
// Return nil so that cloud provider could move on and delete the LB service.
7173
if vmService == nil {
72-
klog.Errorf("failed to get load balancer for %s: VirtualMachineService not found", namespacedName(service))
73-
return nil, false, errors.Errorf("VirtualMachineService not found")
74+
klog.V(1).Infof("VirtualMachineService not found %s", namespacedName(service))
75+
return nil, false, nil
7476
}
7577

7678
return toStatus(vmService), true, nil

pkg/cloudprovider/vsphereparavirtual/loadbalancer_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func TestGetLoadBalancer_VMServiceNotFound(t *testing.T) {
104104

105105
_, exists, err := lb.GetLoadBalancer(context.Background(), testClustername, testK8sService)
106106
assert.Equal(t, exists, false)
107-
assert.Error(t, err)
107+
assert.NoError(t, err)
108108
}
109109

110110
func TestGetLoadBalancer_VMServiceCreated(t *testing.T) {

0 commit comments

Comments
 (0)