Support for reporting authorization errors during scale up

This commit is contained in:
Brett Elliott 2021-03-12 16:36:57 +01:00
parent a8ae4070ab
commit 4cddaed2f2
4 changed files with 31 additions and 5 deletions

View File

@ -666,9 +666,13 @@ func executeScaleUp(context *context.AutoscalingContext, clusterStateRegistry *c
increase := info.NewSize - info.CurrentSize increase := info.NewSize - info.CurrentSize
if err := info.Group.IncreaseSize(increase); err != nil { 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) context.LogRecorder.Eventf(apiv1.EventTypeWarning, "FailedToScaleUpGroup", "Scale-up failed for group %s: %v", info.Group.Id(), err)
clusterStateRegistry.RegisterFailedScaleUp(info.Group, metrics.CloudProviderError, now) reason := metrics.CloudProviderError
return errors.NewAutoscalerError(errors.CloudProviderError, aerr := errors.ToAutoscalerError(errors.CloudProviderError, err).AddPrefix("failed to increase node group size: %v", err)
"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( clusterStateRegistry.RegisterOrUpdateScaleUp(
info.Group, info.Group,

View File

@ -23,13 +23,15 @@ import (
"testing" "testing"
"time" "time"
"k8s.io/autoscaler/cluster-autoscaler/core/utils"
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider" "k8s.io/autoscaler/cluster-autoscaler/cloudprovider"
mockprovider "k8s.io/autoscaler/cluster-autoscaler/cloudprovider/mocks"
testprovider "k8s.io/autoscaler/cluster-autoscaler/cloudprovider/test" testprovider "k8s.io/autoscaler/cluster-autoscaler/cloudprovider/test"
"k8s.io/autoscaler/cluster-autoscaler/clusterstate" "k8s.io/autoscaler/cluster-autoscaler/clusterstate"
"k8s.io/autoscaler/cluster-autoscaler/config" "k8s.io/autoscaler/cluster-autoscaler/config"
"k8s.io/autoscaler/cluster-autoscaler/core/utils"
"k8s.io/autoscaler/cluster-autoscaler/estimator" "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" kube_util "k8s.io/autoscaler/cluster-autoscaler/utils/kubernetes"
. "k8s.io/autoscaler/cluster-autoscaler/utils/test" . "k8s.io/autoscaler/cluster-autoscaler/utils/test"
"k8s.io/autoscaler/cluster-autoscaler/utils/units" "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())
}

View File

@ -65,6 +65,8 @@ const (
APIError FailedScaleUpReason = "apiCallError" APIError FailedScaleUpReason = "apiCallError"
// Timeout was encountered when trying to scale-up // Timeout was encountered when trying to scale-up
Timeout FailedScaleUpReason = "timeout" Timeout FailedScaleUpReason = "timeout"
// AuthorizationError is an authorization error.
AuthorizationError FailedScaleUpReason = "authorizationError"
// autoscaledGroup is managed by CA // autoscaledGroup is managed by CA
autoscaledGroup NodeGroupType = "autoscaled" autoscaledGroup NodeGroupType = "autoscaled"

View File

@ -61,6 +61,8 @@ const (
// NodeGroupDoesNotExistError signifies that a NodeGroup // NodeGroupDoesNotExistError signifies that a NodeGroup
// does not exist. // does not exist.
NodeGroupDoesNotExistError AutoscalerErrorType = "nodeGroupDoesNotExistError" 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 // NewAutoscalerError returns new autoscaler error with a message constructed from format string