Skip to content

Commit

Permalink
Merge pull request kubernetes#5057 from NastassiaM/add-new-error-code…
Browse files Browse the repository at this point in the history
…-to-gce-autoscaling-client

Add a new error code to GCE autoscaling client
  • Loading branch information
k8s-ci-robot authored Jul 29, 2022
2 parents 1cfdb60 + 16356ba commit 7a36158
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
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

0 comments on commit 7a36158

Please sign in to comment.