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 only registers --kubeconfig if it is not already
registered, and gets its value if so.

pkg/test: only register --kubeconfig if not registered, get value
if already registered

test/e2e: add import of controller-runtime/pkg/client/config to test --kubebuilder registration

CHANGELOG.md: add --kubeconfig double registration fix
  • Loading branch information
estroz committed Mar 28, 2020
1 parent 6c8f101 commit f20560c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
- The Ansible Operator proxy server now properly supports the Pod `exec` API ([#2716](https://github.com/operator-framework/operator-sdk/pull/2716))
- Resources that use '-' in the APIGroup name can now be directly accessed by Ansible. ([#2712](https://github.com/operator-framework/operator-sdk/pull/2712))
- Fixed issue in CSV generation that caused an incorrect path to be generated for descriptors on types that are fields in array elements. ([#2721](https://github.com/operator-framework/operator-sdk/pull/2721))
- The test framework `pkg/test` no longer double-registers the `--kubeconfig` flag. Related bug: [kubernetes-sigs/controller-runtime#878](https://github.com/kubernetes-sigs/controller-runtime/issues/878). ([#2731](https://github.com/operator-framework/operator-sdk/pull/2731))

## v0.16.0

Expand Down
1 change: 0 additions & 1 deletion pkg/test/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ func (opts *frameworkOpts) addToFlagSet(flagset *flag.FlagSet) {
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
14 changes: 14 additions & 0 deletions pkg/test/main_entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,22 @@ import (
func MainEntry(m *testing.M) {
fopts := &frameworkOpts{}
fopts.addToFlagSet(flag.CommandLine)
// controller-runtime registers the --kubeconfig flag in client config
// package:
// https://github.com/kubernetes-sigs/controller-runtime/blob/v0.5.2/pkg/client/config/config.go#L39
//
// If this flag is not registered, do so. Otherwise retrieve its value.
kcFlag := flag.Lookup(KubeConfigFlag)
if kcFlag == nil {
flag.StringVar(&fopts.kubeconfigPath, KubeConfigFlag, "", "path to kubeconfig")
}

flag.Parse()

if kcFlag != nil {
fopts.kubeconfigPath = kcFlag.Value.String()
}

f, err := newFramework(fopts)
if err != nil {
log.Fatalf("Failed to create framework: %v", err)
Expand Down
4 changes: 4 additions & 0 deletions test/e2e/_incluster-test-code/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ import (
"testing"

f "github.com/operator-framework/operator-sdk/pkg/test"

// This import tests double-registration of the --kubebuilder flag:
// https://github.com/kubernetes-sigs/controller-runtime/issues/878
_ "sigs.k8s.io/controller-runtime/pkg/client/config"
)

type testArgs struct {
Expand Down

0 comments on commit f20560c

Please sign in to comment.