Skip to content

Commit 6d3ccd8

Browse files
authored
Merge pull request kubernetes#95559 from prameshj/elb-update
Do not skip externalLB update if some nodes are not found.
2 parents 3b868e1 + 6d535f1 commit 6d3ccd8

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)