diff --git a/cloud-functions/common/common.go b/cloud-functions/common/common.go index 0d08f8ed..a0b1a461 100644 --- a/cloud-functions/common/common.go +++ b/cloud-functions/common/common.go @@ -3,6 +3,7 @@ package common import ( "context" "encoding/json" + "errors" "fmt" "math/rand" "strconv" @@ -416,11 +417,12 @@ func GetInstancesByLabel(ctx context.Context, project, zone, labelKey, labelValu listInstanceIter := instanceClient.List(ctx, listInstanceRequest) for { - resp, err := listInstanceIter.Next() - if err == iterator.Done { + resp, err2 := listInstanceIter.Next() + if errors.Is(err2, iterator.Done) { break } - if err != nil { + if err2 != nil { + err = fmt.Errorf("error getting next instances by label: %w", err2) log.Error().Err(err).Send() break } diff --git a/cloud-functions/main.go b/cloud-functions/main.go index 76b8badb..553ccc47 100644 --- a/cloud-functions/main.go +++ b/cloud-functions/main.go @@ -412,7 +412,9 @@ func ScaleUp(w http.ResponseWriter, r *http.Request) { err = fmt.Errorf("failed getting instances by cluster label: %w", err) log.Error().Err(err).Send() respondWithErr(w, err, http.StatusBadRequest) + return } + backendsNumber := len(backends) log.Info().Msgf("Number of backends is: %d", backendsNumber)