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

named reserved identites support for --{,from-,to-}identity #732

Merged
merged 2 commits into from
Jun 2, 2022

Conversation

kaworu
Copy link
Member

@kaworu kaworu commented Jun 1, 2022

#717 introduced display of security identity in the (default) compact output, which is awesome. While trying to copy/paste identities from the Hubble CLI output to its --identity flag, I found that named reserved identities were not supported.

After this patch, we can write hubble observe --identity world instead of hubble observe --label reserved:world.

Before this patch, the identity flags errors were very verbose:

    % hubble observe --identity foo
    invalid argument "foo" for "--identity" flag: invalid security identity: foo: strconv.ParseUint: parsing "foo": invalid syntax

This patch shorten the error message to:

    % hubble observe --identity foo
    invalid argument "foo" for "--identity" flag: invalid security identity

The next commit will introduce support for named special identities,
which would render the integer parsing message moot.

Signed-off-by: Alexandre Perrin <alex@isovalent.com>
@kaworu kaworu added kind/enhancement This would improve or streamline existing functionality. ⌨️ area/cli Impacts the command line interface of any command in the repository. release-note/misc This PR makes changes that have no direct user impact. labels Jun 1, 2022
@kaworu kaworu requested review from gandro, rolinh and a team June 1, 2022 14:29
Copy link
Member

@rolinh rolinh left a comment

Choose a reason for hiding this comment

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

That's a very nice improvement! I have a question below.

Also, what about adding completion support for the reserved/known identities?

cmd/observe/flows_filter.go Outdated Show resolved Hide resolved
@maintainer-s-little-helper maintainer-s-little-helper bot added the ready-to-merge This PR has passed all tests and received consensus from code owners to merge. label Jun 1, 2022
@kaworu kaworu force-pushed the pr/kaworu/named-reserved-identites branch from 51acd7e to ccd709f Compare June 1, 2022 16:59
@kaworu
Copy link
Member Author

kaworu commented Jun 1, 2022

@rolinh updated with completion and list valid values on error, please take another look.

error message

% hubble observe --identity foo
invalid argument "foo" for "--identity" flag: invalid security identity, expected one of [world unmanaged health init remote-node kube-apiserver host] or a number

completion

% hubble observe --identity <TAB>
completions
health          host            init            kube-apiserver  remote-node     unmanaged       world

@kaworu kaworu force-pushed the pr/kaworu/named-reserved-identites branch from ccd709f to 846d52d Compare June 1, 2022 17:06
Copy link
Member

@rolinh rolinh left a comment

Choose a reason for hiding this comment

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

Thanks!

cmd/observe/flows_filter.go Outdated Show resolved Hide resolved
Comment on lines +497 to +505
observeCmd.RegisterFlagCompletionFunc("identity", func(_ *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) {
return reservedIdentitiesNames(), cobra.ShellCompDirectiveDefault
})
observeCmd.RegisterFlagCompletionFunc("to-identity", func(_ *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) {
return reservedIdentitiesNames(), cobra.ShellCompDirectiveDefault
})
observeCmd.RegisterFlagCompletionFunc("from-identity", func(_ *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) {
return reservedIdentitiesNames(), cobra.ShellCompDirectiveDefault
})
Copy link
Member

Choose a reason for hiding this comment

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

❤️

f7c66cc ("printer: Display security identity in compact output")
introduced display of security identities including named reserved
identities, e.g. "(host)" instead of the equivalent "(identity:1)".

Before this patch, the --identity, --from-identity, and --to-identity
flags would only accept numerical values. This patch introduce support
for named reserved identites such as "host", "world", etc.

Signed-off-by: Alexandre Perrin <alex@isovalent.com>
@gandro gandro merged commit be06c1f into master Jun 2, 2022
@gandro gandro deleted the pr/kaworu/named-reserved-identites branch June 2, 2022 08:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⌨️ area/cli Impacts the command line interface of any command in the repository. kind/enhancement This would improve or streamline existing functionality. ready-to-merge This PR has passed all tests and received consensus from code owners to merge. release-note/misc This PR makes changes that have no direct user impact.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants