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

Commit 5942cde

Browse files
authored
Merge pull request #1282 from mwielgus/mig-node
Cluster-autoscaler: fix for multi-mig autoscaling
2 parents 9fe8cf7 + 39ee814 commit 5942cde

File tree

2 files changed

+42
-9
lines changed

2 files changed

+42
-9
lines changed

cluster-autoscaler/utils.go

+3
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

+39-9
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
@@ -75,8 +81,15 @@ func CreateGceManager(migs []*config.MigConfig, configReader io.Reader) (*GceMan
7581
return nil, err
7682
}
7783

84+
migInfos := make([]*migInformation, 0, len(migs))
85+
for _, mig := range migs {
86+
migInfos = append(migInfos, &migInformation{
87+
config: mig,
88+
})
89+
}
90+
7891
manager := &GceManager{
79-
migs: migs,
92+
migs: migInfos,
8093
service: gceService,
8194
migCache: map[config.InstanceConfig]*config.MigConfig{},
8295
}
@@ -165,13 +178,22 @@ func (m *GceManager) GetMigForInstance(instance *config.InstanceConfig) (*config
165178
if mig, found := m.migCache[*instance]; found {
166179
return mig, nil
167180
}
168-
if err := m.regenerateCache(); err != nil {
169-
return nil, fmt.Errorf("Error while looking for MIG for instance %+v, error: %v", *instance, err)
170-
}
171-
if mig, found := m.migCache[*instance]; found {
172-
return mig, nil
181+
182+
for _, mig := range m.migs {
183+
if mig.config.Project == instance.Project &&
184+
mig.config.Zone == instance.Zone &&
185+
strings.HasPrefix(instance.Name, mig.basename) {
186+
if err := m.regenerateCache(); err != nil {
187+
return nil, fmt.Errorf("Error while looking for MIG for instance %+v, error: %v", *instance, err)
188+
}
189+
if mig, found := m.migCache[*instance]; found {
190+
return mig, nil
191+
}
192+
return nil, fmt.Errorf("Instance %+v does not belong to any configured MIG", *instance)
193+
}
173194
}
174-
return nil, fmt.Errorf("Instance %+v does not belong to any known MIG", *instance)
195+
// Instance doesn't belong to any configured mig.
196+
return nil, nil
175197
}
176198

177199
func (m *GceManager) regenerateCacheIgnoreError() {
@@ -185,8 +207,16 @@ func (m *GceManager) regenerateCacheIgnoreError() {
185207
func (m *GceManager) regenerateCache() error {
186208
newMigCache := map[config.InstanceConfig]*config.MigConfig{}
187209

188-
for _, mig := range m.migs {
210+
for _, migInfo := range m.migs {
211+
mig := migInfo.config
189212
glog.V(4).Infof("Regenerating MIG information for %s %s %s", mig.Project, mig.Zone, mig.Name)
213+
214+
instanceGroupManager, err := m.service.InstanceGroupManagers.Get(mig.Project, mig.Zone, mig.Name).Do()
215+
if err != nil {
216+
return err
217+
}
218+
migInfo.basename = instanceGroupManager.BaseInstanceName
219+
190220
instances, err := m.service.InstanceGroupManagers.ListManagedInstances(mig.Project, mig.Zone, mig.Name).Do()
191221
if err != nil {
192222
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)