From 9ffe7e90436fc947eed743c1a28c85fccfc86fc1 Mon Sep 17 00:00:00 2001 From: viragvoros Date: Thu, 7 May 2026 16:28:17 +0200 Subject: [PATCH 1/4] Feature: Map flavor not found to ResourceExhausted grpc code --- pkg/driver/executor/errors.go | 17 +++++++++++------ pkg/driver/utils.go | 2 +- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/pkg/driver/executor/errors.go b/pkg/driver/executor/errors.go index eb344cff..959d18eb 100644 --- a/pkg/driver/executor/errors.go +++ b/pkg/driver/executor/errors.go @@ -8,12 +8,17 @@ 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. + 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 From 63aef65ae23083ac8fa20198799bc41c30c5cd86 Mon Sep 17 00:00:00 2001 From: viragvoros Date: Mon, 11 May 2026 18:06:31 +0200 Subject: [PATCH 2/4] add review points --- pkg/driver/executor/errors.go | 4 ++++ pkg/driver/utils_test.go | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/pkg/driver/executor/errors.go b/pkg/driver/executor/errors.go index 959d18eb..52cd320c 100644 --- a/pkg/driver/executor/errors.go +++ b/pkg/driver/executor/errors.go @@ -17,6 +17,10 @@ const ( 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 FlavourIDFromName (from executor.go deployServer) + // only wraps the typed ErrFlavorNotFound when the undelying 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" ) diff --git a/pkg/driver/utils_test.go b/pkg/driver/utils_test.go index d0bfc5d4..100e73af 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.FlavorNotFoundto 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)) + }) }) }) From 66ff215a75dcf16e05eafa56f6aa4c52b5386411 Mon Sep 17 00:00:00 2001 From: viragvoros Date: Tue, 12 May 2026 08:52:47 +0200 Subject: [PATCH 3/4] add nit --- pkg/driver/executor/errors.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/driver/executor/errors.go b/pkg/driver/executor/errors.go index 52cd320c..9afca572 100644 --- a/pkg/driver/executor/errors.go +++ b/pkg/driver/executor/errors.go @@ -18,9 +18,9 @@ const ( // FlavorNotFound is part of the error message returned when a flavor cannot be resolved. // This string-matching fallback is needed because FlavourIDFromName (from executor.go deployServer) - // only wraps the typed ErrFlavorNotFound when the undelying gophercloud error is gophercloud.ErrResourceNotFound. + // 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. + // we fall back to inspecting the error message here so the failure is still classified as codes.ResourceExhausted. FlavorNotFound = "error resolving flavor" ) From d805d88b3d71c60d6b8c4b37ecd1de6614560e08 Mon Sep 17 00:00:00 2001 From: viragvoros Date: Tue, 12 May 2026 10:34:58 +0200 Subject: [PATCH 4/4] add more nits --- pkg/driver/executor/errors.go | 2 +- pkg/driver/utils_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/driver/executor/errors.go b/pkg/driver/executor/errors.go index 9afca572..466d29f1 100644 --- a/pkg/driver/executor/errors.go +++ b/pkg/driver/executor/errors.go @@ -17,7 +17,7 @@ const ( 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 FlavourIDFromName (from executor.go deployServer) + // 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. diff --git a/pkg/driver/utils_test.go b/pkg/driver/utils_test.go index 100e73af..af32a1ac 100644 --- a/pkg/driver/utils_test.go +++ b/pkg/driver/utils_test.go @@ -61,7 +61,7 @@ var _ = Describe("Utils", func() { Expect(err2).To(HaveOccurred()) Expect(mapErrorToCode(err1)).To(Equal(codes.Internal)) }) - It("should map error containing executor.FlavorNotFoundto ResourceExhausted error code", func() { + 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())