Skip to content

Commit

Permalink
[release-1.28] Remove duplicate pflag.Parse calls (#2467)
Browse files Browse the repository at this point in the history
* client-keystone-auth: Remove duplicate pflag.Parse call

This is already handled by the earlier call to the (confusingly named)
'InitFlags' function provided by 'k8s.io/component-base/cli/flag' [1].

[1] https://github.com/kubernetes/component-base/blob/v0.28.1/cli/flag/flags.go#L51-L59

Signed-off-by: Stephen Finucane <[email protected]>
(cherry picked from commit d0fc449)

* k8s-keystone-auth: Remove duplicate pflag.Parse call

This is already handled by the earlier call to the (confusingly named)
'InitFlags' function provided by 'k8s.io/component-base/cli/flag' [1].
We need to move the handling for the '--version' flag to after this to
ensure we parse the flags first.

[1] https://github.com/kubernetes/component-base/blob/v0.28.1/cli/flag/flags.go#L51-L59

Signed-off-by: Stephen Finucane <[email protected]>
(cherry picked from commit de63646)
  • Loading branch information
stephenfin authored Nov 7, 2023
1 parent 23bb1df commit 92619e4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
3 changes: 1 addition & 2 deletions cmd/client-keystone-auth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,8 @@ func main() {
logs.AddFlags(pflag.CommandLine)

pflag.CommandLine.AddGoFlagSet(klogFlags)
kflag.InitFlags()

pflag.Parse()
kflag.InitFlags()

if showVersion {
fmt.Println(version.Version)
Expand Down
13 changes: 6 additions & 7 deletions cmd/k8s-keystone-auth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,19 @@ func main() {
}
})

pflag.Parse()

if showVersion {
fmt.Println(version.Version)
os.Exit(0)
}

logs.InitLogs()
defer logs.FlushLogs()

config := keystone.NewConfig()
config.AddFlags(pflag.CommandLine)

kflag.InitFlags()

if showVersion {
fmt.Println(version.Version)
os.Exit(0)
}

if err := config.ValidateFlags(); err != nil {
klog.Errorf("%v", err)
os.Exit(1)
Expand Down

0 comments on commit 92619e4

Please sign in to comment.