Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ jobs:
EXOSCALE_ZONE: ch-gva-2
run: |
cd tests/e2e
go test -v -tags=api -timeout 30m -run TestScriptsAPI
go test -v -tags=api -timeout 30m -run TestScriptsAPI 2>&1
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@

- `exo compute eip list` now shows the description & the management type of the EIP #803
- sks: add `rotate-karpenter-credentials` command #797

### Improvements

- compute instance: enrich "not found" error with the zone searched and a hint to use -z #805
- sks: add `active-nodepool-templates` command #797

### Bug fixes
Expand Down
22 changes: 22 additions & 0 deletions cmd/compute/instance/instance.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package instance

import (
"errors"
"fmt"

"github.com/exoscale/cli/cmd/compute"
v3 "github.com/exoscale/egoscale/v3"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -36,3 +40,21 @@ var instanceCmd = &cobra.Command{
func init() {
compute.ComputeCmd.AddCommand(instanceCmd)
}

// findInstance looks up an instance by name or ID from a ListInstancesResponse
// and enriches the "not found" error with the zone that was searched,
// reminding the user to use -z to target a different zone.
func findInstance(resp *v3.ListInstancesResponse, nameOrID, zone string) (v3.ListInstancesResponseInstances, error) {
instance, err := resp.FindListInstancesResponseInstances(nameOrID)
if err != nil {
if errors.Is(err, v3.ErrNotFound) {
return v3.ListInstancesResponseInstances{}, fmt.Errorf(
"instance %q not found in zone %s\nHint: use -z <zone> to specify a different zone, or run 'exo compute instance list' to see instances across all zones",
nameOrID,
zone,
)
}
return v3.ListInstancesResponseInstances{}, err
}
return instance, nil
}
2 changes: 1 addition & 1 deletion cmd/compute/instance/instance_console_url.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (c *instanceConsoleURLCmd) CmdRun(cmd *cobra.Command, _ []string) error {
return err
}

foundInstance, err := resp.FindListInstancesResponseInstances(c.Instance)
foundInstance, err := findInstance(resp, c.Instance, string(c.Zone))
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/compute/instance/instance_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (c *instanceDeleteCmd) CmdRun(_ *cobra.Command, _ []string) error {

instanceToDelete := []v3.UUID{}
for _, i := range c.Instances {
instance, err := instances.FindListInstancesResponseInstances(i)
instance, err := findInstance(instances, i, c.Zone)
if err != nil {
if !c.Force {
return err
Expand Down
4 changes: 2 additions & 2 deletions cmd/compute/instance/instance_elastic_ip_attach.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ func (c *instanceEIPAttachCmd) CmdRun(_ *cobra.Command, _ []string) error {
if err != nil {
return err
}
instance, err := instancesList.FindListInstancesResponseInstances(c.Instance)
instance, err := findInstance(instancesList, c.Instance, c.Zone)
if err != nil {
return fmt.Errorf("error retrieving Instance: %w", err)
return err
}

elasticIPs, err := client.ListElasticIPS(ctx)
Expand Down
2 changes: 1 addition & 1 deletion cmd/compute/instance/instance_elastic_ip_detach.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (c *instanceEIPDetachCmd) CmdRun(_ *cobra.Command, _ []string) error {
if err != nil {
return err
}
instance, err := instancesList.FindListInstancesResponseInstances(c.Instance)
instance, err := findInstance(instancesList, c.Instance, c.Zone)
if err != nil {
return fmt.Errorf("error retrieving Instance: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/compute/instance/instance_enable_tpm.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (c *instanceEnableTPMCmd) CmdRun(_ *cobra.Command, _ []string) error {
return err
}

instance, err := resp.FindListInstancesResponseInstances(c.Instance)
instance, err := findInstance(resp, c.Instance, string(c.Zone))
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/compute/instance/instance_private_network_attach.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (c *instancePrivnetAttachCmd) CmdRun(_ *cobra.Command, _ []string) error {
if err != nil {
return err
}
instance, err := instances.FindListInstancesResponseInstances(c.Instance)
instance, err := findInstance(instances, c.Instance, c.Zone)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/compute/instance/instance_private_network_detach.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (c *instancePrivnetDetachCmd) CmdRun(_ *cobra.Command, _ []string) error {
if err != nil {
return err
}
instance, err := instances.FindListInstancesResponseInstances(c.Instance)
instance, err := findInstance(instances, c.Instance, c.Zone)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/compute/instance/instance_private_network_updateip.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (c *instancePrivnetUpdateIPCmd) CmdRun(_ *cobra.Command, _ []string) error
if err != nil {
return err
}
instance, err := instances.FindListInstancesResponseInstances(c.Instance)
instance, err := findInstance(instances, c.Instance, c.Zone)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/compute/instance/instance_reboot.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (c *instanceRebootCmd) CmdRun(_ *cobra.Command, _ []string) error {
if err != nil {
return err
}
instance, err := instances.FindListInstancesResponseInstances(c.Instance)
instance, err := findInstance(instances, c.Instance, c.Zone)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/compute/instance/instance_reset.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (c *instanceResetCmd) CmdRun(_ *cobra.Command, _ []string) error {
if err != nil {
return err
}
instance, err := instances.FindListInstancesResponseInstances(c.Instance)
instance, err := findInstance(instances, c.Instance, c.Zone)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/compute/instance/instance_reset_password.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (c *instanceResetPasswordCmd) CmdRun(_ *cobra.Command, _ []string) error {
if err != nil {
return err
}
instance, err := instances.FindListInstancesResponseInstances(c.Instance)
instance, err := findInstance(instances, c.Instance, c.Zone)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/compute/instance/instance_resizedisk.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (c *instanceResizeDiskCmd) CmdRun(_ *cobra.Command, _ []string) error {
if err != nil {
return err
}
instance, err := instances.FindListInstancesResponseInstances(c.Instance)
instance, err := findInstance(instances, c.Instance, c.Zone)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/compute/instance/instance_reveal_password.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (c *instanceRevealCmd) CmdRun(_ *cobra.Command, _ []string) error {
if err != nil {
return err
}
instance, err := instances.FindListInstancesResponseInstances(c.Instance)
instance, err := findInstance(instances, c.Instance, c.Zone)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/compute/instance/instance_scale.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (c *instanceScaleCmd) CmdRun(_ *cobra.Command, _ []string) error {
if err != nil {
return err
}
instance, err := instances.FindListInstancesResponseInstances(c.Instance)
instance, err := findInstance(instances, c.Instance, c.Zone)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/compute/instance/instance_scp.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (c *instanceSCPCmd) CmdRun(_ *cobra.Command, _ []string) error {
if err != nil {
return err
}
instance, err := instances.FindListInstancesResponseInstances(c.Instance)
instance, err := findInstance(instances, c.Instance, c.Zone)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/compute/instance/instance_security_group_add.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (c *instanceSGAddCmd) CmdRun(cmd *cobra.Command, _ []string) error {
if err != nil {
return err
}
instance, err := instances.FindListInstancesResponseInstances(c.Instance)
instance, err := findInstance(instances, c.Instance, c.Zone)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/compute/instance/instance_security_group_remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (c *instanceSGRemoveCmd) CmdRun(cmd *cobra.Command, _ []string) error {
if err != nil {
return err
}
instance, err := instances.FindListInstancesResponseInstances(c.Instance)
instance, err := findInstance(instances, c.Instance, c.Zone)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/compute/instance/instance_show.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (c *instanceShowCmd) CmdRun(cmd *cobra.Command, _ []string) error {
return err
}

foundInstance, err := resp.FindListInstancesResponseInstances(c.Instance)
foundInstance, err := findInstance(resp, c.Instance, string(c.Zone))
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/compute/instance/instance_snapshot_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (c *instanceSnapshotCreateCmd) CmdRun(_ *cobra.Command, _ []string) error {
if err != nil {
return err
}
instance, err := instances.FindListInstancesResponseInstances(c.Instance)
instance, err := findInstance(instances, c.Instance, c.Zone)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/compute/instance/instance_snapshot_revert.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (c *instanceSnapshotRevertCmd) CmdRun(_ *cobra.Command, _ []string) error {
if err != nil {
return err
}
instance, err := instances.FindListInstancesResponseInstances(c.Instance)
instance, err := findInstance(instances, c.Instance, c.Zone)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/compute/instance/instance_ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (c *instanceSSHCmd) CmdRun(_ *cobra.Command, _ []string) error {
if err != nil {
return err
}
instance, err := instances.FindListInstancesResponseInstances(c.Instance)
instance, err := findInstance(instances, c.Instance, c.Zone)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/compute/instance/instance_start.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (c *instanceStartCmd) CmdRun(_ *cobra.Command, _ []string) error {
if err != nil {
return err
}
instance, err := instances.FindListInstancesResponseInstances(c.Instance)
instance, err := findInstance(instances, c.Instance, c.Zone)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/compute/instance/instance_stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (c *instanceStopCmd) CmdRun(_ *cobra.Command, _ []string) error {
if err != nil {
return err
}
instance, err := instances.FindListInstancesResponseInstances(c.Instance)
instance, err := findInstance(instances, c.Instance, c.Zone)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/compute/instance/instance_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (c *instanceUpdateCmd) CmdRun(cmd *cobra.Command, _ []string) error {
if err != nil {
return err
}
instance, err := instances.FindListInstancesResponseInstances(c.Instance)
instance, err := findInstance(instances, c.Instance, c.Zone)
if err != nil {
return err
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Test: exo compute instance <action> returns enriched error when instance not found
# Verifies that when an instance lookup fails, the error message includes the zone
# that was searched and a hint to use -z.
# No resources are created so no teardown is required.
# TEST_ZONE is injected by the API test runner.

# show: instance not found should mention zone and hint
! exec exo --output-format json compute instance show nonexistent-e2e-instance
stderr 'not found in zone'
stderr 'Hint: use -z'

# reboot: same helper, same enriched error
! exec exo --output-format json compute instance reboot --force nonexistent-e2e-instance
stderr 'not found in zone'
stderr 'Hint: use -z'

# stop: same helper, same enriched error
! exec exo --output-format json compute instance stop --force nonexistent-e2e-instance
stderr 'not found in zone'
stderr 'Hint: use -z'
Loading
Loading