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

CLI Unification: kafka #936

Merged
merged 1 commit into from
Jul 29, 2021
Merged

CLI Unification: kafka #936

merged 1 commit into from
Jul 29, 2021

Conversation

brianstrauch
Copy link
Member

Checklist

  1. [CRUCIAL] Is the change for CP or CCloud functionalities that are already live in prod?

    • yes: ok
  2. Did you add/update any commands that accept secrets as args/flags?

    • no: ok

What

Unified the kafka command. Notably, the on-prem kafka acl and kafka topic commands are "stateless" (they have a --url flag, so they can be used without logging in). We show the on-prem version of those command when the user is not logged in, or logged in on-prem. Otherwise, we show the cloud version of those commands.

Test & Review

Make sure integration tests can infer a cloud or on-prem context. All existing tests pass.

@brianstrauch brianstrauch requested a review from a team as a code owner July 22, 2021 18:48
Comment on lines +74 to +75
c.AddCommand(NewAclCommandOnPrem(c.prerunner))
c.AddCommand(NewTopicCommandOnPrem(c.prerunner))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So these are going to be shown for ccloud users?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, if you're logged in to Confluent Cloud, you get the cloud version of those two commands (there's a return at the end of the above if)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah got it - I understand these are shown pre-login since you can authenticate directly against KRest w/o MDS, but do you think it's a weird UX for these commands to show up for a ccloud user when they aren't logged in, but then go away once they do login?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not that I have an alternative idea 😅

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, they'll stick around when the user logs in! There's three cases:

  1. Not logged in: You get the on-prem command.
  2. Logged in with MDS: You get the on-prem command.
  3. Logged in to Cloud: You get the cloud command.

@@ -164,6 +165,7 @@ func AuthenticatedConfigMock(params mockConfigParams) *Config {
MetricSink: nil,
Logger: log.New(),
})
conf.IsTest = true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The IsCloud() function looks for a Confluent Cloud URL in your config. If IsTest is set, it can also look for a local Confluent Cloud URL (http://localhost:1024) which is what the integration tests are hardcoded to use.

I think it's possible that someone uses http://localhost:1024 as their on-prem MDS URL, so I decided it's better to be safe than sorry and only check for that URL when it's an integration test.

Copy link
Contributor

@DABH DABH left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM up to minor questions/comments

c.serverCompleter.AddCommand(aclCmd)
c.serverCompleter.AddCommand(clusterCmd)
c.serverCompleter.AddCommand(groupCmd)
c.serverCompleter.AddCommand(groupCmd.lagCmd)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you manually test that these server completers still work? I know it sounds weird, but I remember back in the day that there was something sensitive about the order of when you added the commands and when you added the completers. But maybe it was just that you have to add the servercompleters after you add the commands (which would make sense).

Copy link
Member Author

@brianstrauch brianstrauch Jul 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, there's a comment up above about that. Wouldn't hurt to double check though.

Order matters here. If we add to the server-side completer first then the command doesn't have a parent and that doesn't trigger completion.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It turns out that Cobra has built in arg and flag completion... Wish we had gone down that route instead of creating an entire shell 😅

https://github.com/spf13/cobra/blob/master/shell_completions.md#dynamic-completion-of-nouns

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It honestly might be worth playing around with this and seeing how difficult it is to implement. I feel like the autocomplete stuff is something no one has a great understanding of which is leading to some technical debt (new commands not having the proper ServerComplete functions, etc).

@brianstrauch brianstrauch merged commit 3259327 into main Jul 29, 2021
@brianstrauch brianstrauch deleted the unify-kafka branch July 29, 2021 01:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants