Skip to content

Commit bb74bd1

Browse files
authored
security-group show: fix empty response if an API endpoint is misbehaving (#660)
# Description <!-- * Prefix: the title with the component name being changed. Add a short and self describing sentence to ease the review * Please add a few lines providing context and describing the change * Please self comment changes whenever applicable to help with the review process * Please keep the checklist as part of the PR. Tick what applies to this change. --> `exo compute security-group show` iterates through all zones to retrieve instances associated with it. If a single API endpoint happened to throw an error, the call itself would error out. This fix allows showing that security group while still showing an error ## Checklist (For exoscale contributors) * [x] Changelog updated (under *Unreleased* block) * [x] Testing ## Testing <!-- Describe the tests you did --> ``` ➜ ~/exo/cli git:(tgrondier/sc-114869/exo-c-sh-show-error-in-preprod) ✗ go run . c sg show edc0d129-2f94-4531-920e-7cf798439cd3 25-01-06 16:40 error while listing instances in security group: 1 error occurred: * Get "https://ppapi-at-vie-2.exoscale.com/v2/instance": dial tcp: lookup ppapi-at-vie-2.exoscale.com on 127.0.0.53:53: server misbehaving ┼──────────────────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼ │ SECURITY GROUP │ │ ┼──────────────────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼ │ ID │ edc0d129-2f94-4531-920e-7cf798439cd3 │ │ Name │ default │ │ Description │ Default Security Group │ │ Ingress Rules │ │ │ │ 08798387-0c7d-4601-a5ed-93367b889314 TCP 0.0.0.0/0 22 │ │ │ │ │ Egress Rules │ - │ │ External Sources │ - │ │ Instances │ │ │ │ VM-ec365352-f303-4fac-9cad-26e4a63b2227 ec365352-f303-4fac-9cad-26e4a63b2227 159.100.241.234 ch-gva-2 │ │ │ VM-79e75e58-34c8-4f99-8168-e37722eb97cc 79e75e58-34c8-4f99-8168-e37722eb97cc 85.217.161.242 ch-gva-2 │ │ │ VM-33e1fdda-d1d4-4fbd-8c7a-4e49971e3975 33e1fdda-d1d4-4fbd-8c7a-4e49971e3975 85.217.161.235 ch-gva-2 │ │ │ │ ┼──────────────────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼ ```
1 parent 9bae8be commit bb74bd1

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
- instance update: fixing no err check after creating client #657
1313
- fix(error): Improve error message on snapshot creation (#655)
14+
- security-group show: fix empty response if an API endpoint is misbehaving #660
1415

1516
## 1.82.0
1617

utils/utils.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"crypto/rand"
66
"encoding/base64"
7+
"errors"
78
"fmt"
89
"net"
910
"strconv"
@@ -49,15 +50,21 @@ func GetInstancesInSecurityGroup(ctx context.Context, client *v2.Client, securit
4950

5051
instances, err := client.ListInstances(ctx, zone)
5152
if err != nil {
52-
return err
53+
if !errors.Is(err, exoapi.ErrNotFound) {
54+
return err
55+
}
56+
} else {
57+
allInstances = append(allInstances, instances...)
5358
}
5459

55-
allInstances = append(allInstances, instances...)
56-
5760
return nil
5861
})
5962
if err != nil {
60-
return nil, err
63+
if allInstances == nil {
64+
return nil, err
65+
} else {
66+
fmt.Printf("error while listing instances in security group: %s", err)
67+
}
6168
}
6269

6370
var instancesInSG []*v2.Instance

0 commit comments

Comments
 (0)