@@ -3,6 +3,8 @@ package client
3
3
import (
4
4
"context"
5
5
"net"
6
+ "os"
7
+ "path/filepath"
6
8
"strconv"
7
9
8
10
"github.com/pkg/errors"
@@ -13,10 +15,10 @@ import (
13
15
corectlv1 "github.com/rancher/wrangler/pkg/generated/controllers/core/v1"
14
16
rbacctl "github.com/rancher/wrangler/pkg/generated/controllers/rbac"
15
17
rbacctlv1 "github.com/rancher/wrangler/pkg/generated/controllers/rbac/v1"
16
- "github.com/rancher/wrangler/pkg/kubeconfig"
17
18
"github.com/sirupsen/logrus"
18
19
corev1 "k8s.io/api/core/v1"
19
20
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21
+ "k8s.io/client-go/tools/clientcmd"
20
22
"k8s.io/kubernetes/pkg/credentialprovider"
21
23
"k8s.io/kubernetes/pkg/credentialprovider/secrets"
22
24
)
@@ -51,7 +53,20 @@ type Interface struct {
51
53
}
52
54
53
55
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
+
55
70
ns , _ , err := cc .Namespace ()
56
71
if err != nil {
57
72
return nil , err
0 commit comments