@@ -41,6 +41,7 @@ import (
4141 "k8s.io/apimachinery/pkg/labels"
4242 "k8s.io/client-go/kubernetes"
4343 coordinationv1lister "k8s.io/client-go/listers/coordination/v1"
44+ "k8s.io/client-go/rest"
4445 "k8s.io/client-go/tools/cache"
4546 "k8s.io/client-go/tools/clientcmd"
4647 "k8s.io/klog/v2"
@@ -144,12 +145,20 @@ func (a *Agent) runProxyConnection(o *options.GrpcProxyAgentOptions, drainCh, st
144145 cc := o .ClientSetConfig (dialOptions ... )
145146
146147 if o .CountServerLeases {
147- var k8sClient * kubernetes.Clientset
148- config , err := clientcmd .BuildConfigFromFlags ("" , o .KubeconfigPath )
149- if err != nil {
150- return nil , fmt .Errorf ("failed to load kubernetes client config: %v" , err )
148+ var config * rest.Config
149+ if o .KubeconfigPath != "" {
150+ config , err = clientcmd .BuildConfigFromFlags ("" , o .KubeconfigPath )
151+ if err != nil {
152+ return nil , fmt .Errorf ("failed to load kubernetes client config: %v" , err )
153+ }
154+ } else {
155+ config , err = rest .InClusterConfig ()
156+ if err != nil {
157+ return nil , fmt .Errorf ("failed to load in cluster kubernetes client config: %w" , err )
158+ }
151159 }
152- k8sClient , err = kubernetes .NewForConfig (config )
160+
161+ k8sClient , err := kubernetes .NewForConfig (config )
153162 if err != nil {
154163 return nil , fmt .Errorf ("failed to create kubernetes clientset: %v" , err )
155164 }
0 commit comments