Skip to content
This repository was archived by the owner on Sep 2, 2024. It is now read-only.

Commit ed12c95

Browse files
committed
support multi-entry kubeconfig
Fixes #81 Signed-off-by: Jacob Blain Christen <[email protected]>
1 parent 8733bde commit ed12c95

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

pkg/client/client.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package client
33
import (
44
"context"
55
"net"
6+
"os"
7+
"path/filepath"
68
"strconv"
79

810
"github.com/pkg/errors"
@@ -13,10 +15,10 @@ import (
1315
corectlv1 "github.com/rancher/wrangler/pkg/generated/controllers/core/v1"
1416
rbacctl "github.com/rancher/wrangler/pkg/generated/controllers/rbac"
1517
rbacctlv1 "github.com/rancher/wrangler/pkg/generated/controllers/rbac/v1"
16-
"github.com/rancher/wrangler/pkg/kubeconfig"
1718
"github.com/sirupsen/logrus"
1819
corev1 "k8s.io/api/core/v1"
1920
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21+
"k8s.io/client-go/tools/clientcmd"
2022
"k8s.io/kubernetes/pkg/credentialprovider"
2123
"k8s.io/kubernetes/pkg/credentialprovider/secrets"
2224
)
@@ -51,7 +53,20 @@ type Interface struct {
5153
}
5254

5355
func NewInterface(kubecfg, kubectx, kubens string) (*Interface, error) {
54-
cc := kubeconfig.GetNonInteractiveClientConfigWithContext(kubecfg, kubectx)
56+
if err := os.Setenv(clientcmd.RecommendedConfigPathEnvVar, kubecfg); err != nil {
57+
logrus.Warn(err)
58+
}
59+
lr := clientcmd.NewDefaultClientConfigLoadingRules()
60+
lr.DefaultClientConfig = &clientcmd.DefaultClientConfig
61+
if home, err := os.UserHomeDir(); err == nil {
62+
lr.Precedence = append(lr.Precedence, filepath.Join(home, ".kube", "k3s.yaml"))
63+
}
64+
lr.Precedence = append(lr.Precedence, "/etc/rancher/k3s/k3s.yaml")
65+
cc := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(lr, &clientcmd.ConfigOverrides{
66+
ClusterDefaults: clientcmd.ClusterDefaults,
67+
CurrentContext: kubectx,
68+
})
69+
5570
ns, _, err := cc.Namespace()
5671
if err != nil {
5772
return nil, err

0 commit comments

Comments
 (0)