Skip to content
This repository was archived by the owner on Apr 17, 2019. It is now read-only.

Commit 39ee814

Browse files
committed
Cluster-autoscaler: fix for multi-mig autoscaling
1 parent fe721a9 commit 39ee814

File tree

2 files changed

+42
-9
lines changed

2 files changed

+42
-9
lines changed

cluster-autoscaler/utils.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,9 @@ func CheckMigsAndNodes(nodes []*kube_api.Node, gceManager *gce.GceManager) error
241241
if err != nil {
242242
return err
243243
}
244+
if migConfig == nil {
245+
continue
246+
}
244247
url := migConfig.Url()
245248
count, _ := migCount[url]
246249
migCount[url] = count + 1

cluster-autoscaler/utils/gce/gce.go

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package gce
1919
import (
2020
"fmt"
2121
"io"
22+
"strings"
2223
"sync"
2324
"time"
2425

@@ -40,9 +41,14 @@ const (
4041
operationPollInterval = 100 * time.Millisecond
4142
)
4243

44+
type migInformation struct {
45+
config *config.MigConfig
46+
basename string
47+
}
48+
4349
// GceManager is handles gce communication and data caching.
4450
type GceManager struct {
45-
migs []*config.MigConfig
51+
migs []*migInformation
4652
service *gce.Service
4753
migCache map[config.InstanceConfig]*config.MigConfig
4854
cacheMutex sync.Mutex
@@ -74,8 +80,15 @@ func CreateGceManager(migs []*config.MigConfig, configReader io.Reader) (*GceMan
7480
return nil, err
7581
}
7682

83+
migInfos := make([]*migInformation, 0, len(migs))
84+
for _, mig := range migs {
85+
migInfos = append(migInfos, &migInformation{
86+
config: mig,
87+
})
88+
}
89+
7790
manager := &GceManager{
78-
migs: migs,
91+
migs: migInfos,
7992
service: gceService,
8093
migCache: map[config.InstanceConfig]*config.MigConfig{},
8194
}
@@ -164,13 +177,22 @@ func (m *GceManager) GetMigForInstance(instance *config.InstanceConfig) (*config
164177
if mig, found := m.migCache[*instance]; found {
165178
return mig, nil
166179
}
167-
if err := m.regenerateCache(); err != nil {
168-
return nil, fmt.Errorf("Error while looking for MIG for instance %+v, error: %v", *instance, err)
169-
}
170-
if mig, found := m.migCache[*instance]; found {
171-
return mig, nil
180+
181+
for _, mig := range m.migs {
182+
if mig.config.Project == instance.Project &&
183+
mig.config.Zone == instance.Zone &&
184+
strings.HasPrefix(instance.Name, mig.basename) {
185+
if err := m.regenerateCache(); err != nil {
186+
return nil, fmt.Errorf("Error while looking for MIG for instance %+v, error: %v", *instance, err)
187+
}
188+
if mig, found := m.migCache[*instance]; found {
189+
return mig, nil
190+
}
191+
return nil, fmt.Errorf("Instance %+v does not belong to any configured MIG", *instance)
192+
}
172193
}
173-
return nil, fmt.Errorf("Instance %+v does not belong to any known MIG", *instance)
194+
// Instance doesn't belong to any configured mig.
195+
return nil, nil
174196
}
175197

176198
func (m *GceManager) regenerateCacheIgnoreError() {
@@ -184,8 +206,16 @@ func (m *GceManager) regenerateCacheIgnoreError() {
184206
func (m *GceManager) regenerateCache() error {
185207
newMigCache := map[config.InstanceConfig]*config.MigConfig{}
186208

187-
for _, mig := range m.migs {
209+
for _, migInfo := range m.migs {
210+
mig := migInfo.config
188211
glog.V(4).Infof("Regenerating MIG information for %s %s %s", mig.Project, mig.Zone, mig.Name)
212+
213+
instanceGroupManager, err := m.service.InstanceGroupManagers.Get(mig.Project, mig.Zone, mig.Name).Do()
214+
if err != nil {
215+
return err
216+
}
217+
migInfo.basename = instanceGroupManager.BaseInstanceName
218+
189219
instances, err := m.service.InstanceGroupManagers.ListManagedInstances(mig.Project, mig.Zone, mig.Name).Do()
190220
if err != nil {
191221
glog.V(4).Infof("Failed MIG info request for %s %s %s: %v", mig.Project, mig.Zone, mig.Name, err)

0 commit comments

Comments
 (0)