-
Notifications
You must be signed in to change notification settings - Fork 19
cmd/rofl/machine: Support provider:machine-id directly #680
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
base: master
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for oasisprotocol-cli canceled.
|
3c5a323 to
61b5349
Compare
61b5349 to
59fa883
Compare
59fa883 to
8d48aed
Compare
peternose
left a comment
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.
Looks like these changes should work, but I did not test them. The code (previous and changes) is quite complicated and could be improved.
| ) | ||
|
|
||
| func resolveMachine(args []string, deployment *buildRofl.Deployment) (*buildRofl.Machine, string, roflmarket.InstanceID) { | ||
| func resolveMachineManifestNpa(args []string, manifestOpts *roflCommon.ManifestOptions) (machineCfg *buildRofl.Machine, machineName string, machineID roflmarket.InstanceID, manifest *buildRofl.Manifest, extraCfg *roflCmdBuild.AppExtraConfig, providerAddr *types.Address, npa *common.NPASelection) { |
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.
Few remarks:
- Returned data should be collected in a struct, as Go methods should return at most 2 values.
- The returned values should also not be named, unless this is needed because of
deferstatement or to explain what the function returns. - The code is very complicated, and should be changed in such a way that you a) get npa b) resolve machine from args or manifest c) resolve provider address.
| Aliases: []string{"cancel", "rm"}, | ||
| Args: cobra.MaximumNArgs(1), | ||
| Run: func(_ *cobra.Command, args []string) { | ||
| txCfg := common.GetTransactionConfig() |
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 could be done in change-admin.
| return machineCfg, machineName, machineID, manifest, extraCfg, providerAddr, npa | ||
| } | ||
|
|
||
| func resolveMachineFromArgs(args []string) (*buildRofl.Machine, string, roflmarket.InstanceID) { |
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.
If function optionally returns values, it should return two values, the second one being bool, e.g. func resolve() (*mystruct, bool).
Also, happy path should not be indented.
if len(args) == 0
...
if len(parts) != 2
...|
|
||
| if err = manifest.Save(); err != nil { | ||
| cobra.CheckErr(fmt.Errorf("failed to update manifest: %w", err)) | ||
| if manifest != nil { |
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.
This complicates everything. Since helper function can return nil manifest, I would expect it could also return nil for other values. So I would expect these kind of checks for all values. Therefore, I don't allow returning nil values, and if I do, the function returns also bool to indicate whether the value is nil.
This PR adds support for addressing ROFL machines directly using
provider-address:machine-idsyntax. This enables showing machine info, removing it, topping it up, changing admin, showing logs without needingrofl.yamlmanifest.Useful for automation. Related #677 .