Skip to content

Commit 81364bc

Browse files
committed
e2e: operator: remove kubeconfig flag added by controller-runtime
Signed-off-by: Tuomas Katila <tuomas.katila@intel.com>
1 parent e958204 commit 81364bc

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

test/e2e/operator/operator_suite_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ import (
2020
"context"
2121
"flag"
2222
"os"
23+
"reflect"
2324
"testing"
2425
"time"
26+
"unsafe"
2527

2628
"github.com/onsi/ginkgo/v2"
2729
"github.com/onsi/gomega"
@@ -226,6 +228,12 @@ func TestMain(m *testing.M) {
226228
logs.InitLogs()
227229
config.CopyFlags(config.Flags, flag.CommandLine)
228230
framework.RegisterCommonFlags(flag.CommandLine)
231+
// controller-runtime's init() registers "kubeconfig" to flag.CommandLine before TestMain runs.
232+
// framework.RegisterClusterFlags also registers "kubeconfig", which causes a panic.
233+
// Remove the controller-runtime registration so the framework's version (which binds to
234+
// TestContext.KubeConfig) takes over. "formal" is unexported, so unsafe is required.
235+
fv := reflect.ValueOf(flag.CommandLine).Elem().FieldByName("formal")
236+
reflect.NewAt(fv.Type(), unsafe.Pointer(fv.UnsafeAddr())).Elem().SetMapIndex(reflect.ValueOf("kubeconfig"), reflect.Value{})
229237
framework.RegisterClusterFlags(flag.CommandLine)
230238
flag.Parse()
231239

0 commit comments

Comments
 (0)