Skip to content

Commit 5672bc2

Browse files
committed
Fix not in cluster error
1 parent f9c7461 commit 5672bc2

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

main.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"errors"
45
"fmt"
56
"net/url"
67
"os"
@@ -9,6 +10,7 @@ import (
910
"cdr.dev/slog/sloggers/sloghuman"
1011
"github.com/spf13/cobra"
1112
"k8s.io/client-go/kubernetes"
13+
restclient "k8s.io/client-go/rest"
1214
"k8s.io/client-go/tools/clientcmd"
1315
)
1416

@@ -48,7 +50,10 @@ func root() *cobra.Command {
4850
kubeConfig = home + kubeConfig[1:]
4951
}
5052

51-
config, err := clientcmd.BuildConfigFromFlags("", kubeConfig)
53+
config, err := restclient.InClusterConfig()
54+
if errors.Is(err, restclient.ErrNotInCluster) {
55+
config, err = clientcmd.BuildConfigFromFlags("", kubeConfig)
56+
}
5257
if err != nil {
5358
return fmt.Errorf("build kubeconfig: %w", err)
5459
}

0 commit comments

Comments
 (0)