make it easier to use garm-cli pool create
trying to create a new pool for a given repo we currently have to use the repo id, which is somewhat cumbersome, because there is no apparent way to get the repo id from a name. we have to use garm-cli repo list and manually parse the id from the output, which is quite cumbersome and error prone.
for example, trying this:
./garm-cli pool create \
--enabled true \
--min-idle-runners 0 \
--max-runners 2 \
--tags azure,ubuntu \
--repo terraform-azure-garm-example-repository \
--provider-name azure \
--os-arch amd64 \
--os-type linux \
--flavor Standard_F8s \
--image Canonical:0001-com-ubuntu-server-jammy:22_04-lts-gen2:22.04.202206040
resulted in cryptic garm-cli error:
Error: [POST /repositories/{repoID}/pools][500] CreateRepoPool default {"error":"Server error","details":""}
and looking at the garm logs we have another cryptic error:
time=2024-09-22T06:50:42.131Z level=ERROR msg="error creating repository pool" error="failed to create pool: parsing id: invalid request"
can these errors be somehow improved?
can there be an easier way for creating pools? or maybe, to list repos as json (and to find repos by their properties (e.g. name))?
Yes to most of the questions, "maybe" to referencing repo by name.
The reason for that is that garm supports ghes and github. There is the slim (but still possible) chance that you may have the same owner and repo combination in both and both are configured in garm.
There is a way to do this with an extra query. Given that it's a pain in the behind to keep copying that ID, it may be worth adding.
Will create a pr next week as time permits.
Added a --format option to the CLI:
- https://github.com/cloudbase/garm/pull/298
as for referencing by name, I will try to create a PR for that as well. Repos actually have 2 components. The owner and the name of the repo. You and I can both have a repo with the same name. So to identify a repo, we'd need to specify something like gabriel-samfira/garm. Orgs and enterprises are made up of just the name.
In the case of the cryptic error, that's indeed a problem. It shouldn't be a 500 error. I need to go through the code and make sure that errors.Wrap() is used instead of fmt.Errorf(). At least until we have a chance to migrate to the standard package.
This was started here:
- https://github.com/cloudbase/garm/pull/299
Will go through the rest of the files in the following days.
I merged https://github.com/cloudbase/garm/pull/432, which adds the ability to use friendly names when creating/listing pools as well as for other sub-commands of garm-cli. There is an asciinema video in the linked PR that shows the new behavior.
I will keep this issue open, as I still need to find and replace all errors.Wrap().
finally got around to replacing errors.Wrap() in: https://github.com/cloudbase/garm/pull/482
Closing, as that was the last main issue. We can still improve on the error message returned by the API, but we should see a lot fewer 500 errors, and instead we should see proper errors.