diff --git a/pkg/driver/executor/errors.go b/pkg/driver/executor/errors.go index eb344cff..466d29f1 100644 --- a/pkg/driver/executor/errors.go +++ b/pkg/driver/executor/errors.go @@ -8,12 +8,21 @@ import ( "fmt" ) -// NoValidHost is a part of the error message returned when there is no valid host in the zone to deploy a VM. -// Matches: -// -// "No valid host was found." -// "No valid host was found. There are not enough hosts available." -const NoValidHost = "No valid host was found" +const ( + // NoValidHost is a part of the error message returned when there is no valid host in the zone to deploy a VM. + // Matches: + // + // "No valid host was found." + // "No valid host was found. There are not enough hosts available." + NoValidHost = "No valid host was found" + + // FlavorNotFound is part of the error message returned when a flavor cannot be resolved. + // This string-matching fallback is needed because FlavorIDFromName (from executor.go deployServer) + // only wraps the typed ErrFlavorNotFound when the underlying gophercloud error is gophercloud.ErrResourceNotFound. + // If gophercloud returns any other error type, the typed-error path in mapErrorToCode will not match, and + // we fall back to inspecting the error message here so the failure is still classified as codes.ResourceExhausted. + FlavorNotFound = "error resolving flavor" +) var ( // ErrNotFound is returned when the requested resource could not be found. diff --git a/pkg/driver/utils.go b/pkg/driver/utils.go index 60703483..04094208 100644 --- a/pkg/driver/utils.go +++ b/pkg/driver/utils.go @@ -72,7 +72,7 @@ func mapErrorToCode(err error) codes.Code { func mapErrorMessageToCode(err error) codes.Code { errorMessage := err.Error() - if strings.Contains(errorMessage, executor.NoValidHost) { + if strings.Contains(errorMessage, executor.NoValidHost) || strings.Contains(errorMessage, executor.FlavorNotFound) { return codes.ResourceExhausted } return codes.Internal diff --git a/pkg/driver/utils_test.go b/pkg/driver/utils_test.go index d0bfc5d4..af32a1ac 100644 --- a/pkg/driver/utils_test.go +++ b/pkg/driver/utils_test.go @@ -61,5 +61,12 @@ var _ = Describe("Utils", func() { Expect(err2).To(HaveOccurred()) Expect(mapErrorToCode(err1)).To(Equal(codes.Internal)) }) + It("should map error containing executor.FlavorNotFound to ResourceExhausted error code", func() { + err1 := fmt.Errorf("error: %s", executor.FlavorNotFound) + err2 := status.Error(mapErrorToCode(err1), err1.Error()) + Expect(err1).To(HaveOccurred()) + Expect(err2).To(HaveOccurred()) + Expect(mapErrorToCode(err1)).To(Equal(codes.ResourceExhausted)) + }) }) })