diff --git a/cluster-autoscaler/cloudprovider/gce/cache.go b/cluster-autoscaler/cloudprovider/gce/cache.go index 716aaef37afa..1b393790ebd0 100644 --- a/cluster-autoscaler/cloudprovider/gce/cache.go +++ b/cluster-autoscaler/cloudprovider/gce/cache.go @@ -28,12 +28,6 @@ import ( "k8s.io/klog" ) -// MigInformation is a wrapper for Mig. -type MigInformation struct { - Config Mig - Basename string -} - // MachineTypeKey is used to identify MachineType. type MachineTypeKey struct { Zone string @@ -61,18 +55,16 @@ type MachineTypeKey struct { // - instanceRefToMigRef (2) is NOT updated automatically when migs field (1) is updated. Calling // RegenerateInstancesCache is required to sync it with registered migs. type GceCache struct { + cacheMutex sync.Mutex + // Cache content. - migs map[GceRef]*MigInformation + migs map[GceRef]Mig instanceRefToMigRef map[GceRef]GceRef resourceLimiter *cloudprovider.ResourceLimiter machinesCache map[MachineTypeKey]*gce.MachineType migTargetSizeCache map[GceRef]int64 - // Locks. Rules of locking: - // - migsMutex protects only migs. - // - cacheMutex protects instanceRefToMigRef, resourceLimiter, machinesCache and migTargetSizeCache. - // - if both locks are needed, cacheMutex must be obtained before migsMutex. - cacheMutex sync.Mutex - migsMutex sync.Mutex + migBaseNameCache map[GceRef]string + // Service used to refresh cache. GceService AutoscalingGceClient } @@ -80,11 +72,12 @@ type GceCache struct { // NewGceCache creates empty GceCache. func NewGceCache(gceService AutoscalingGceClient) GceCache { return GceCache{ - migs: map[GceRef]*MigInformation{}, + migs: map[GceRef]Mig{}, instanceRefToMigRef: map[GceRef]GceRef{}, machinesCache: map[MachineTypeKey]*gce.MachineType{}, - GceService: gceService, migTargetSizeCache: map[GceRef]int64{}, + migBaseNameCache: map[GceRef]string{}, + GceService: gceService, } } @@ -92,13 +85,13 @@ func NewGceCache(gceService AutoscalingGceClient) GceCache { // RegisterMig returns true if the node group wasn't in cache before, or its config was updated. func (gc *GceCache) RegisterMig(newMig Mig) bool { - gc.migsMutex.Lock() - defer gc.migsMutex.Unlock() + gc.cacheMutex.Lock() + defer gc.cacheMutex.Unlock() - oldMigInformation, found := gc.migs[newMig.GceRef()] + oldMig, found := gc.migs[newMig.GceRef()] if found { - if !reflect.DeepEqual(oldMigInformation.Config, newMig) { - gc.migs[newMig.GceRef()].Config = newMig + if !reflect.DeepEqual(oldMig, newMig) { + gc.migs[newMig.GceRef()] = newMig klog.V(4).Infof("Updated Mig %s", newMig.GceRef().String()) return true } @@ -106,11 +99,7 @@ func (gc *GceCache) RegisterMig(newMig Mig) bool { } klog.V(1).Infof("Registering %s", newMig.GceRef().String()) - // TODO(aleksandra-malinowska): fetch and set MIG basename here. - newMigInformation := &MigInformation{ - Config: newMig, - } - gc.migs[newMig.GceRef()] = newMigInformation + gc.migs[newMig.GceRef()] = newMig return true } @@ -118,8 +107,6 @@ func (gc *GceCache) RegisterMig(newMig Mig) bool { func (gc *GceCache) UnregisterMig(toBeRemoved Mig) bool { gc.cacheMutex.Lock() defer gc.cacheMutex.Unlock() - gc.migsMutex.Lock() - defer gc.migsMutex.Unlock() _, found := gc.migs[toBeRemoved.GceRef()] if found { @@ -132,25 +119,19 @@ func (gc *GceCache) UnregisterMig(toBeRemoved Mig) bool { } // GetMigs returns a copy of migs list. -func (gc *GceCache) GetMigs() []*MigInformation { - gc.migsMutex.Lock() - defer gc.migsMutex.Unlock() +func (gc *GceCache) GetMigs() []Mig { + gc.cacheMutex.Lock() + defer gc.cacheMutex.Unlock() - migs := make([]*MigInformation, 0, len(gc.migs)) + migs := make([]Mig, 0, len(gc.migs)) for _, mig := range gc.migs { - migs = append(migs, &MigInformation{ - Basename: mig.Basename, - Config: mig.Config, - }) + migs = append(migs, mig) } return migs } // GetMigs returns a copy of migs list. func (gc *GceCache) getMigRefs() []GceRef { - gc.migsMutex.Lock() - defer gc.migsMutex.Unlock() - migRefs := make([]GceRef, 0, len(gc.migs)) for migRef := range gc.migs { migRefs = append(migRefs, migRef) @@ -158,17 +139,6 @@ func (gc *GceCache) getMigRefs() []GceRef { return migRefs } -func (gc *GceCache) updateMigBasename(migRef GceRef, basename string) { - gc.migsMutex.Lock() - defer gc.migsMutex.Unlock() - - mig, found := gc.migs[migRef] - if found { - mig.Basename = basename - } - // TODO: is found == false a possiblity? -} - // Methods locking on cacheMutex. // GetMigForInstance returns Mig to which the given instance belongs. @@ -180,18 +150,31 @@ func (gc *GceCache) GetMigForInstance(instanceRef GceRef) (Mig, error) { defer gc.cacheMutex.Unlock() if migRef, found := gc.instanceRefToMigRef[instanceRef]; found { - mig, found := gc.getMig(migRef) + mig, found := gc.getMigNoLock(migRef) if !found { return nil, fmt.Errorf("instance %+v belongs to unregistered mig %+v", instanceRef, migRef) } - return mig.Config, nil + return mig, nil } - for _, mig := range gc.GetMigs() { - if mig.Config.GceRef().Project == instanceRef.Project && - mig.Config.GceRef().Zone == instanceRef.Zone && - strings.HasPrefix(instanceRef.Name, mig.Basename) { - if err := gc.regenerateInstanceCacheForMigNoLock(mig.Config.GceRef()); err != nil { + for _, migRef := range gc.getMigRefs() { + + // get mig basename - refresh if not found + // todo[lukaszos] move this one as well as whole instance cache regeneration out of cache + migBasename, found := gc.migBaseNameCache[migRef] + var err error + if !found { + migBasename, err = gc.GceService.FetchMigBasename(migRef) + if err != nil { + return nil, err + } + gc.migBaseNameCache[migRef] = migBasename + } + + if migRef.Project == instanceRef.Project && + migRef.Zone == instanceRef.Zone && + strings.HasPrefix(instanceRef.Name, migBasename) { + if err := gc.regenerateInstanceCacheForMigNoLock(migRef); err != nil { return nil, fmt.Errorf("error while looking for MIG for instance %+v, error: %v", instanceRef, err) } @@ -199,11 +182,11 @@ func (gc *GceCache) GetMigForInstance(instanceRef GceRef) (Mig, error) { if !found { return nil, fmt.Errorf("instance %+v belongs to unknown mig", instanceRef) } - mig, found := gc.getMig(migRef) + mig, found := gc.getMigNoLock(migRef) if !found { return nil, fmt.Errorf("instance %+v belongs to unregistered mig %+v", instanceRef, migRef) } - return mig.Config, nil + return mig, nil } } // Instance doesn't belong to any configured mig. @@ -218,11 +201,9 @@ func (gc *GceCache) removeInstancesForMig(migRef GceRef) { } } -func (gc *GceCache) getMig(migRef GceRef) (MigInformation, bool) { - gc.migsMutex.Lock() - defer gc.migsMutex.Unlock() - mig, found := gc.migs[migRef] - return *mig, found +func (gc *GceCache) getMigNoLock(migRef GceRef) (mig Mig, found bool) { + mig, found = gc.migs[migRef] + return } // RegenerateInstanceCacheForMig triggers instances cache regeneration for single MIG under lock. @@ -238,12 +219,6 @@ func (gc *GceCache) regenerateInstanceCacheForMigNoLock(migRef GceRef) error { // cleanup old entries gc.removeInstancesForMig(migRef) - basename, err := gc.GceService.FetchMigBasename(migRef) - if err != nil { - return err - } - gc.updateMigBasename(migRef, basename) - instances, err := gc.GceService.FetchMigInstances(migRef) if err != nil { klog.V(4).Infof("Failed MIG info request for %s: %v", migRef.String(), err) @@ -310,24 +285,24 @@ func (gc *GceCache) SetMigTargetSize(ref GceRef, size int64) { gc.migTargetSizeCache[ref] = size } -// InvalidateTargetSizeCache clears the target size cache -func (gc *GceCache) InvalidateTargetSizeCache() { +// InvalidateMigTargetSize clears the target size cache +func (gc *GceCache) InvalidateMigTargetSize(ref GceRef) { gc.cacheMutex.Lock() defer gc.cacheMutex.Unlock() - klog.V(5).Infof("target size cache invalidated") - gc.migTargetSizeCache = map[GceRef]int64{} + if _, found := gc.migTargetSizeCache[ref]; found { + klog.V(5).Infof("target size cache invalidated for %s", ref) + delete(gc.migTargetSizeCache, ref) + } } -// InvalidateTargetSizeCacheForMig clears the target size cache -func (gc *GceCache) InvalidateTargetSizeCacheForMig(ref GceRef) { +// InvalidateAllMigTargetSizes clears the target size cache +func (gc *GceCache) InvalidateAllMigTargetSizes() { gc.cacheMutex.Lock() defer gc.cacheMutex.Unlock() - if _, found := gc.migTargetSizeCache[ref]; found { - klog.V(5).Infof("target size cache invalidated for %s", ref) - delete(gc.migTargetSizeCache, ref) - } + klog.V(5).Infof("target size cache invalidated") + gc.migTargetSizeCache = map[GceRef]int64{} } // GetMachineFromCache retrieves machine type from cache under lock. @@ -353,3 +328,32 @@ func (gc *GceCache) SetMachinesCache(machinesCache map[MachineTypeKey]*gce.Machi gc.machinesCache = machinesCache } + +// SetMigBasename sets basename for given mig in cache +func (gc *GceCache) SetMigBasename(migRef GceRef, basename string) { + gc.cacheMutex.Lock() + defer gc.cacheMutex.Unlock() + gc.migBaseNameCache[migRef] = basename +} + +// GetMigBasename get basename for given mig from cache. +func (gc *GceCache) GetMigBasename(migRef GceRef) (basename string, found bool) { + gc.cacheMutex.Lock() + defer gc.cacheMutex.Unlock() + basename, found = gc.migBaseNameCache[migRef] + return +} + +// InvalidateMigBasename invalidates basename entry for given mig. +func (gc *GceCache) InvalidateMigBasename(migRef GceRef) { + gc.cacheMutex.Lock() + defer gc.cacheMutex.Unlock() + delete(gc.migBaseNameCache, migRef) +} + +// InvalidateAllMigBasenames invalidates all basename entries. +func (gc *GceCache) InvalidateAllMigBasenames() { + gc.cacheMutex.Lock() + defer gc.cacheMutex.Unlock() + gc.migBaseNameCache = make(map[GceRef]string) +} diff --git a/cluster-autoscaler/cloudprovider/gce/gce_cloud_provider.go b/cluster-autoscaler/cloudprovider/gce/gce_cloud_provider.go index d4b6aba6918f..35c60d5e672c 100644 --- a/cluster-autoscaler/cloudprovider/gce/gce_cloud_provider.go +++ b/cluster-autoscaler/cloudprovider/gce/gce_cloud_provider.go @@ -87,7 +87,7 @@ func (gce *GceCloudProvider) NodeGroups() []cloudprovider.NodeGroup { migs := gce.gceManager.GetMigs() result := make([]cloudprovider.NodeGroup, 0, len(migs)) for _, mig := range migs { - result = append(result, mig.Config) + result = append(result, mig) } return result } diff --git a/cluster-autoscaler/cloudprovider/gce/gce_cloud_provider_test.go b/cluster-autoscaler/cloudprovider/gce/gce_cloud_provider_test.go index 6e6092f8a4d7..a68106a5a9c0 100644 --- a/cluster-autoscaler/cloudprovider/gce/gce_cloud_provider_test.go +++ b/cluster-autoscaler/cloudprovider/gce/gce_cloud_provider_test.go @@ -72,9 +72,9 @@ func (m *gceManagerMock) Cleanup() error { return args.Error(0) } -func (m *gceManagerMock) GetMigs() []*MigInformation { +func (m *gceManagerMock) GetMigs() []Mig { args := m.Called() - return args.Get(0).([]*MigInformation) + return args.Get(0).([]Mig) } func (m *gceManagerMock) GetResourceLimiter() (*cloudprovider.ResourceLimiter, error) { @@ -114,10 +114,10 @@ func TestNodeGroups(t *testing.T) { gce := &GceCloudProvider{ gceManager: gceManagerMock, } - mig := &MigInformation{Config: &gceMig{gceRef: GceRef{Name: "ng1"}}} - gceManagerMock.On("GetMigs").Return([]*MigInformation{mig}).Once() + mig := &gceMig{gceRef: GceRef{Name: "ng1"}} + gceManagerMock.On("GetMigs").Return([]Mig{mig}).Once() result := gce.NodeGroups() - assert.Equal(t, []cloudprovider.NodeGroup{mig.Config}, result) + assert.Equal(t, []cloudprovider.NodeGroup{mig}, result) mock.AssertExpectationsForObjects(t, gceManagerMock) } diff --git a/cluster-autoscaler/cloudprovider/gce/gce_manager.go b/cluster-autoscaler/cloudprovider/gce/gce_manager.go index 320b5d541f23..329ba4e266c6 100644 --- a/cluster-autoscaler/cloudprovider/gce/gce_manager.go +++ b/cluster-autoscaler/cloudprovider/gce/gce_manager.go @@ -64,7 +64,7 @@ type GceManager interface { Cleanup() error // GetMigs returns list of registered MIGs. - GetMigs() []*MigInformation + GetMigs() []Mig // GetMigNodes returns mig nodes. GetMigNodes(mig Mig) ([]cloudprovider.Instance, error) // GetMigForInstance returns MIG to which the given instance belongs. @@ -220,7 +220,7 @@ func (m *gceManagerImpl) GetMigSize(mig Mig) (int64, error) { // SetMigSize sets MIG size. func (m *gceManagerImpl) SetMigSize(mig Mig, size int64) error { klog.V(0).Infof("Setting mig size %s to %d", mig.Id(), size) - m.cache.InvalidateTargetSizeCacheForMig(mig.GceRef()) + m.cache.InvalidateMigTargetSize(mig.GceRef()) return m.GceService.ResizeMig(mig.GceRef(), size) } @@ -242,12 +242,12 @@ func (m *gceManagerImpl) DeleteInstances(instances []GceRef) error { return fmt.Errorf("cannot delete instances which don't belong to the same MIG.") } } - m.cache.InvalidateTargetSizeCacheForMig(commonMig.GceRef()) + m.cache.InvalidateMigTargetSize(commonMig.GceRef()) return m.GceService.DeleteInstances(commonMig.GceRef(), instances) } // GetMigs returns list of registered MIGs. -func (m *gceManagerImpl) GetMigs() []*MigInformation { +func (m *gceManagerImpl) GetMigs() []Mig { return m.cache.GetMigs() } @@ -263,7 +263,7 @@ func (m *gceManagerImpl) GetMigNodes(mig Mig) ([]cloudprovider.Instance, error) // Refresh triggers refresh of cached resources. func (m *gceManagerImpl) Refresh() error { - m.cache.InvalidateTargetSizeCache() + m.cache.InvalidateAllMigTargetSizes() if m.lastRefresh.Add(refreshInterval).After(time.Now()) { return nil } @@ -372,8 +372,8 @@ func (m *gceManagerImpl) fetchAutoMigs() error { } for _, mig := range m.GetMigs() { - if !exists[mig.Config.GceRef()] && !m.explicitlyConfigured[mig.Config.GceRef()] { - m.cache.UnregisterMig(mig.Config) + if !exists[mig.GceRef()] && !m.explicitlyConfigured[mig.GceRef()] { + m.cache.UnregisterMig(mig) changed = true } } diff --git a/cluster-autoscaler/cloudprovider/gce/gce_manager_test.go b/cluster-autoscaler/cloudprovider/gce/gce_manager_test.go index 84d5f5901cea..67c01004097f 100644 --- a/cluster-autoscaler/cloudprovider/gce/gce_manager_test.go +++ b/cluster-autoscaler/cloudprovider/gce/gce_manager_test.go @@ -57,7 +57,7 @@ const instanceGroupManagerResponseTemplate = `{ "zone": "https://www.googleapis.com/compute/v1/projects/project1/zones/%s", "instanceTemplate": "https://www.googleapis.com/compute/v1/projects/project1/global/instanceTemplates/%s", "instanceGroup": "https://www.googleapis.com/compute/v1/projects/project1/zones/%s/instanceGroups/%s", - "baseInstanceName": "gke-cluster-1-default-pool-f23aac-grp", + "baseInstanceName": "%s", "fingerprint": "kfdsuH", "currentActions": { "none": 3, @@ -241,7 +241,7 @@ func buildDefaultInstanceGroupManagerResponse(zone string) string { } func buildInstanceGroupManagerResponse(zone string, instanceGroup string) string { - return fmt.Sprintf(instanceGroupManagerResponseTemplate, instanceGroup, zone, instanceGroup, zone, instanceGroup, zone, instanceGroup) + return fmt.Sprintf(instanceGroupManagerResponseTemplate, instanceGroup, zone, instanceGroup, zone, instanceGroup, instanceGroup, zone, instanceGroup) } func buildFourRunningInstancesOnDefaultMigManagedInstancesResponse(zone string) string { @@ -269,7 +269,7 @@ func newTestGceManager(t *testing.T, testServerURL string, regional bool) *gceMa manager := &gceManagerImpl{ cache: GceCache{ - migs: make(map[GceRef]*MigInformation), + migs: make(map[GceRef]Mig), GceService: gceService, instanceRefToMigRef: make(map[GceRef]GceRef), machinesCache: map[MachineTypeKey]*gce.MachineType{ @@ -278,6 +278,7 @@ func newTestGceManager(t *testing.T, testServerURL string, regional bool) *gceMa {"us-central1-f", "n1-standard-1"}: {GuestCpus: 1, MemoryMb: 1}, }, migTargetSizeCache: map[GceRef]int64{}, + migBaseNameCache: map[GceRef]string{}, }, GceService: gceService, projectId: projectId, @@ -329,7 +330,7 @@ const deleteInstancesOperationResponse = ` "selfLink": "https://www.googleapis.com/compute/v1/projects/project1/zones/us-central1-a/operations/operation-1505802641136-55984ff86d980-a99e8c2b-0c8aaaaa" }` -func setupTestDefaultPool(manager *gceManagerImpl) { +func setupTestDefaultPool(manager *gceManagerImpl, setupBaseName bool) { mig := &gceMig{ gceRef: GceRef{ Name: defaultPoolMig, @@ -340,10 +341,13 @@ func setupTestDefaultPool(manager *gceManagerImpl) { minSize: 1, maxSize: 11, } - manager.cache.migs[mig.GceRef()] = &MigInformation{Config: mig} + manager.cache.migs[mig.GceRef()] = mig + if setupBaseName { + manager.cache.migBaseNameCache[mig.GceRef()] = defaultPoolMig + } } -func setupTestExtraPool(manager *gceManagerImpl) { +func setupTestExtraPool(manager *gceManagerImpl, setupBaseName bool) { mig := &gceMig{ gceRef: GceRef{ Name: extraPoolMig, @@ -354,7 +358,10 @@ func setupTestExtraPool(manager *gceManagerImpl) { minSize: 0, maxSize: 1000, } - manager.cache.migs[mig.GceRef()] = &MigInformation{Config: mig} + manager.cache.migs[mig.GceRef()] = mig + if setupBaseName { + manager.cache.migBaseNameCache[mig.GceRef()] = extraPoolMig + } } func TestDeleteInstances(t *testing.T) { @@ -362,12 +369,15 @@ func TestDeleteInstances(t *testing.T) { defer server.Close() g := newTestGceManager(t, server.URL, false) - setupTestDefaultPool(g) - setupTestExtraPool(g) + setupTestDefaultPool(g, false) + setupTestExtraPool(g, true) - // Test DeleteInstance function. + // Get basename for defaultPool server.On("handle", "/project1/zones/us-central1-b/instanceGroupManagers/gke-cluster-1-default-pool").Return(buildDefaultInstanceGroupManagerResponse(zoneB)).Once() + + // Regenerate instances for defaultPool server.On("handle", "/project1/zones/us-central1-b/instanceGroupManagers/gke-cluster-1-default-pool/listManagedInstances").Return(buildFourRunningInstancesOnDefaultMigManagedInstancesResponse(zoneB)).Once() + server.On("handle", "/project1/zones/us-central1-b/instanceGroupManagers/gke-cluster-1-default-pool/deleteInstances").Return(deleteInstancesResponse).Once() server.On("handle", "/project1/zones/us-central1-b/operations/operation-1505802641136-55984ff86d980-a99e8c2b-0c8aaaaa").Return(deleteInstancesOperationResponse).Once() @@ -388,7 +398,7 @@ func TestDeleteInstances(t *testing.T) { assert.NoError(t, err) mock.AssertExpectationsForObjects(t, server) - server.On("handle", "/project1/zones/us-central1-b/instanceGroupManagers/gke-cluster-1-extra-pool-323233232").Return(buildDefaultInstanceGroupManagerResponse(zoneB)).Once() + // Regenerate instances for extraPool (no basename call because it is already in cache) server.On("handle", "/project1/zones/us-central1-b/instanceGroupManagers/gke-cluster-1-extra-pool-323233232/listManagedInstances").Return(buildOneRunningInstanceOnExtraPoolMigManagedInstancesResponse(zoneB)).Once() // Fail on deleting instances from different MIGs. @@ -534,7 +544,8 @@ func TestGetMigForInstance(t *testing.T) { defer server.Close() g := newTestGceManager(t, server.URL, false) - setupTestDefaultPool(g) + setupTestDefaultPool(g, false) + g.cache.InvalidateAllMigBasenames() server.On("handle", "/project1/zones/us-central1-b/instanceGroupManagers/gke-cluster-1-default-pool").Return(buildDefaultInstanceGroupManagerResponse(zoneB)).Once() server.On("handle", "/project1/zones/us-central1-b/instanceGroupManagers/gke-cluster-1-default-pool/listManagedInstances").Return(buildFourRunningInstancesOnDefaultMigManagedInstancesResponse(zoneB)).Once() @@ -927,11 +938,10 @@ func TestFetchAutoMigsZonal(t *testing.T) { server.On("handle", "/project1/zones/"+zoneB+"/instanceGroupManagers/"+gceMigA).Return(buildInstanceGroupManagerResponse(zoneB, gceMigA)).Once() server.On("handle", "/project1/zones/"+zoneB+"/instanceGroupManagers/"+gceMigB).Return(buildInstanceGroupManagerResponse(zoneB, gceMigB)).Once() + // Regenerate instance cache server.On("handle", "/project1/global/instanceTemplates/"+gceMigA).Return(instanceTemplate).Once() server.On("handle", "/project1/global/instanceTemplates/"+gceMigB).Return(instanceTemplate).Once() - server.On("handle", "/project1/zones/"+zoneB+"/instanceGroupManagers/"+gceMigA).Return(buildInstanceGroupManagerResponse(zoneB, gceMigA)).Once() server.On("handle", "/project1/zones/"+zoneB+"/instanceGroupManagers/"+gceMigA+"/listManagedInstances").Return(buildFourRunningInstancesManagedInstancesResponse(zoneB, gceMigA)).Once() - server.On("handle", "/project1/zones/"+zoneB+"/instanceGroupManagers/"+gceMigB).Return(buildInstanceGroupManagerResponse(zoneB, gceMigB)).Once() server.On("handle", "/project1/zones/"+zoneB+"/instanceGroupManagers/"+gceMigB+"/listManagedInstances").Return(buildOneRunningInstanceManagedInstancesResponse(zoneB, gceMigB)).Once() regional := false @@ -960,7 +970,6 @@ func TestFetchAutoMigsUnregistersMissingMigs(t *testing.T) { server.On("handle", "/project1/global/instanceTemplates/"+gceMigA).Return(instanceTemplate).Once() // Regenerate cache for explicit instance group - server.On("handle", "/project1/zones/"+zoneB+"/instanceGroupManagers/"+gceMigA).Return(buildInstanceGroupManagerResponse(zoneB, gceMigA)).Twice() server.On("handle", "/project1/zones/"+zoneB+"/instanceGroupManagers/"+gceMigA+"/listManagedInstances").Return(buildFourRunningInstancesManagedInstancesResponse(zoneB, gceMigA)).Twice() // Register 'previously autodetected' instance group @@ -1002,11 +1011,10 @@ func TestFetchAutoMigsRegional(t *testing.T) { server.On("handle", "/project1/zones/"+zoneB+"/instanceGroupManagers/"+gceMigA).Return(buildInstanceGroupManagerResponse(zoneB, gceMigA)).Once() server.On("handle", "/project1/zones/"+zoneB+"/instanceGroupManagers/"+gceMigB).Return(buildInstanceGroupManagerResponse(zoneB, gceMigB)).Once() + // Regenerate instance cache server.On("handle", "/project1/global/instanceTemplates/"+gceMigA).Return(instanceTemplate).Once() server.On("handle", "/project1/global/instanceTemplates/"+gceMigB).Return(instanceTemplate).Once() - server.On("handle", "/project1/zones/"+zoneB+"/instanceGroupManagers/"+gceMigA).Return(buildInstanceGroupManagerResponse(zoneB, gceMigA)).Once() server.On("handle", "/project1/zones/"+zoneB+"/instanceGroupManagers/"+gceMigA+"/listManagedInstances").Return(buildFourRunningInstancesManagedInstancesResponse(zoneB, gceMigA)).Once() - server.On("handle", "/project1/zones/"+zoneB+"/instanceGroupManagers/"+gceMigB).Return(buildInstanceGroupManagerResponse(gceMigB, zoneB)).Once() server.On("handle", "/project1/zones/"+zoneB+"/instanceGroupManagers/"+gceMigB+"/listManagedInstances").Return(buildOneRunningInstanceManagedInstancesResponse(zoneB, gceMigB)).Once() regional := true @@ -1036,9 +1044,7 @@ func TestFetchExplicitMigs(t *testing.T) { server.On("handle", "/project1/global/instanceTemplates/"+gceMigA).Return(instanceTemplate).Once() server.On("handle", "/project1/global/instanceTemplates/"+gceMigB).Return(instanceTemplate).Once() - server.On("handle", "/project1/zones/"+zoneB+"/instanceGroupManagers/"+gceMigA).Return(buildInstanceGroupManagerResponse(zoneB, gceMigA)).Once() server.On("handle", "/project1/zones/"+zoneB+"/instanceGroupManagers/"+gceMigA+"/listManagedInstances").Return(buildFourRunningInstancesManagedInstancesResponse(zoneB, gceMigA)).Once() - server.On("handle", "/project1/zones/"+zoneB+"/instanceGroupManagers/"+gceMigB).Return(buildInstanceGroupManagerResponse(zoneB, gceMigB)).Once() server.On("handle", "/project1/zones/"+zoneB+"/instanceGroupManagers/"+gceMigB+"/listManagedInstances").Return(buildOneRunningInstanceManagedInstancesResponse(zoneB, gceMigB)).Once() regional := false @@ -1194,14 +1200,13 @@ func TestParseCustomMachineType(t *testing.T) { assert.Error(t, err) } -func validateMigExists(t *testing.T, migs []*MigInformation, zone string, name string, minSize int, maxSize int) { +func validateMigExists(t *testing.T, migs []Mig, zone string, name string, minSize int, maxSize int) { ref := GceRef{ projectId, zone, name, } - for _, migInformation := range migs { - mig := migInformation.Config + for _, mig := range migs { if mig.GceRef() == ref { assert.Equal(t, minSize, mig.MinSize()) assert.Equal(t, maxSize, mig.MaxSize()) @@ -1209,8 +1214,8 @@ func validateMigExists(t *testing.T, migs []*MigInformation, zone string, name s } } allRefs := []GceRef{} - for _, migInformation := range migs { - allRefs = append(allRefs, migInformation.Config.GceRef()) + for _, mig := range migs { + allRefs = append(allRefs, mig.GceRef()) } assert.Failf(t, "Mig not found", "Mig %v not found among %v", ref, allRefs) }