Skip to content

Commit a5df7a3

Browse files
committed
Fix ILB deletion by checking for finalizer if annotation is removed
1 parent 90efdf5 commit a5df7a3

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

providers/gce/gce_loadbalancer.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,10 @@ func (g *Cloud) EnsureLoadBalancerDeleted(ctx context.Context, clusterName strin
279279
}
280280

281281
func getSvcScheme(svc *v1.Service) cloud.LbScheme {
282-
if t := GetLoadBalancerAnnotationType(svc); t == LBTypeInternal {
282+
if LBTypeInternal == GetLoadBalancerAnnotationType(svc) {
283+
return cloud.SchemeInternal
284+
}
285+
if hasFinalizer(svc, ILBFinalizerV1) || hasFinalizer(svc, ILBFinalizerV2) {
283286
return cloud.SchemeInternal
284287
}
285288
return cloud.SchemeExternal

providers/gce/gce_loadbalancer_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,33 @@ func TestEnsureLoadBalancerDeletedDeletesInternalLb(t *testing.T) {
183183
assertInternalLbResourcesDeleted(t, gce, apiService, vals, true)
184184
}
185185

186+
func TestEnsureLoadBalancerDeletedChecksInternalLbFinalizer(t *testing.T) {
187+
t.Parallel()
188+
189+
vals := DefaultTestClusterValues()
190+
gce, err := fakeGCECloud(vals)
191+
require.NoError(t, err)
192+
193+
nodeNames := []string{"test-node-1"}
194+
_, err = createAndInsertNodes(gce, nodeNames, vals.ZoneName)
195+
require.NoError(t, err)
196+
197+
apiService := fakeLoadbalancerService(string(LBTypeInternal))
198+
apiService, err = gce.client.CoreV1().Services(apiService.Namespace).Create(context.TODO(), apiService, metav1.CreateOptions{})
199+
require.NoError(t, err)
200+
createInternalLoadBalancer(gce, apiService, nil, nodeNames, vals.ClusterName, vals.ClusterID, vals.ZoneName)
201+
202+
// Read service from apiserver so it has finalizer
203+
apiService, err = gce.client.CoreV1().Services(apiService.Namespace).Get(context.TODO(), apiService.Name, metav1.GetOptions{})
204+
if err != nil {
205+
t.Fatalf("Unexpected error: %v", err)
206+
}
207+
delete(apiService.Annotations, ServiceAnnotationLoadBalancerType)
208+
err = gce.EnsureLoadBalancerDeleted(context.Background(), vals.ClusterName, apiService)
209+
assert.NoError(t, err)
210+
assertInternalLbResourcesDeleted(t, gce, apiService, vals, true)
211+
}
212+
186213
func TestProjectsBasePath(t *testing.T) {
187214
t.Parallel()
188215
vals := DefaultTestClusterValues()

0 commit comments

Comments
 (0)