Skip to content

Commit

Permalink
Unwind some purely stylistic changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nic Cope committed Dec 1, 2017
1 parent 1d6c9d3 commit df80002
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 52 deletions.
90 changes: 42 additions & 48 deletions cluster-autoscaler/cloudprovider/gce/gce_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package gce

import (
"context"
"errors"
"flag"
"fmt"
"io"
Expand Down Expand Up @@ -500,14 +499,14 @@ func (m *gceManagerImpl) RegisterMig(mig *Mig) bool {
if oldMig := m.migs[i].config; oldMig.GceRef == mig.GceRef {
if !reflect.DeepEqual(oldMig, mig) {
m.migs[i].config = mig
glog.V(4).Infof("Updated MIG %s/%s/%s", mig.GceRef.Project, mig.GceRef.Zone, mig.GceRef.Name)
glog.V(4).Infof("Updated Mig %s/%s/%s", mig.GceRef.Project, mig.GceRef.Zone, mig.GceRef.Name)
return true
}
return false
}
}

glog.V(1).Infof("Registering MIG %s/%s/%s", mig.GceRef.Project, mig.GceRef.Zone, mig.GceRef.Name)
glog.V(1).Infof("Registering %s/%s/%s", mig.GceRef.Project, mig.GceRef.Zone, mig.GceRef.Name)
m.migs = append(m.migs, &migInformation{
config: mig,
})
Expand Down Expand Up @@ -681,7 +680,7 @@ func (m *gceManagerImpl) DeleteInstances(instances []*GceRef) error {
return err
}
if mig != commonMig {
return errors.New("Cannot delete instances which don't belong to the same MIG.")
return fmt.Errorf("Cannot delete instances which don't belong to the same MIG.")
}
}

Expand Down Expand Up @@ -730,22 +729,17 @@ func (m *gceManagerImpl) GetMigForInstance(instance *GceRef) (*Mig, error) {
}

for _, mig := range m.getMigs() {
if mig.config.Project != instance.Project {
continue
}
if mig.config.Zone != instance.Zone {
continue
}
if !strings.HasPrefix(instance.Name, mig.basename) {
continue
}
if err := m.regenerateCacheWithoutLock(); err != nil {
return nil, fmt.Errorf("Error while looking for MIG for instance %+v, error: %v", *instance, err)
}
if mig, found := m.migCache[*instance]; found {
return mig, nil
if mig.config.Project == instance.Project &&
mig.config.Zone == instance.Zone &&
strings.HasPrefix(instance.Name, mig.basename) {
if err := m.regenerateCacheWithoutLock(); err != nil {
return nil, fmt.Errorf("Error while looking for MIG for instance %+v, error: %v", *instance, err)
}
if mig, found := m.migCache[*instance]; found {
return mig, nil
}
return nil, fmt.Errorf("Instance %+v does not belong to any configured MIG", *instance)
}
return nil, fmt.Errorf("Instance %+v does not belong to any configured MIG", *instance)
}
// Instance doesn't belong to any configured mig.
return nil, nil
Expand Down Expand Up @@ -948,40 +942,40 @@ func (m *gceManagerImpl) buildMigFromAutoCfg(link string, cfg cloudprovider.MIGA
}

func (m *gceManagerImpl) fetchResourceLimiter() error {
m.assertGKENAP()

cluster, err := m.gkeAlphaService.Projects.Zones.Clusters.Get(m.projectId, m.location, m.clusterName).Do()
if err != nil {
return err
}
if cluster.Autoscaling == nil {
return nil
}
if m.mode == ModeGKENAP {
cluster, err := m.gkeAlphaService.Projects.Zones.Clusters.Get(m.projectId, m.location, m.clusterName).Do()
if err != nil {
return err
}
if cluster.Autoscaling == nil {
return nil
}

minLimits := make(map[string]int64)
maxLimits := make(map[string]int64)
for _, limit := range cluster.Autoscaling.ResourceLimits {
if _, found := supportedResources[limit.Name]; !found {
glog.Warning("Unsupported limit defined %s: %d - %d", limit.Name, limit.Minimum, limit.Maximum)
minLimits := make(map[string]int64)
maxLimits := make(map[string]int64)
for _, limit := range cluster.Autoscaling.ResourceLimits {
if _, found := supportedResources[limit.Name]; !found {
glog.Warning("Unsupported limit defined %s: %d - %d", limit.Name, limit.Minimum, limit.Maximum)
}
minLimits[limit.Name] = limit.Minimum
maxLimits[limit.Name] = limit.Maximum
}
minLimits[limit.Name] = limit.Minimum
maxLimits[limit.Name] = limit.Maximum
}

// GKE API provides memory in GB, but ResourceLimiter expects them in MB
if _, found := minLimits[cloudprovider.ResourceNameMemory]; found {
minLimits[cloudprovider.ResourceNameMemory] = minLimits[cloudprovider.ResourceNameMemory] * 1024
}
if _, found := maxLimits[cloudprovider.ResourceNameMemory]; found {
maxLimits[cloudprovider.ResourceNameMemory] = maxLimits[cloudprovider.ResourceNameMemory] * 1024
}
// GKE API provides memory in GB, but ResourceLimiter expects them in MB
if _, found := minLimits[cloudprovider.ResourceNameMemory]; found {
minLimits[cloudprovider.ResourceNameMemory] = minLimits[cloudprovider.ResourceNameMemory] * 1024
}
if _, found := maxLimits[cloudprovider.ResourceNameMemory]; found {
maxLimits[cloudprovider.ResourceNameMemory] = maxLimits[cloudprovider.ResourceNameMemory] * 1024
}

resourceLimiter := cloudprovider.NewResourceLimiter(minLimits, maxLimits)
glog.V(2).Infof("Refreshed resource limits: %s", resourceLimiter.String())
resourceLimiter := cloudprovider.NewResourceLimiter(minLimits, maxLimits)
glog.V(2).Infof("Refreshed resource limits: %s", resourceLimiter.String())

m.cacheMutex.Lock()
defer m.cacheMutex.Unlock()
m.resourceLimiter = resourceLimiter
m.cacheMutex.Lock()
defer m.cacheMutex.Unlock()
m.resourceLimiter = resourceLimiter
}
return nil
}

Expand Down
7 changes: 3 additions & 4 deletions cluster-autoscaler/core/autoscaling_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,9 @@ func NewAutoscalingContext(options AutoscalingOptions, predicateChecker *simulat
cloudprovider.NodeGroupDiscoveryOptions{NodeGroupSpecs: options.NodeGroups, NodeGroupAutoDiscoverySpecs: options.NodeGroupAutoDiscovery},
cloudprovider.NewResourceLimiter(
map[string]int64{cloudprovider.ResourceNameCores: int64(options.MinCoresTotal), cloudprovider.ResourceNameMemory: options.MinMemoryTotal},
map[string]int64{cloudprovider.ResourceNameCores: options.MaxCoresTotal, cloudprovider.ResourceNameMemory: options.MaxMemoryTotal},
),
)
expanderStrategy, err := factory.ExpanderStrategyFromString(options.ExpanderName, cloudProvider, listerRegistry.AllNodeLister())
map[string]int64{cloudprovider.ResourceNameCores: options.MaxCoresTotal, cloudprovider.ResourceNameMemory: options.MaxMemoryTotal}))
expanderStrategy, err := factory.ExpanderStrategyFromString(options.ExpanderName,
cloudProvider, listerRegistry.AllNodeLister())
if err != nil {
return nil, err
}
Expand Down

0 comments on commit df80002

Please sign in to comment.