-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
instance: add a protection flag to exo compute #608
instance: add a protection flag to exo compute #608
Conversation
cmd/instance_update.go
Outdated
if err != nil { | ||
return | ||
} | ||
op, err = globalstate.EgoscaleV3Client.Wait(ctx, op, egoscale3.OperationStateSuccess) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
op, err = globalstate.EgoscaleV3Client.Wait(ctx, op, egoscale3.OperationStateSuccess) | |
_, err = globalstate.EgoscaleV3Client.Wait(ctx, op, egoscale3.OperationStateSuccess) |
Go doesn't allow you to create unused variables. You have to assign to _
if you would like to discard a returned value.
cmd/instance_create.go
Outdated
if err != nil { | ||
return | ||
} | ||
op, err = globalstate.EgoscaleV3Client.Wait(ctx, op, egoscale3.OperationStateSuccess) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same issue here as below :)
@@ -25,6 +26,7 @@ type instanceUpdateCmd struct { | |||
CloudInitCompress bool `cli-flag:"cloud-init-compress" cli-usage:"compress instance cloud-init user data"` | |||
Labels map[string]string `cli-flag:"label" cli-usage:"instance label (format: key=value)"` | |||
Name string `cli-short:"n" cli-usage:"instance name"` | |||
Protection bool `cli-flag:"protection" cli-usage:"enable delete protection"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately one flag is not enough here, you'll need to create two flags --add-protection
and --remove-protection
.
The problem with your current implementation, is that it always removes the instance protection whenever you run an update command without the --protection
flag. That's not ideal, users should have to set --remove-protection
explicitly to do that. When the user doesn't set a protection flag, nothing related to delete protection should happen.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a bug there for sure, but we don't need a second flag.
We can use --protection=false
for removing delete protection (same how we manage DBaaS --termination-protection
).
There is function to check if flag was specified at all (see here).
here is the output of the testing: ./exo compute instance update 3e8d4838-48a7-40f5-ae5d-c01d39567d22 --protection=false
┼──────────────────────┼──────────────────────────────────────┼
│ COMPUTE INSTANCE │ │
┼──────────────────────┼──────────────────────────────────────┼
│ ID │ 3e8d4838-48a7-40f5-ae5d-c01d39567d22 │
│ Name │ test-instance │
│ Creation Date │ 2024-08-09 15:27:50 +0000 UTC │
│ Instance Type │ standard.medium │
│ Template │ Linux Ubuntu 22.04 LTS 64-bit │
│ Zone │ at-vie-1 │
│ Anti-Affinity Groups │ n/a │
│ Deploy Target │ - │
│ Security Groups │ default │
│ Private Instance │ No │
│ Private Networks │ n/a │
│ Elastic IPs │ n/a │
│ IP Address │ 185.150.10.107 │
│ IPv6 Address │ - │
│ SSH Key │ - │
│ Disk Size │ 50 GiB │
│ State │ running │
│ Labels │ n/a │
│ Reverse DNS │ │
┼──────────────────────┼──────────────────────────────────────┼
❯ ./exo compute instance delete 3e8d4838-48a7-40f5-ae5d-c01d39567d22
[+] Are you sure you want to delete instance "3e8d4838-48a7-40f5-ae5d-c01d39567d22"? [yN]: y
✔ Deleting instance "3e8d4838-48a7-40f5-ae5d-c01d39567d22"... 0s
error: Delete "https://api-at-vie-1.exoscale.com/v2/instance/3e8d4838-48a7-40f5-ae5d-c01d39567d22": invalid request: Operation delete-instance on resource 3e8d4838-48a7-40f5-ae5d-c01d39567d22 is forbidden - reason: manual instance protection
❯ go run . compute instance delete 3e8d4838-48a7-40f5-ae5d-c01d39567d22
[+] Are you sure you want to delete instance "3e8d4838-48a7-40f5-ae5d-c01d39567d22"? [yN]: y
✔ Deleting instance "3e8d4838-48a7-40f5-ae5d-c01d39567d22"... 0s
error: Delete "https://api-at-vie-1.exoscale.com/v2/instance/3e8d4838-48a7-40f5-ae5d-c01d39567d22": invalid request: Operation delete-instance on resource 3e8d4838-48a7-40f5-ae5d-c01d39567d22 is forbidden - reason: manual instance protection
exit status 1
❯ go run . compute instance update 3e8d4838-48a7-40f5-ae5d-c01d39567d22 --protection=false
✔ Updating instance "3e8d4838-48a7-40f5-ae5d-c01d39567d22"... 0s
┼──────────────────────┼──────────────────────────────────────┼
│ COMPUTE INSTANCE │ │
┼──────────────────────┼──────────────────────────────────────┼
│ ID │ 3e8d4838-48a7-40f5-ae5d-c01d39567d22 │
│ Name │ test-instance │
│ Creation Date │ 2024-08-09 15:27:50 +0000 UTC │
│ Instance Type │ standard.medium │
│ Template │ Linux Ubuntu 22.04 LTS 64-bit │
│ Zone │ at-vie-1 │
│ Anti-Affinity Groups │ n/a │
│ Deploy Target │ - │
│ Security Groups │ default │
│ Private Instance │ No │
│ Private Networks │ n/a │
│ Elastic IPs │ n/a │
│ IP Address │ 185.150.10.107 │
│ IPv6 Address │ - │
│ SSH Key │ - │
│ Disk Size │ 50 GiB │
│ State │ running │
│ Labels │ n/a │
│ Reverse DNS │ │
┼──────────────────────┼──────────────────────────────────────┼
❯ go run . compute instance delete 3e8d4838-48a7-40f5-ae5d-c01d39567d22
[+] Are you sure you want to delete instance "3e8d4838-48a7-40f5-ae5d-c01d39567d22"? [yN]: y
✔ Deleting instance "3e8d4838-48a7-40f5-ae5d-c01d39567d22"... 6s |
@elkezza I renamed this PR, please try to use a similar format when naming your PRs. |
LTGM, I tested it on my side as well and it works. Please rebase your branch to resolve the conflicts, then I'll approve. Thanks! |
86c610b
to
8794f48
Compare
6a472a0
to
97dceda
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you need to rebase again to fix the changelog conflict. It's not your mistake, the problem will disappear when we generate the changelog automatically.
…hich is once the protection flag is set.
541c382
to
21f2507
Compare
ack, thanks for the feedback! |
Description
added add/remove a protection flag to exo compute, however it did not work as expected
Checklist
(For exoscale contributors)
Testing
I tested the cli after the changes locally but the protection flag does not work.