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

Lines changed: 6 additions & 1 deletion
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy