-
Notifications
You must be signed in to change notification settings - Fork 13
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
Introduce acsfleetctl binary #1074
Conversation
Skipping CI for Draft Pull Request. |
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.
LGTM, looks simpler than expected. I am convinced 👍
@@ -0,0 +1,51 @@ | |||
// Package cliflags defines util methods for flags used in acsfleetctl | |||
package cliflags |
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 package: pkg/flags/flags.go
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.
I didn't use it on purpose, see the changes in comments I did for pkg/flags/flags.go
. The problem is the package glog.Fatals a lot if flags are not set. With glog.Fatal there is a problem:
It is unrecoverable because it calls ox.Exit(2) directly after logging and not panic (that's why I changed the comment), this does not allow us to intercept the exit on top level with the recover function and modify output to the output we desired for the CLI. I didn't want to change the fleet-manager serve/migrate behaviour that's why I created another cliflags package just for CLI.
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.
In this case I think we should return an error instead of os.Exit
or panic
.
What is your concern about serve
and migrate
behaviour?
I see these changes as uncritical because it is parsing CLI flags which does not crash in prod (except we messed something up pretty bad).
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.
Personally, I want this to be a panic for the CLI.
I think this makes it easier to handle errors that cause termination of the program. If a required flag is not set I want to terminate the whole program. We could do this in two ways:
- Return an error and propagate it through every function with if err != nil {return err}, than handle it at some point to terminate the application
- panic and immediately go up the stack without having to passthrough the error to the top, handle the error in recover and exit the application
IMO option 2 yields more readable/less noisy code. According to [this post](https://stackoverflow.com/questions/35412449/why-did-go-add-panic-and-recover-in-addition-to-error-handling/35413011#35413011 that's also one of the reasons panic/recover), this is why panic/recover was implemented in Go.
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.
What is your concern about serve and migrate behaviour?
No concern that can not be addressed, just don't wanted to change anything in that regards in this specific PR.
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.
I still see disadvantages for the pruposed solution and not convinced by it. The panic in the library shows its architectural weakness in two disadvantages here:
- Source code is duplicated for a panic when it could return an error instead and be supported by both libraries. It shows a leaky abstraction because the same problem is solved twice to exchange its output format (here panic & glog.Fatal). However, there could be wrapper functions to panic or glog.Fatal and the caller decides what to use.
- Deferrable recovery is more complex to read compared to an
if err != nil
because an engineer- most look into the deferred function
- keep a map in mind that there is a deferred function executed
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.
We had short call to discuss this, Outcome:
- Duplication of flags package removed
glog.Fatal
replaced bypanic
calls - CLI implementation itself stays with calling "MustGet*" function from the flags package for required flags.
b77a5f7
to
2026e5c
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.
I see similar messages twice now locally:
❯ ./acsfleetctl centrals get --debug
Error: required flag(s) "id" not set
Usage:
acsfleetctl centrals get [flags]
Flags:
-h, --help help for get
--id string Central ID (required)
Global Flags:
--debug use debug output
Error executing command: required flag(s) "id" not set%
And could not see any changes when I removed the panic recovery and no difference with the --debug
flag enabled.
❯ ./acsfleetctl centrals --debug get
Error: required flag(s) "id" not set
Usage:
acsfleetctl centrals get [flags]
Flags:
-h, --help help for get
--id string Central ID (required)
Global Flags:
--debug use debug output
Error executing command: required flag(s) "id" not set%
❯ ./acsfleetctl centrals --debug delete
@johannes94 Can you confirm this behaviour?
I can confirm, the behaviour above. I removed the second log from the code @SimonBaeumer |
2aff0a9
to
309ee90
Compare
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: johannes94, SimonBaeumer The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Description
Move the Fleet-Manager CLI to it's own binary instead of embedding it in the fleet-manager binary. Some motivating facts for this PR:
Slack thread: https://redhat-internal.slack.com/archives/C02HTD51SMD/p1685620429880799
Checklist (Definition of Done)
[ ] Unit and integration tests addedTest manual
[ ] Documentation added if necessary (i.e. changes to dev setup, test execution, ...)[ ] Add the ticket number to the PR title if available, i.e.ROX-12345: ...
[ ] Discussed security and business related topics privately. Will move any security and business related topics that arise to private communication channel.[ ] Add secret to app-interface Vault or Secrets Manager if necessary[ ] RDS changes were e2e tested manually[ ] Check AWS limits are reasonable for changes provisioning new resourcesTest manual
Run local fleet-manager and test CLI commands against it: