Updating instances interface to accept all named ports at once
This commit is contained in:
parent
abc8b9de51
commit
3dcdc2600e
11 changed files with 135 additions and 93 deletions
|
|
@ -134,7 +134,7 @@ func (c *ClusterManager) Checkpoint(lbs []*loadbalancers.L7RuntimeInfo, nodeName
|
|||
if err != nil {
|
||||
return igs, err
|
||||
}
|
||||
if err := c.backendPool.Sync(backendServicePorts, igs); err != nil {
|
||||
if err := c.backendPool.Ensure(backendServicePorts, igs); err != nil {
|
||||
return igs, err
|
||||
}
|
||||
if err := c.instancePool.Sync(nodeNames); err != nil {
|
||||
|
|
@ -167,20 +167,12 @@ func (c *ClusterManager) Checkpoint(lbs []*loadbalancers.L7RuntimeInfo, nodeName
|
|||
}
|
||||
|
||||
func (c *ClusterManager) EnsureInstanceGroupsAndPorts(servicePorts []backends.ServicePort) ([]*compute.InstanceGroup, error) {
|
||||
var igs []*compute.InstanceGroup
|
||||
var err error
|
||||
ports := []int64{}
|
||||
for _, p := range servicePorts {
|
||||
// EnsureInstanceGroupsAndPorts always returns all the instance groups, so we can return
|
||||
// the output of any call, no need to append the return from all calls.
|
||||
// TODO: Ideally, we want to call CreateInstaceGroups only the first time and
|
||||
// then call AddNamedPort multiple times. Need to update the interface to
|
||||
// achieve this.
|
||||
igs, _, err = instances.EnsureInstanceGroupsAndPorts(c.instancePool, c.ClusterNamer, p.Port)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ports = append(ports, p.Port)
|
||||
}
|
||||
return igs, nil
|
||||
igs, _, err := instances.EnsureInstanceGroupsAndPorts(c.instancePool, c.ClusterNamer, ports)
|
||||
return igs, err
|
||||
}
|
||||
|
||||
// GC garbage collects unused resources.
|
||||
|
|
|
|||
|
|
@ -71,17 +71,12 @@ func TestInstancesAddedToZones(t *testing.T) {
|
|||
|
||||
// Create 2 igs, one per zone.
|
||||
testIG := "test-ig"
|
||||
testPort := int64(3001)
|
||||
lbc.CloudClusterManager.instancePool.AddInstanceGroup(testIG, testPort)
|
||||
lbc.CloudClusterManager.instancePool.AddInstanceGroup(testIG, []int64{int64(3001)})
|
||||
|
||||
// node pool syncs kube-nodes, this will add them to both igs.
|
||||
lbc.CloudClusterManager.instancePool.Sync([]string{"n1", "n2", "n3"})
|
||||
gotZonesToNode := cm.fakeIGs.GetInstancesByZone()
|
||||
|
||||
if cm.fakeIGs.Ports[0] != testPort {
|
||||
t.Errorf("Expected the same node port on all igs, got ports %+v", cm.fakeIGs.Ports)
|
||||
}
|
||||
|
||||
for z, nodeNames := range zoneToNode {
|
||||
if ig, err := cm.fakeIGs.GetInstanceGroup(testIG, z); err != nil {
|
||||
t.Errorf("Failed to find ig %v in zone %v, found %+v: %v", testIG, z, ig, err)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue