Skip to content

Commit 6d535f1

Browse files
committed
Do not skip externalLB update if some nodes are not found.
Log a warning instead and continue with the update. This is useful in cases where the number of nodes is changing due to autoscaling or updgrades. It is possible that the nodes picked by service controller don't all exist when gce layer lists them. Update should still succeed with the nodes in the input that are valid. This will still return an error if 0 nodes were found, when a non-zero input was passed in. same
1 parent 6d01c5a commit 6d535f1

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

staging/src/k8s.io/legacy-cloud-providers/gce/gce_instances.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,11 @@ func (g *Cloud) getInstancesByNames(names []string) ([]*gceInstance, error) {
561561
return nil, err
562562
}
563563
if len(foundInstances) != len(names) {
564-
return nil, cloudprovider.InstanceNotFound
564+
if len(foundInstances) == 0 {
565+
// return error so the TargetPool nodecount does not drop to 0 unexpectedly.
566+
return nil, cloudprovider.InstanceNotFound
567+
}
568+
klog.Warningf("getFoundInstanceByNames - input instances %d, found %d. Continuing LoadBalancer Update", len(names), len(foundInstances))
565569
}
566570
return foundInstances, nil
567571
}

staging/src/k8s.io/legacy-cloud-providers/gce/gce_loadbalancer_external_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,24 @@ func TestUpdateExternalLoadBalancer(t *testing.T) {
372372
[]string{fmt.Sprintf("/zones/%s/instances/%s", vals.ZoneName, nodeName)},
373373
pool.Instances,
374374
)
375+
376+
anotherNewNodeName := "test-node-3"
377+
newNodes, err = createAndInsertNodes(gce, []string{nodeName, newNodeName, anotherNewNodeName}, vals.ZoneName)
378+
assert.NoError(t, err)
379+
380+
// delete one of the existing nodes, but include it in the list
381+
err = gce.DeleteInstance(gce.ProjectID(), vals.ZoneName, nodeName)
382+
require.NoError(t, err)
383+
384+
// The update should ignore the reference to non-existent node "test-node-1", but update target pool with rest of the valid nodes.
385+
err = gce.updateExternalLoadBalancer(vals.ClusterName, svc, newNodes)
386+
assert.NoError(t, err)
387+
388+
pool, err = gce.GetTargetPool(lbName, gce.region)
389+
require.NoError(t, err)
390+
391+
namePrefix := fmt.Sprintf("/zones/%s/instances/", vals.ZoneName)
392+
assert.ElementsMatch(t, pool.Instances, []string{namePrefix + newNodeName, namePrefix + anotherNewNodeName})
375393
}
376394

377395
func TestEnsureExternalLoadBalancerDeleted(t *testing.T) {

0 commit comments

Comments
 (0)