aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/gce
diff options
context:
space:
mode:
authorTaras Madan <tarasmadan@google.com>2023-07-21 11:51:35 +0200
committerTaras Madan <tarasmadan@google.com>2023-07-24 09:12:13 +0000
commita36fe24b8383f6cd9b3519cd3eabdb9675d8992d (patch)
tree3fef9a57760ccc4013289acd60e94e083db466e6 /pkg/gce
parent7549a7e1b57831cf6b08ce4700fc6e53417919f9 (diff)
all: use errors.As instead of .(type)
Diffstat (limited to 'pkg/gce')
-rw-r--r--pkg/gce/gce.go10
1 files changed, 7 insertions, 3 deletions
diff --git a/pkg/gce/gce.go b/pkg/gce/gce.go
index 71b88e2ec..ecc2c9853 100644
--- a/pkg/gce/gce.go
+++ b/pkg/gce/gce.go
@@ -12,6 +12,7 @@
package gce
import (
+ "errors"
"fmt"
"io"
"math/rand"
@@ -170,7 +171,8 @@ retry:
return "", fmt.Errorf("failed to create instance: %w", err)
}
if err := ctx.waitForCompletion("zone", "create image", op.Name, false); err != nil {
- if _, ok := err.(resourcePoolExhaustedError); ok && instance.Scheduling.Preemptible {
+ var resourcePoolExhaustedError resourcePoolExhaustedError
+ if errors.As(err, &resourcePoolExhaustedError) && instance.Scheduling.Preemptible {
instance.Scheduling.Preemptible = false
goto retry
}
@@ -206,7 +208,8 @@ func (ctx *Context) DeleteInstance(name string, wait bool) error {
op, err = ctx.computeService.Instances.Delete(ctx.ProjectID, ctx.ZoneID, name).Do()
return
})
- if apiErr, ok := err.(*googleapi.Error); ok && apiErr.Code == 404 {
+ var apiErr *googleapi.Error
+ if errors.As(err, &apiErr) && apiErr.Code == 404 {
return nil
}
if err != nil {
@@ -270,7 +273,8 @@ func (ctx *Context) DeleteImage(imageName string) error {
op, err = ctx.computeService.Images.Delete(ctx.ProjectID, imageName).Do()
return
})
- if apiErr, ok := err.(*googleapi.Error); ok && apiErr.Code == 404 {
+ var apiErr *googleapi.Error
+ if errors.As(err, &apiErr) && apiErr.Code == 404 {
return nil
}
if err != nil {