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 additional error codes for invalid reservations to GCE client #6093

Merged
merged 1 commit into from
Sep 11, 2023
Merged
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
27 changes: 18 additions & 9 deletions cluster-autoscaler/cloudprovider/gce/autoscaling_gce_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,22 @@ const (
ErrorCodeOther = "OTHER"
)

var (
regexReservationErrors = []*regexp.Regexp{
regexp.MustCompile("Incompatible AggregateReservation VMFamily"),
regexp.MustCompile("Could not find the given reservation with the following name"),
regexp.MustCompile("must use ReservationAffinity of"),
regexp.MustCompile("The reservation must exist in the same project as the instance"),
regexp.MustCompile("only compatible with Aggregate Reservations"),
regexp.MustCompile("Please target a reservation with workload_type ="),
regexp.MustCompile("AggregateReservation VMFamily: should be a (.*) VM Family for instance with (.*) machine type"),
regexp.MustCompile("VM Family: (.*) is not supported for aggregate reservations. It must be one of"),
regexp.MustCompile("Reservation (.*) is incorrect for the requested resources"),
regexp.MustCompile("Zone does not currently have sufficient capacity for the requested resources"),
regexp.MustCompile("Reservation (.*) does not have sufficient capacity for the requested resources."),
}
)

// AutoscalingGceClient is used for communicating with GCE API.
type AutoscalingGceClient interface {
// reading resources
Expand Down Expand Up @@ -453,15 +469,8 @@ func isReservationNotReady(errorCode, errorMessage string) bool {
}

func isInvalidReservationError(errorCode, errorMessage string) bool {
reservationErrors := []string{
"Incompatible AggregateReservation VMFamily",
"Could not find the given reservation with the following name",
"must use ReservationAffinity of",
"The reservation must exist in the same project as the instance",
"only compatible with Aggregate Reservations",
}
for _, rErr := range reservationErrors {
if strings.Contains(errorMessage, rErr) {
for _, re := range regexReservationErrors {
if re.MatchString(errorMessage) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm concerned that this change will make the matching more restrictive.
Old checkers uses a contains logic, wheres now we're doing a full-match (I think).
This could potentially break existing logic where we would have stacktrace to the errorMessage?

Can we explore if we can do a regex contains?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will work: in order to do a full match you'd have to include ^ and $ in the regex string. It's not anchored by default.

return true
}
}
Expand Down