diff --git a/cluster-autoscaler/core/scale_up.go b/cluster-autoscaler/core/scale_up.go index 0209c4cbd58d..567ff064ba52 100644 --- a/cluster-autoscaler/core/scale_up.go +++ b/cluster-autoscaler/core/scale_up.go @@ -666,9 +666,13 @@ func executeScaleUp(context *context.AutoscalingContext, clusterStateRegistry *c increase := info.NewSize - info.CurrentSize if err := info.Group.IncreaseSize(increase); err != nil { context.LogRecorder.Eventf(apiv1.EventTypeWarning, "FailedToScaleUpGroup", "Scale-up failed for group %s: %v", info.Group.Id(), err) - clusterStateRegistry.RegisterFailedScaleUp(info.Group, metrics.CloudProviderError, now) - return errors.NewAutoscalerError(errors.CloudProviderError, - "failed to increase node group size: %v", err) + reason := metrics.CloudProviderError + aerr := errors.ToAutoscalerError(errors.CloudProviderError, err).AddPrefix("failed to increase node group size: %v", err) + if aerr.Type() == errors.AuthorizationError { + reason = metrics.AuthorizationError + } + clusterStateRegistry.RegisterFailedScaleUp(info.Group, reason, now) + return aerr } clusterStateRegistry.RegisterOrUpdateScaleUp( info.Group, diff --git a/cluster-autoscaler/core/scale_up_test.go b/cluster-autoscaler/core/scale_up_test.go index 453226e21e3f..69cb35e67e1c 100644 --- a/cluster-autoscaler/core/scale_up_test.go +++ b/cluster-autoscaler/core/scale_up_test.go @@ -23,13 +23,15 @@ import ( "testing" "time" - "k8s.io/autoscaler/cluster-autoscaler/core/utils" - "k8s.io/autoscaler/cluster-autoscaler/cloudprovider" + mockprovider "k8s.io/autoscaler/cluster-autoscaler/cloudprovider/mocks" testprovider "k8s.io/autoscaler/cluster-autoscaler/cloudprovider/test" "k8s.io/autoscaler/cluster-autoscaler/clusterstate" "k8s.io/autoscaler/cluster-autoscaler/config" + "k8s.io/autoscaler/cluster-autoscaler/core/utils" "k8s.io/autoscaler/cluster-autoscaler/estimator" + "k8s.io/autoscaler/cluster-autoscaler/processors/nodegroupset" + "k8s.io/autoscaler/cluster-autoscaler/utils/errors" kube_util "k8s.io/autoscaler/cluster-autoscaler/utils/kubernetes" . "k8s.io/autoscaler/cluster-autoscaler/utils/test" "k8s.io/autoscaler/cluster-autoscaler/utils/units" @@ -970,3 +972,19 @@ func TestCheckScaleUpDeltaWithinLimits(t *testing.T) { } } } + +func TestAuthError(t *testing.T) { + context, err := NewScaleTestAutoscalingContext(config.AutoscalingOptions{}, &fake.Clientset{}, nil, nil, nil) + assert.NoError(t, err) + + nodeGroup := &mockprovider.NodeGroup{} + info := nodegroupset.ScaleUpInfo{Group: nodeGroup} + nodeGroup.On("Id").Return("A") + nodeGroup.On("IncreaseSize", 0).Return(errors.NewAutoscalerError(errors.AuthorizationError, "")) + + clusterStateRegistry := clusterstate.NewClusterStateRegistry(nil, clusterstate.ClusterStateRegistryConfig{}, context.LogRecorder, newBackoff()) + + aerr := executeScaleUp(&context, clusterStateRegistry, info, "", time.Now()) + assert.Error(t, aerr) + assert.Equal(t, errors.AuthorizationError, aerr.Type()) +} diff --git a/cluster-autoscaler/metrics/metrics.go b/cluster-autoscaler/metrics/metrics.go index e3b5ed22edbd..efcfc18540a8 100644 --- a/cluster-autoscaler/metrics/metrics.go +++ b/cluster-autoscaler/metrics/metrics.go @@ -65,6 +65,8 @@ const ( APIError FailedScaleUpReason = "apiCallError" // Timeout was encountered when trying to scale-up Timeout FailedScaleUpReason = "timeout" + // AuthorizationError is an authorization error. + AuthorizationError FailedScaleUpReason = "authorizationError" // autoscaledGroup is managed by CA autoscaledGroup NodeGroupType = "autoscaled" diff --git a/cluster-autoscaler/utils/errors/errors.go b/cluster-autoscaler/utils/errors/errors.go index fbdd6e22a674..22216e5f867b 100644 --- a/cluster-autoscaler/utils/errors/errors.go +++ b/cluster-autoscaler/utils/errors/errors.go @@ -61,6 +61,8 @@ const ( // NodeGroupDoesNotExistError signifies that a NodeGroup // does not exist. NodeGroupDoesNotExistError AutoscalerErrorType = "nodeGroupDoesNotExistError" + // AuthorizationError signifies that an authorization error occurred. + AuthorizationError AutoscalerErrorType = "authorizationError" ) // NewAutoscalerError returns new autoscaler error with a message constructed from format string