Skip to content

Commit

Permalink
Merge branch 'ca_region_fix' of github.com:shreyas-srinivas/autoscale…
Browse files Browse the repository at this point in the history
…r into ca_region_fix
  • Loading branch information
darkpssngr committed Jun 9, 2021
2 parents f6eb130 + 3fa5443 commit fde8ebd
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 30 deletions.
11 changes: 8 additions & 3 deletions cluster-autoscaler/core/static_autoscaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,15 @@ func NewStaticAutoscaler(

scaleDown := NewScaleDown(autoscalingContext, processors, clusterStateRegistry)

// Set the initial scale times to be less than the start time so as to
// not start in cooldown mode.
initialScaleTime := time.Now().Add(-time.Hour)
return &StaticAutoscaler{
AutoscalingContext: autoscalingContext,
startTime: time.Now(),
lastScaleUpTime: time.Now(),
lastScaleDownDeleteTime: time.Now(),
lastScaleDownFailTime: time.Now(),
lastScaleUpTime: initialScaleTime,
lastScaleDownDeleteTime: initialScaleTime,
lastScaleDownFailTime: initialScaleTime,
scaleDown: scaleDown,
processors: processors,
processorCallbacks: processorCallbacks,
Expand Down Expand Up @@ -257,7 +260,9 @@ func (a *StaticAutoscaler) RunOnce(currentTime time.Time) errors.AutoscalerError
}

// Call CloudProvider.Refresh before any other calls to cloud provider.
refreshStart := time.Now()
err = a.AutoscalingContext.CloudProvider.Refresh()
metrics.UpdateDurationFromStart(metrics.CloudProviderRefresh, refreshStart)
if err != nil {
klog.Errorf("Failed to refresh cloud provider config: %v", err)
return errors.ToAutoscalerError(errors.CloudProviderError, err)
Expand Down
52 changes: 26 additions & 26 deletions cluster-autoscaler/core/static_autoscaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -972,20 +972,20 @@ func TestStaticAutoscalerInstaceCreationErrors(t *testing.T) {
nodeGroupA.On("DeleteNodes", mock.Anything).Return(nil)
nodeGroupA.On("Nodes").Return([]cloudprovider.Instance{
{
"A1",
&cloudprovider.InstanceStatus{
Id: "A1",
Status: &cloudprovider.InstanceStatus{
State: cloudprovider.InstanceRunning,
},
},
{
"A2",
&cloudprovider.InstanceStatus{
Id: "A2",
Status: &cloudprovider.InstanceStatus{
State: cloudprovider.InstanceCreating,
},
},
{
"A3",
&cloudprovider.InstanceStatus{
Id: "A3",
Status: &cloudprovider.InstanceStatus{
State: cloudprovider.InstanceCreating,
ErrorInfo: &cloudprovider.InstanceErrorInfo{
ErrorClass: cloudprovider.OutOfResourcesErrorClass,
Expand All @@ -994,8 +994,8 @@ func TestStaticAutoscalerInstaceCreationErrors(t *testing.T) {
},
},
{
"A4",
&cloudprovider.InstanceStatus{
Id: "A4",
Status: &cloudprovider.InstanceStatus{
State: cloudprovider.InstanceCreating,
ErrorInfo: &cloudprovider.InstanceErrorInfo{
ErrorClass: cloudprovider.OutOfResourcesErrorClass,
Expand All @@ -1004,8 +1004,8 @@ func TestStaticAutoscalerInstaceCreationErrors(t *testing.T) {
},
},
{
"A5",
&cloudprovider.InstanceStatus{
Id: "A5",
Status: &cloudprovider.InstanceStatus{
State: cloudprovider.InstanceCreating,
ErrorInfo: &cloudprovider.InstanceErrorInfo{
ErrorClass: cloudprovider.OutOfResourcesErrorClass,
Expand All @@ -1014,8 +1014,8 @@ func TestStaticAutoscalerInstaceCreationErrors(t *testing.T) {
},
},
{
"A6",
&cloudprovider.InstanceStatus{
Id: "A6",
Status: &cloudprovider.InstanceStatus{
State: cloudprovider.InstanceCreating,
ErrorInfo: &cloudprovider.InstanceErrorInfo{
ErrorClass: cloudprovider.OtherErrorClass,
Expand All @@ -1032,8 +1032,8 @@ func TestStaticAutoscalerInstaceCreationErrors(t *testing.T) {
nodeGroupB.On("DeleteNodes", mock.Anything).Return(nil)
nodeGroupB.On("Nodes").Return([]cloudprovider.Instance{
{
"B1",
&cloudprovider.InstanceStatus{
Id: "B1",
Status: &cloudprovider.InstanceStatus{
State: cloudprovider.InstanceRunning,
},
},
Expand Down Expand Up @@ -1102,38 +1102,38 @@ func TestStaticAutoscalerInstaceCreationErrors(t *testing.T) {
// restub node group A so nodes are no longer reporting errors
nodeGroupA.On("Nodes").Return([]cloudprovider.Instance{
{
"A1",
&cloudprovider.InstanceStatus{
Id: "A1",
Status: &cloudprovider.InstanceStatus{
State: cloudprovider.InstanceRunning,
},
},
{
"A2",
&cloudprovider.InstanceStatus{
Id: "A2",
Status: &cloudprovider.InstanceStatus{
State: cloudprovider.InstanceCreating,
},
},
{
"A3",
&cloudprovider.InstanceStatus{
Id: "A3",
Status: &cloudprovider.InstanceStatus{
State: cloudprovider.InstanceDeleting,
},
},
{
"A4",
&cloudprovider.InstanceStatus{
Id: "A4",
Status: &cloudprovider.InstanceStatus{
State: cloudprovider.InstanceDeleting,
},
},
{
"A5",
&cloudprovider.InstanceStatus{
Id: "A5",
Status: &cloudprovider.InstanceStatus{
State: cloudprovider.InstanceDeleting,
},
},
{
"A6",
&cloudprovider.InstanceStatus{
Id: "A6",
Status: &cloudprovider.InstanceStatus{
State: cloudprovider.InstanceDeleting,
},
},
Expand Down
1 change: 1 addition & 0 deletions cluster-autoscaler/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ const (
FindUnneeded FunctionLabel = "findUnneeded"
UpdateState FunctionLabel = "updateClusterState"
FilterOutSchedulable FunctionLabel = "filterOutSchedulable"
CloudProviderRefresh FunctionLabel = "cloudProviderRefresh"
Main FunctionLabel = "main"
Poll FunctionLabel = "poll"
Reconfigure FunctionLabel = "reconfigure"
Expand Down
2 changes: 1 addition & 1 deletion cluster-autoscaler/simulator/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func TestUtilization(t *testing.T) {
assert.InEpsilon(t, 2.0/10, utilInfo.Utilization, 0.01)

terminatedPod := BuildTestPod("podTerminated", 100, 200000)
terminatedPod.DeletionTimestamp = &metav1.Time{testTime.Add(-10 * time.Minute)}
terminatedPod.DeletionTimestamp = &metav1.Time{Time: testTime.Add(-10 * time.Minute)}
nodeInfo = schedulerframework.NewNodeInfo(pod, pod, pod2, terminatedPod)
utilInfo, err = CalculateUtilization(node, nodeInfo, false, false, gpuLabel, testTime)
assert.NoError(t, err)
Expand Down

0 comments on commit fde8ebd

Please sign in to comment.