Skip to content

Commit

Permalink
security-group show: fix empty response if an API endpoint is misbeha…
Browse files Browse the repository at this point in the history
…ving (#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   │
│                  │                                                                                                                 │
┼──────────────────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼

```
  • Loading branch information
tgrondier authored Jan 9, 2025
1 parent 9bae8be commit bb74bd1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

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

## 1.82.0

Expand Down
15 changes: 11 additions & 4 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"crypto/rand"
"encoding/base64"
"errors"
"fmt"
"net"
"strconv"
Expand Down Expand Up @@ -49,15 +50,21 @@ func GetInstancesInSecurityGroup(ctx context.Context, client *v2.Client, securit

instances, err := client.ListInstances(ctx, zone)
if err != nil {
return err
if !errors.Is(err, exoapi.ErrNotFound) {
return err
}
} else {
allInstances = append(allInstances, instances...)
}

allInstances = append(allInstances, instances...)

return nil
})
if err != nil {
return nil, err
if allInstances == nil {
return nil, err
} else {
fmt.Printf("error while listing instances in security group: %s", err)
}
}

var instancesInSG []*v2.Instance
Expand Down

0 comments on commit bb74bd1

Please sign in to comment.