@@ -160,6 +160,8 @@ func (c *KubeRuntimeConfig) ensureDefaults(ctx context.Context, log logging.Logg
160
160
161
161
type KubeRuntime struct {
162
162
node * Node
163
+
164
+ kubeConfig * restclient.Config
163
165
}
164
166
165
167
// readState reads the URI and staking address for the node if the node is running.
@@ -818,13 +820,23 @@ func (p *KubeRuntime) runtimeConfig() *KubeRuntimeConfig {
818
820
return p .node .getRuntimeConfig ().Kube
819
821
}
820
822
823
+ // getKubeconfig retrieves the kubeconfig for the target cluster. It
824
+ // will be cached after the first call to avoid unnecessary logging
825
+ // when running in-cluster.
821
826
func (p * KubeRuntime ) getKubeconfig () (* restclient.Config , error ) {
822
- runtimeConfig := p .runtimeConfig ()
823
- return GetClientConfig (
824
- p .node .network .log ,
825
- runtimeConfig .ConfigPath ,
826
- runtimeConfig .ConfigContext ,
827
- )
827
+ if p .kubeConfig == nil {
828
+ runtimeConfig := p .runtimeConfig ()
829
+ config , err := GetClientConfig (
830
+ p .node .network .log ,
831
+ runtimeConfig .ConfigPath ,
832
+ runtimeConfig .ConfigContext ,
833
+ )
834
+ if err != nil {
835
+ return nil , fmt .Errorf ("failed to get kubeconfig: %w" , err )
836
+ }
837
+ p .kubeConfig = config
838
+ }
839
+ return p .kubeConfig , nil
828
840
}
829
841
830
842
func (p * KubeRuntime ) getClientset () (* kubernetes.Clientset , error ) {
0 commit comments