Skip to content
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

Avoid leaving unclean state when using gscloud-server-create #97

Closed
bkircher opened this issue Nov 29, 2020 · 3 comments
Closed

Avoid leaving unclean state when using gscloud-server-create #97

bkircher opened this issue Nov 29, 2020 · 3 comments
Assignees
Labels
bug Something isn't working help wanted Extra attention is needed
Milestone

Comments

@bkircher
Copy link
Contributor

When server create fails somewhere in the middle of the whole thing it leaves objects behind that have already been created. This is unlike the panel which always cleans up nicely.

Panel uses POST /batch with

{
    "sub_calls": {
        "sub_calls": [
            {
                "call_type": "servers_post",
                "name": "ser1",
                "payload": {
                    "auto_recovery": true,
                    "availability_zone": null,
                    "cores": 1,
                    "hardware_profile": "q35",
                    "location_uuid": "8328a5bc-e66e-4edc-8aae-2e2bf07fdb28",
                    "memory": 1,
                    "name": "test-1"
                }
            },
            {
                "call_type": "storages_post",
                "name": "sto1",
                "payload": {
                    "capacity": 10,
                    "location_uuid": "8328a5bc-e66e-4edc-8aae-2e2bf07fdb28",
                    "name": "test-1",
                    "storage_type": "storage",
                    "template": {
                        "hostname": "test-1",
                        "password": "mysecret",
                        "password_type": "plain",
                        "template_uuid": "8d1bb5dc-7c37-4c90-8529-d2aaac75d812"
                    }
                }
            },
            {
                "call_type": "servers_storages_post",
                "name": "sto_x_ser",
                "payload": {
                    "bootdevice": true,
                    "server_uuid": "${SER1:SERVER_UUID}",
                    "storage_uuid": "${STO1:STORAGE_UUID}"
                }
            }
        ]
    }
}

to create a server. Not in API docs. You can observe this kind of behavior when user forgets to set --password in gscloud-server-create: new server object will be left while storage creation fails.

Ideas?

@bkircher bkircher added bug Something isn't working help wanted Extra attention is needed labels Nov 29, 2020
@bkircher
Copy link
Contributor Author

bkircher commented Dec 3, 2020

We started work here on this branch in gsclient-go: https://github.com/gridscale/gsclient-go/tree/batch

@bkircher bkircher added this to the v0.8.0 milestone Jan 10, 2021
@bkircher
Copy link
Contributor Author

bkircher commented Feb 4, 2021

/batch API won't be supported by gsclient-go (gridscale/gsclient-go#176) So we have to come up with something here on the client side.

Something with defer that gets cancelled on the success path. Shouldn't be too hard.

@nvthongswansea
Copy link
Member

@bkircher if you take a look at the "example" directory in gsclient-go package, you will see how to clean stuffs when there are errors during a process.

bkircher added a commit that referenced this issue Feb 7, 2021
Do not use os.Exit directly (or indirectly through log.Fatal or other
helper functions) anymore.

Motivation: we need to clean up resources in error cases (see
#97). os.Exit makes the
program terminate immediately and deferred functions are not run. This
makes it impossible to use defer for cleaning up real resources when we
need to bail out.

This commit replaces all Run functions with RunE, returning errors from
now on in subcommands instead of exiting the process immediately. Other
functions use panic for errors that shouldn't actually happen.

This commit also introduces cmd.Error as a custom error type. It
contains a What message that should explain to the user what went wrong
and an Err error with all the details (probably from the API).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants