Skip to content

refactor stringSlice type CLI arguments#12457

Merged
tgraf merged 1 commit intocilium:masterfrom
LexCC:pr/JieJhih/refactor-config
Jul 9, 2020
Merged

refactor stringSlice type CLI arguments#12457
tgraf merged 1 commit intocilium:masterfrom
LexCC:pr/JieJhih/refactor-config

Conversation

@LexCC
Copy link
Copy Markdown
Contributor

@LexCC LexCC commented Jul 8, 2020

Signed-off-by: JieJhih Jhang jiejhihjhang@gmail.com

The type of option --log-driver is string slice, which make this line entry.Infof(" --%s='%s'", k, viper.GetString(k)) will get the empty string. For the options should handle both type string and string slice, otherwise just print the empty string at the final.
Fixes: #12132

Fix string slice type CLI arguments

@LexCC LexCC requested a review from a team July 8, 2020 11:55
@LexCC LexCC requested a review from a team as a code owner July 8, 2020 11:55
@maintainer-s-little-helper maintainer-s-little-helper Bot added the dont-merge/needs-release-note-label The author needs to describe the release impact of these changes. label Jul 8, 2020
Copy link
Copy Markdown
Member

@tklauser tklauser left a comment

Choose a reason for hiding this comment

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

Please also provide a short description why this change was done (not just what it does) in the commit message and PR description.

Comment thread pkg/option/config.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The len of a slice can never be smaller than 0. I think you can just drop this if clause and let the entry.Infof below print the key with an empty value.

Comment thread pkg/option/config.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This will print the option in the format --option=[value1 value2 value3] due to the %v verb being used. It would be nice to get a comma-separated list here so it matches the way the option was passed on the command line.

@tklauser tklauser added the release-note/misc This PR makes changes that have no direct user impact. label Jul 8, 2020
@maintainer-s-little-helper maintainer-s-little-helper Bot removed the dont-merge/needs-release-note-label The author needs to describe the release impact of these changes. label Jul 8, 2020
@coveralls
Copy link
Copy Markdown

coveralls commented Jul 8, 2020

Coverage Status

Coverage decreased (-0.01%) to 36.933% when pulling dcb6589 on JieJhih:pr/JieJhih/refactor-config into d7e2076 on cilium:master.

@LexCC LexCC force-pushed the pr/JieJhih/refactor-config branch from fef08e4 to 6a85ac3 Compare July 8, 2020 16:00
@LexCC
Copy link
Copy Markdown
Contributor Author

LexCC commented Jul 8, 2020

Thanks for reviewing, I've updated the PR. Please take a look.

Please also provide a short description why this change was done (not just what it does) in the commit message and PR description.

Copy link
Copy Markdown
Member

@tklauser tklauser left a comment

Choose a reason for hiding this comment

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

Thanks for the updated commit messages. Got one more suggestion inline regarding the actual fix.

Comment thread pkg/option/config.go Outdated
Comment on lines 1234 to 1239
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think we don't need to wrap the option list with [...] in the output. Also, we should still report options with empty values. How about making this a bit more concise, e.g. as follows?

Suggested change
msgs := viper.GetStringSlice(k)
if len(msgs) > 0 {
entry.Infof(" --%s='[%s]'", k, strings.Join(msgs, ","))
continue
}
msg := viper.GetString(k)
if len(msg) > 0 {
entry.Infof(" --%s='%s'", k, msg)
}
v := viper.GetStringSlice(k)
if len(v) > 0 {
entry.Infof(" --%s='%s'", k, strings.Join(v, ","))
} else {
entry.Infof(" --%s='%s'", k, viper.GetString(k))
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Looks good! I've update the PR, please take a look.

Signed-off-by: JieJhih Jhang <jiejhihjhang@gmail.com>
@LexCC LexCC force-pushed the pr/JieJhih/refactor-config branch from 6a85ac3 to dcb6589 Compare July 9, 2020 06:38
@tklauser
Copy link
Copy Markdown
Member

tklauser commented Jul 9, 2020

test-me-please

Copy link
Copy Markdown
Member

@tklauser tklauser left a comment

Choose a reason for hiding this comment

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

LGTM, thanks.

Copy link
Copy Markdown
Member

@aanm aanm left a comment

Choose a reason for hiding this comment

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

Nice finding. I think we also need to address GetIntSlice and all other Slices in case we start using it in the future.

@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 Jul 9, 2020
@aanm aanm added needs-backport/1.6 release-note/bug This PR fixes an issue in a previous release of Cilium. and removed release-note/misc This PR makes changes that have no direct user impact. labels Jul 9, 2020
@tgraf tgraf merged commit 9fe5b33 into cilium:master Jul 9, 2020
@brb brb mentioned this pull request Jul 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-to-merge This PR has passed all tests and received consensus from code owners to merge. release-note/bug This PR fixes an issue in a previous release of Cilium.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

StringSlice type CLI arguments (e.g. --log-driver=syslog,stdout) are empty in dumped configurations

9 participants