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

ResourceExhausted error code mapping introduced for GCP #92

Merged
merged 4 commits into from
Sep 21, 2023
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@

# Output of the go coverage tool
*coverprofile.out*
/local/
/local/
34 changes: 19 additions & 15 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ require (
github.com/pkg/errors v0.9.1
github.com/spf13/pflag v1.0.5
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616
golang.org/x/net v0.7.0
golang.org/x/oauth2 v0.0.0-20220411215720-9780585627b5
google.golang.org/api v0.57.0
golang.org/x/net v0.14.0
golang.org/x/oauth2 v0.11.0
google.golang.org/api v0.138.0
k8s.io/api v0.26.2
k8s.io/apimachinery v0.26.2
k8s.io/component-base v0.26.2
Expand All @@ -20,14 +20,15 @@ require (
)

require (
cloud.google.com/go v0.97.0 // indirect
cloud.google.com/go/compute v1.23.0 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
github.com/Masterminds/semver v1.5.0 // indirect
github.com/Microsoft/go-winio v0.4.16 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7 // indirect
github.com/acomagu/bufpipe v1.0.3 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/blang/semver/v4 v4.0.0 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emicklei/go-restful/v3 v3.9.0 // indirect
github.com/emirpasic/gods v1.12.0 // indirect
Expand All @@ -43,11 +44,14 @@ require (
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/gnostic v0.5.7-v3refs // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/gofuzz v1.1.0 // indirect
github.com/googleapis/gax-go/v2 v2.1.0 // indirect
github.com/google/s2a-go v0.1.5 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.2.5 // indirect
github.com/googleapis/gax-go/v2 v2.12.0 // indirect
github.com/imdario/mergo v0.3.12 // indirect
github.com/inconshreveable/mousetrap v1.0.1 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
Expand All @@ -68,17 +72,17 @@ require (
github.com/sergi/go-diff v1.1.0 // indirect
github.com/spf13/cobra v1.6.1 // indirect
github.com/xanzy/ssh-agent v0.3.0 // indirect
go.opencensus.io v0.23.0 // indirect
golang.org/x/crypto v0.6.0 // indirect
golang.org/x/sys v0.5.0 // indirect
golang.org/x/term v0.5.0 // indirect
golang.org/x/text v0.7.0 // indirect
go.opencensus.io v0.24.0 // indirect
golang.org/x/crypto v0.12.0 // indirect
golang.org/x/sys v0.11.0 // indirect
golang.org/x/term v0.11.0 // indirect
golang.org/x/text v0.12.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.6.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20220502173005-c8bf987b8c21 // indirect
google.golang.org/grpc v1.49.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230807174057-1744710a1577 // indirect
google.golang.org/grpc v1.57.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
Expand Down
230 changes: 61 additions & 169 deletions go.sum

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions pkg/gcp/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,13 @@ type MachineNotFoundError struct {
func (e *MachineNotFoundError) Error() string {
return fmt.Sprintf("machine name=%s, uuid=%s not found", e.Name, e.MachineID)
}

// MachineResourceExhaustedError is used to indicate resource exhausted error in PluginSPI
type MachineResourceExhaustedError struct {
// error msg of error classified as resource exhausted
Msg string
}

func (e *MachineResourceExhaustedError) Error() string {
return e.Msg
}
33 changes: 29 additions & 4 deletions pkg/gcp/machine_controller_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func (ms *MachinePlugin) CreateMachineUtil(ctx context.Context, machineName stri
instance.ServiceAccounts = serviceAccounts
operation, err := computeService.Instances.Insert(project, zone, instance).Context(ctx).Do()
if err != nil {
return "", err
return "", classifyIfResourceExhaustedError(err)
}

if err := WaitUntilOperationCompleted(computeService, project, zone, operation.Name); err != nil {
Expand Down Expand Up @@ -375,6 +375,9 @@ func prepareErrorf(err error, format string, args ...interface{}) error {
case *errors2.MachineNotFoundError:
code = codes.NotFound
wrapped = err
case *errors2.MachineResourceExhaustedError:
code = codes.ResourceExhausted
wrapped = errors.Wrap(err, fmt.Sprintf(format, args...))
default:
code = codes.Internal
wrapped = errors.Wrap(err, fmt.Sprintf(format, args...))
Expand Down Expand Up @@ -408,11 +411,16 @@ func WaitUntilOperationCompleted(computeService *compute.Service, project, zone,
if op.Error == nil {
return true, nil
}
var err []error
var (
errorMessages []string
latestOpErr *compute.OperationErrorErrors
)
for _, opErr := range op.Error.Errors {
err = append(err, fmt.Errorf("%s", *opErr))
latestOpErr = opErr
errorMessages = append(errorMessages, opErr.Message)
}
return false, fmt.Errorf("The following errors occurred: %+v", err)

return false, checkIfResourceExhaustedError(latestOpErr, errorMessages)
}
return false, nil
})
Expand All @@ -431,3 +439,20 @@ func getUserData(userData string) *compute.MetadataItems {
Value: &userData,
}
}

func classifyIfResourceExhaustedError(err error) error {
gerr, ok := err.(*googleapi.Error)
// https://cloud.google.com/compute/docs/troubleshooting/troubleshooting-vm-creation#zone_availability also depends on error message, that's why adopted this approach
if ok && strings.Contains(gerr.Message, "does not exist in zone") {
return &errors2.MachineResourceExhaustedError{Msg: err.Error()}
}
return err
}

func checkIfResourceExhaustedError(opErr *compute.OperationErrorErrors, errorMessages []string) error {
combinedErrMsg := strings.Join(errorMessages, "; ")
if opErr.Code == "RESOURCE_POOL_EXHAUSTED" || opErr.Code == "ZONE_RESOURCE_POOL_EXHAUSTED" || opErr.Code == "ZONE_RESOURCE_POOL_EXHAUSTED_WITH_DETAILS" || strings.Contains(opErr.Code, "QUOTA") {
return &errors2.MachineResourceExhaustedError{Msg: combinedErrMsg}
}
return fmt.Errorf(combinedErrMsg)
}
18 changes: 18 additions & 0 deletions vendor/cloud.google.com/go/compute/internal/version.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions vendor/cloud.google.com/go/compute/metadata/CHANGES.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions vendor/cloud.google.com/go/compute/metadata/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 19 additions & 12 deletions vendor/cloud.google.com/go/compute/metadata/metadata.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions vendor/cloud.google.com/go/compute/metadata/tidyfix.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 17 additions & 14 deletions vendor/github.com/cespare/xxhash/v2/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions vendor/github.com/cespare/xxhash/v2/testall.sh

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading