-
Notifications
You must be signed in to change notification settings - Fork 0
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
CLI Unification: Root Command #917
Conversation
* unify config command * unified config file, IsCloud and IsOnPrem * consolidate ccloud hostnames var * finish config unification and test * add golden files * check for test url second * add back missing return * support all cpdev platforms * trim trailing slash from platform names, and use contains * revert trim trailing slash * fix error
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 awesome !
// TODO: Remove once unification is complete | ||
cliName := "confluent" | ||
if cfg.IsCloud() { | ||
cliName = "ccloud" |
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.
is this meant to be deleted?
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.
Yes, the config file is loaded in the main function now. The CLI needs a correctly formatted config file in order to work, since it shows a certain subset of commands based on the contents of the config file.
isTest = "false" | ||
) | ||
|
||
func main() { | ||
viper.AutomaticEnv() | ||
cfg, err := cmd.LoadConfig() |
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.
do we need to fail immediately because you need the config to tell if it's ccloud or confluent?
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 forget if that was a field added to the config .. or if you're just parsing the url from the context name but either way
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.
Yep exactly. We're using the --url
flag to determine whether we should log in to cloud or on-prem, and then once we log in and the context gets stored, we use the current context's platform name (a config field) to decide between cloud and on-prem
@@ -44,7 +45,6 @@ const DoNotTrack = "do-not-track-analytics" | |||
// PreRun is the standard PreRunner implementation | |||
type PreRun struct { | |||
Config *v3.Config | |||
ConfigLoadingError error |
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.
the part of me that doesn't love how coupled the CLI is with the config wants to keep this (i.e. not fail immediately on config load err) ... i.e. confluent kafka topic list
could work if you have the login env vars set and passed a --cluster and --environment value
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.
Oh interesting... didn't know that was a thing you could do. I'll have to think about this some more but I wonder if that's something we want people to be able to do in the first place; like, why can kafka
commands bypass the login
command, but not other commands.
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.
Ok, I've thought about this a bit and I want to make a proper config a hard requirement. If a user changed their config file somehow and it broke, they would see a limited subset of the commands and get no help with how to fix it.
For example, if a user had the intention of using the CLI for listing their Kafka clusters, and the kafka
command wasn't showing up (even though they thought they had a working config file) they'd be very confused.
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 think this makes sense .. and i don't think we've seen any customer feedback around not wanting a config file but cc: @DABH since we've discussed not requiring a config file
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.
@DABH the tldr is that the config is now a hard requirement (fail immediately if it doesn't load) since the config is needed to determine whether the user is logged into ccloud or on-prem
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.
Just want to clarify that if there's no config, then it shows the default set of commands that don't require authentication (login
, logout
, completion
, config
, help
, local
, update
, version
).
It only fails if the config exists and is broken in some way.
The only thing this doesn't support (and maybe should?) is running the commands mentioned above with a broken config. Although... a bunch of the commands listed above read from or write to the config (config
, login
, logout
, update
), so they would fail anyway.
At the end of the day, it looks like the only (useful) functionality changing this would enable is being able to run completion
, help
, local
, and version
with a broken config.
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 actually think we would like to be able to run without a config file. The use case is multiple instances of the CLI being used on the same machine/user at the same time, e.g. on a CI machine where multiple jobs run simultaneously. In fact, we've advertised this capability as "stateless mode" -- you can just pass flags for whatever credentials/cluster/env you need etc., and assuming there are valid credentials (env vars / netrc / etc.), the command will work, regardless of what's in the config file, if the config file is corrupted, etc.
I don't think we really want to totally break this functionality. But I do see the problem with needing to know what version of a command to run. So maybe we change things a bit... e.g. we could require an extra flag like "--context"? But that would indeed require at least having a config file. Can we think about this a bit more?
cmd/lint/main.go
Outdated
CurrentContext: "no context", | ||
}, | ||
{ | ||
Contexts: map[string]*v3.Context{"cloud": {PlatformName: testserver.TestCloudURL.String()}}, |
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.
When does this run, during make lint-go
? if so im not sure the test servers will have been started so testserver.TestCloudURL might be empty
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.
make lint-go
runs golangci-lint
. This is the main file for make lint-cli
, which lints command descriptions/flags. There are three possible subsets of commands that need to be linted, so we need to pass in three configs.
testserver.TestCloudURL.String()
is a constant, so this works fine! But... now that you mention it, it would be cleaner to pass in confluent.cloud
to the second config, because they're not technically tests.
Yeah, I think this is ok... you do need to have CP downloaded in order to use these commands ( |
@brianstrauch Jenkins doesn't like this: |
Checklist
[CRUCIAL] Is the change for CP or CCloud functionalities that are already live in prod?
Did you add/update any commands that accept secrets as args/flags?
What
cliName
, which was previously passed in as a linker flag (-ldflags "-X main.cliName=confluent"
)IsCloud()
andIsOnPrem()
, show the commands available in the user's current context.At this point, the
confluent
binary is unified! Future PRs will unify individual commands.Plan of action: https://confluentinc.atlassian.net/wiki/spaces/Foundations/pages/2423849814/1-Pager+CLI+Unification+Implementation+Details
Test & Review
New unit and integration tests based on showing appropriate commands
Open questions / Follow ups
Should the
confluent local
command be always shown, since it doesn't require login? Are there any other commands that don't require a login that I'm missing?