@@ -83,6 +83,8 @@ type KubeRuntimeConfig struct {
83
83
84
84
type KubeRuntime struct {
85
85
node * Node
86
+
87
+ kubeConfig * restclient.Config
86
88
}
87
89
88
90
// readState reads the URI and staking address for the node if the node is running.
@@ -741,13 +743,23 @@ func (p *KubeRuntime) runtimeConfig() *KubeRuntimeConfig {
741
743
return p .node .getRuntimeConfig ().Kube
742
744
}
743
745
746
+ // getKubeconfig retrieves the kubeconfig for the target cluster. It
747
+ // will be cached after the first call to avoid unnecessary logging
748
+ // when running in-cluster.
744
749
func (p * KubeRuntime ) getKubeconfig () (* restclient.Config , error ) {
745
- runtimeConfig := p .runtimeConfig ()
746
- return GetClientConfig (
747
- p .node .network .log ,
748
- runtimeConfig .ConfigPath ,
749
- runtimeConfig .ConfigContext ,
750
- )
750
+ if p .kubeConfig == nil {
751
+ runtimeConfig := p .runtimeConfig ()
752
+ config , err := GetClientConfig (
753
+ p .node .network .log ,
754
+ runtimeConfig .ConfigPath ,
755
+ runtimeConfig .ConfigContext ,
756
+ )
757
+ if err != nil {
758
+ return nil , fmt .Errorf ("failed to get kubeconfig: %w" , err )
759
+ }
760
+ p .kubeConfig = config
761
+ }
762
+ return p .kubeConfig , nil
751
763
}
752
764
753
765
func (p * KubeRuntime ) getClientset () (* kubernetes.Clientset , error ) {
0 commit comments