From 5d3c3ad5f5fc549e33457aa4631022a9df029dbc Mon Sep 17 00:00:00 2001 From: Olivier Cano Date: Fri, 17 Apr 2020 11:36:05 +0200 Subject: [PATCH] fix(instance): list image with image from not found server (#854) --- go.mod | 2 +- go.sum | 2 ++ .../namespaces/instance/v1/custom_image.go | 30 +++++++++++-------- ...ors-error-invalid-image-uuid.stderr.golden | 4 +-- ...alid,-but-non-existing-pg-id.stderr.golden | 2 +- ...e-attach-invalid-volume-uuid.stderr.golden | 2 +- ...e-detach-invalid-volume-uuid.stderr.golden | 2 +- 7 files changed, 26 insertions(+), 18 deletions(-) diff --git a/go.mod b/go.mod index f3209fc9bd..949c63a386 100644 --- a/go.mod +++ b/go.mod @@ -20,7 +20,7 @@ require ( github.com/mattn/go-colorable v0.1.4 github.com/mattn/go-isatty v0.0.11 github.com/pkg/errors v0.9.1 // indirect - github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6.0.20200409105057-297e3dbdccb5 + github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6.0.20200414183251-a6244a393e63 github.com/sergi/go-diff v1.0.0 // indirect github.com/spf13/cobra v0.0.5 github.com/spf13/pflag v1.0.5 // indirect diff --git a/go.sum b/go.sum index 920eddea66..86c8d9fe07 100644 --- a/go.sum +++ b/go.sum @@ -67,6 +67,8 @@ github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6.0.20200403173805-25a10631420d github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6.0.20200403173805-25a10631420d/go.mod h1:CJJ5VAbozOl0yEw7nHB9+7BXTJbIn6h7W+f6Gau5IP8= github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6.0.20200409105057-297e3dbdccb5 h1:QmrgbtSAIDKRTnzAjdpop3yFAqHFO4MEc8W+/0Epu88= github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6.0.20200409105057-297e3dbdccb5/go.mod h1:CJJ5VAbozOl0yEw7nHB9+7BXTJbIn6h7W+f6Gau5IP8= +github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6.0.20200414183251-a6244a393e63 h1:8tRzNwnY+PK6TD21bvKU0p334p+kApiKdHRO3xsZgpg= +github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6.0.20200414183251-a6244a393e63/go.mod h1:CJJ5VAbozOl0yEw7nHB9+7BXTJbIn6h7W+f6Gau5IP8= github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ= github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= diff --git a/internal/namespaces/instance/v1/custom_image.go b/internal/namespaces/instance/v1/custom_image.go index 73e1602176..70a533ec05 100644 --- a/internal/namespaces/instance/v1/custom_image.go +++ b/internal/namespaces/instance/v1/custom_image.go @@ -127,20 +127,26 @@ func imageListBuilder(c *core.Command) *core.Command { State: image.State, Zone: image.Zone, } + customImages = append(customImages, newCustomImage) - if image.FromServer != "" { - serverReq := instance.GetServerRequest{ - Zone: req.Zone, - ServerID: image.FromServer, - } - getServerResponse, err := api.GetServer(&serverReq) - if err != nil { - return nil, err - } - newCustomImage.ServerID = getServerResponse.Server.ID - newCustomImage.ServerName = getServerResponse.Server.Name + if image.FromServer == "" { + continue } - customImages = append(customImages, newCustomImage) + + serverReq := instance.GetServerRequest{ + Zone: req.Zone, + ServerID: image.FromServer, + } + getServerResponse, err := api.GetServer(&serverReq) + if _, ok := err.(*scw.ResourceNotFoundError); ok { + newCustomImage.ServerName = "-" + continue + } + if err != nil { + return nil, err + } + newCustomImage.ServerID = getServerResponse.Server.ID + newCustomImage.ServerName = getServerResponse.Server.Name } return customImages, nil diff --git a/internal/namespaces/instance/v1/testdata/test-create-server-errors-error-invalid-image-uuid.stderr.golden b/internal/namespaces/instance/v1/testdata/test-create-server-errors-error-invalid-image-uuid.stderr.golden index 0498fbd4fc..91cf81d344 100644 --- a/internal/namespaces/instance/v1/testdata/test-create-server-errors-error-invalid-image-uuid.stderr.golden +++ b/internal/namespaces/instance/v1/testdata/test-create-server-errors-error-invalid-image-uuid.stderr.golden @@ -1,3 +1,3 @@ -WARNING: 2019/12/09 16:04:07 cannot get image 7a892c1a-bbdc-491f-9974-4008e3708664: scaleway-sdk-go: http error 404 Not Found: "7a892c1a-bbdc-491f-9974-4008e3708664" not found +WARNING: 2019/12/09 16:04:07 cannot get image 7a892c1a-bbdc-491f-9974-4008e3708664: scaleway-sdk-go: resource with ID 7a892c1a-bbdc-491f-9974-4008e3708664 is not found WARNING: 2019/12/09 16:04:07 skipping image server-type compatibility validation -Cannot create the server: scaleway-sdk-go: http error 404 Not Found: "7a892c1a-bbdc-491f-9974-4008e3708664" not found +Cannot create the server: scaleway-sdk-go: resource with ID 7a892c1a-bbdc-491f-9974-4008e3708664 is not found diff --git a/internal/namespaces/instance/v1/testdata/test-server-update-no-initial-placement-group&-placement-group-id=valid,-but-non-existing-pg-id.stderr.golden b/internal/namespaces/instance/v1/testdata/test-server-update-no-initial-placement-group&-placement-group-id=valid,-but-non-existing-pg-id.stderr.golden index 503f45c26c..71e5bb0e4d 100644 --- a/internal/namespaces/instance/v1/testdata/test-server-update-no-initial-placement-group&-placement-group-id=valid,-but-non-existing-pg-id.stderr.golden +++ b/internal/namespaces/instance/v1/testdata/test-server-update-no-initial-placement-group&-placement-group-id=valid,-but-non-existing-pg-id.stderr.golden @@ -1 +1 @@ -"11111111-1111-1111-1111-111111111111" not found +Cannot find resource '' with ID '11111111-1111-1111-1111-111111111111' diff --git a/internal/namespaces/instance/v1/testdata/test-server-volume-update-attach-invalid-volume-uuid.stderr.golden b/internal/namespaces/instance/v1/testdata/test-server-volume-update-attach-invalid-volume-uuid.stderr.golden index 503f45c26c..71e5bb0e4d 100644 --- a/internal/namespaces/instance/v1/testdata/test-server-volume-update-attach-invalid-volume-uuid.stderr.golden +++ b/internal/namespaces/instance/v1/testdata/test-server-volume-update-attach-invalid-volume-uuid.stderr.golden @@ -1 +1 @@ -"11111111-1111-1111-1111-111111111111" not found +Cannot find resource '' with ID '11111111-1111-1111-1111-111111111111' diff --git a/internal/namespaces/instance/v1/testdata/test-server-volume-update-detach-invalid-volume-uuid.stderr.golden b/internal/namespaces/instance/v1/testdata/test-server-volume-update-detach-invalid-volume-uuid.stderr.golden index 503f45c26c..71e5bb0e4d 100644 --- a/internal/namespaces/instance/v1/testdata/test-server-volume-update-detach-invalid-volume-uuid.stderr.golden +++ b/internal/namespaces/instance/v1/testdata/test-server-volume-update-detach-invalid-volume-uuid.stderr.golden @@ -1 +1 @@ -"11111111-1111-1111-1111-111111111111" not found +Cannot find resource '' with ID '11111111-1111-1111-1111-111111111111'