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

test framework: handle double-registered --kubeconfig flag #2731

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
estroz marked this conversation as resolved.
Show resolved Hide resolved
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
camilamacedo86 marked this conversation as resolved.
Show resolved Hide resolved
//
// 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)
estroz marked this conversation as resolved.
Show resolved Hide resolved
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:
Copy link
Member Author

Choose a reason for hiding this comment

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

@jmrodri @camilamacedo86 confirmed that this import causes a panic w/o these changes.

// https://github.com/kubernetes-sigs/controller-runtime/issues/878
_ "sigs.k8s.io/controller-runtime/pkg/client/config"
)

type testArgs struct {
Expand Down