Closed nurhun closed 1 year ago
I'm getting "flag redefined: kubeconfig" error detailed below with the second request, I had to restart the server for each request when using out-of-cluster config example here https://github.com/kubernetes/client-go/blob/master/examples/out-of-cluster-client-configuration/main.go
2023/03/28 20:29:05 http: panic serving 127.0.0.1:43550: /home/nurhun/project/__debug_bin flag redefined: kubeconfig goroutine 10 [running]: net/http.(*conn).serve.func1() usr/local/go/src/net/http/server.go:1825 +0x148 panic({0x20bc8e0, 0xc0001910c0}) /usr/local/go/src/runtime/panic.go:844 +0x25a flag.(*FlagSet).Var(0xc00007c1e0, {0x2557120, 0xc000190fc0}, {0x23b1a0a, 0xa}, {0x23ee655, 0x2f}) /usr/local/go/src/flag/flag.go:879 +0x3d9 flag.(*FlagSet).StringVar(0xc00007c1e0, 0xc000190fc0, {0x23b1a0a, 0xa}, {0xc0004161e0, 0x19}, {0x23ee655, 0x2f}) /usr/local/go/src/flag/flag.go:762 +0x8c flag.(*FlagSet).String(0xc00007c1e0, {0x23b1a0a, 0xa}, {0xc0004161e0, 0x19}, {0x23ee655, 0x2f}) /usr/local/go/src/flag/flag.go:775 +0x95 flag.String({0x23b1a0a, 0xa}, {0xc0004161e0, 0x19}, {0x23ee655, 0x2f}) /usr/local/go/src/flag/flag.go:782 +0x6b main.(*Kube).ConnectLocal(0xc00000e108) /home/nurhun/project/kube.go:39 +0x15d main.(*Kube).SelectConnection(0xc00000e108) /home/nurhun/project/kube.go:78 +0x48 main.getSystemTestEnvList({0x2568288, 0xc0005c6000}, 0xc0005c2200) /home/nurhun/project/main.go:1128 +0x4f net/http.HandlerFunc.ServeHTTP(0x249fbe0, {0x2568288, 0xc0005c6000}, 0xc0005c2200) /usr/local/go/src/net/http/server.go:2084 +0x43 main.BasicAuthMiddleware.func1({0x2568288, 0xc0005c6000}, 0xc0005c2200) /home/nurhun/project/main.go:1195 +0x21e net/http.HandlerFunc.ServeHTTP(0xc00000e0f0, {0x2568288, 0xc0005c6000}, 0xc0005c2200) /usr/local/go/src/net/http/server.go:2084 +0x43 github.com/gorilla/mux.(*Router).ServeHTTP(0xc00011e540, {0x2568288, 0xc0005c6000}, 0xc0005c2200) /home/nurhun/go/pkg/mod/github.com/gorilla/mux@v1.8.0/mux.go:210 +0x25d net/http.serverHandler.ServeHTTP({0xc0004b41c0}, {0x2568288, 0xc0005c6000}, 0xc0005c2000) /usr/local/go/src/net/http/server.go:2916 +0x474 net/http.(*conn).serve(0xc000286be0, {0x2568d38, 0xc0003df000}) /usr/local/go/src/net/http/server.go:1966 +0x193c created by net/http.(*Server).Serve /usr/local/go/src/net/http/server.go:3071 +0x9cf
There was another issue for the same here https://github.com/kubernetes/client-go/issues/1142
I managed to solve it. Open PR is here https://github.com/kubernetes/client-go/pull/1239
The flag should only be registered in your main() function, not inside a client function you invoke multiple times
I'm getting "flag redefined: kubeconfig" error detailed below with the second request, I had to restart the server for each request when using out-of-cluster config example here https://github.com/kubernetes/client-go/blob/master/examples/out-of-cluster-client-configuration/main.go
There was another issue for the same here https://github.com/kubernetes/client-go/issues/1142