Skip to content

Commit

Permalink
controller-runtime currently adds the --kubeconfig flag if
Browse files Browse the repository at this point in the history
pkg/client/config is imported (set up in an init() function).
The SDK's test framework also adds this flag, which will panic
if both are imported and the test framework is initialized.
This commit creates a new flag.FlagSet for the test framework
instead of using the global one.

pkg/test: use local flag.FlagSet instead of flag.CommandLine
  • Loading branch information
estroz committed Mar 27, 2020
1 parent b0b67a4 commit ae4665c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pkg/test/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ const (

func (opts *frameworkOpts) addToFlagSet(flagset *flag.FlagSet) {
flagset.StringVar(&opts.projectRoot, ProjRootFlag, "", "path to project root")
flagset.StringVar(&opts.kubeconfigPath, KubeConfigFlag, "", "path to kubeconfig")
flagset.StringVar(&opts.namespacedManPath, NamespacedManPathFlag, "", "path to rbac manifest")
flagset.BoolVar(&opts.isLocalOperator, LocalOperatorFlag, false,
"enable if operator is running locally (not in cluster)")
flagset.StringVar(&opts.kubeconfigPath, KubeConfigFlag, "", "path to kubeconfig")
flagset.StringVar(&opts.globalManPath, GlobalManPathFlag, "", "path to operator manifest")
flagset.StringVar(&opts.localOperatorArgs, LocalOperatorArgs, "",
"flags that the operator needs (while using --up-local). example: \"--flag1 value1 --flag2=value2\"")
Expand Down
6 changes: 4 additions & 2 deletions pkg/test/main_entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ import (

func MainEntry(m *testing.M) {
fopts := &frameworkOpts{}
fopts.addToFlagSet(flag.CommandLine)
flag.Parse()
fs := flag.NewFlagSet(os.Args[0], flag.ExitOnError)
fopts.addToFlagSet(fs)

fs.Parse(os.Args[1:])

f, err := newFramework(fopts)
if err != nil {
Expand Down

0 comments on commit ae4665c

Please sign in to comment.