@@ -28,17 +28,20 @@ import (
2828type instanceGroupManagerClient struct {
2929 // instanceGroupManagers are instanceGroupManagers keyed by project, zone, and name.
3030 instanceGroupManagers map [string ]map [string ]map [string ]* compute.InstanceGroupManager
31- // instances are instances keyed by project, zone, and name.
32- instances map [string ]map [string ]map [string ]* compute.ManagedInstance
31+ // managedInstances are managedInstances keyed by project, zone, and name.
32+ managedInstances map [string ]map [string ]map [string ]* compute.ManagedInstance
33+ // instanceClient is the client for instances.
34+ instanceClient gce.InstanceClient
3335 sync.Mutex
3436}
3537
3638var _ gce.InstanceGroupManagerClient = & instanceGroupManagerClient {}
3739
38- func newInstanceGroupManagerClient () * instanceGroupManagerClient {
40+ func newInstanceGroupManagerClient (instanceClient gce. InstanceClient ) * instanceGroupManagerClient {
3941 return & instanceGroupManagerClient {
4042 instanceGroupManagers : map [string ]map [string ]map [string ]* compute.InstanceGroupManager {},
41- instances : map [string ]map [string ]map [string ]* compute.ManagedInstance {},
43+ managedInstances : map [string ]map [string ]map [string ]* compute.ManagedInstance {},
44+ instanceClient : instanceClient ,
4245 }
4346}
4447
@@ -72,22 +75,25 @@ func (c *instanceGroupManagerClient) Insert(project, zone string, igm *compute.I
7275 igm .SelfLink = fmt .Sprintf ("https://www.googleapis.com/compute/v1/projects/%s/zones/%s/instanceGroupManagers/%s" , project , zone , igm .Name )
7376 igms [igm .Name ] = igm
7477
75- newInstance := & compute.ManagedInstance {
76- Instance : fmt . Sprintf ( "https://www.googleapis.com/compute/v1/projects/%s/zones/%s/instances/%s" , project , zone , igm .Name ) ,
78+ newInstance := & compute.Instance {
79+ Name : igm .Name ,
7780 }
7881
79- instanceZones , ok := c .instances [project ]
82+ c .instanceClient .Insert (project , zone , newInstance )
83+
84+ instanceZones , ok := c .managedInstances [project ]
8085 if ! ok {
8186 instanceZones = map [string ]map [string ]* compute.ManagedInstance {}
82- c .instances [project ] = instanceZones
87+ c .managedInstances [project ] = instanceZones
8388 }
84- instanceIgms , ok : = instanceZones [zone ]
89+ _ , ok = instanceZones [zone ]
8590 if ! ok {
86- instanceIgms = map [string ]* compute.ManagedInstance {}
87- instanceZones [zone ] = instanceIgms
91+ instanceZones [zone ] = map [string ]* compute.ManagedInstance {}
8892 }
8993
90- c.instances [project ][zone ][igm .Name ] = newInstance
94+ c.managedInstances [project ][zone ][igm .Name ] = & compute.ManagedInstance {
95+ Instance : fmt .Sprintf ("https://www.googleapis.com/compute/v1/projects/%s/zones/%s/instances/%s" , project , zone , igm .Name ),
96+ }
9197
9298 return doneOperation (), nil
9399}
@@ -150,7 +156,7 @@ func (c *instanceGroupManagerClient) ListManagedInstances(ctx context.Context, p
150156 c .Lock ()
151157 defer c .Unlock ()
152158
153- zones , ok := c .instances [project ]
159+ zones , ok := c .managedInstances [project ]
154160 if ! ok {
155161 return nil , nil
156162 }
0 commit comments