Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a new error code to GCE autoscaling client #5057

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions cluster-autoscaler/cloudprovider/gce/autoscaling_gce_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ const (
// permissions error
ErrorCodePermissions = "PERMISSIONS_ERROR"

// ErrorCodeVmExternalIpAccessPolicyConstraint is an error code in InstanceErrorInfo if the user
// is facing errors caused by vmExternalIpAccess policy constraint misconfiguration.
ErrorCodeVmExternalIpAccessPolicyConstraint = "VM_EXTERNAL_IP_ACCESS_POLICY_CONSTRAINT"

// ErrorCodeOther is an error code used in InstanceErrorInfo if other error occurs.
ErrorCodeOther = "OTHER"
)
Expand Down Expand Up @@ -306,6 +310,9 @@ func (client *autoscalingGceClientV1) FetchMigInstances(migRef GceRef) ([]cloudp
} else if isPermissionsError(instanceError.Code) {
errorInfo.ErrorClass = cloudprovider.OtherErrorClass
errorInfo.ErrorCode = ErrorCodePermissions
} else if isVmExternalIpAccessPolicyConstraintError(instanceError) {
errorInfo.ErrorClass = cloudprovider.OtherErrorClass
errorInfo.ErrorCode = ErrorCodeVmExternalIpAccessPolicyConstraint
} else if isInstanceNotRunningYet(gceInstance) {
if !errorFound {
// do not override error code with OTHER
Expand Down Expand Up @@ -369,6 +376,11 @@ func isPermissionsError(errorCode string) bool {
return strings.Contains(errorCode, "PERMISSIONS_ERROR")
}

func isVmExternalIpAccessPolicyConstraintError(err *gce.ManagedInstanceLastAttemptErrorsErrors) bool {
regexProjectPolicyConstraint := regexp.MustCompile(`Constraint constraints/compute.vmExternalIpAccess violated for project`)
return strings.Contains(err.Code, "CONDITION_NOT_MET") && regexProjectPolicyConstraint.MatchString(err.Message)
}

func isInstanceNotRunningYet(gceInstance *gce.ManagedInstance) bool {
return gceInstance.InstanceStatus == "" || gceInstance.InstanceStatus == "PROVISIONING" || gceInstance.InstanceStatus == "STAGING"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ func TestErrors(t *testing.T) {

testCases := []struct {
errorCodes []string
errorMessage string
expectedErrorCode string
expectedErrorClass cloudprovider.InstanceErrorClass
}{
Expand All @@ -166,6 +167,12 @@ func TestErrors(t *testing.T) {
expectedErrorCode: "PERMISSIONS_ERROR",
expectedErrorClass: cloudprovider.OtherErrorClass,
},
{
errorCodes: []string{"CONDITION_NOT_MET"},
errorMessage: "Instance 'myinst' creation failed: Constraint constraints/compute.vmExternalIpAccess violated for project 1234567890.",
expectedErrorCode: "VM_EXTERNAL_IP_ACCESS_POLICY_CONSTRAINT",
expectedErrorClass: cloudprovider.OtherErrorClass,
},
{
errorCodes: []string{"xyz", "abc"},
expectedErrorCode: "OTHER",
Expand All @@ -183,7 +190,8 @@ func TestErrors(t *testing.T) {
Errors: &gce_api.ManagedInstanceLastAttemptErrors{
Errors: []*gce_api.ManagedInstanceLastAttemptErrorsErrors{
{
Code: errorCode,
Code: errorCode,
Message: tc.errorMessage,
},
},
},
Expand Down