Skip to content

Commit 2a0ca73

Browse files
committed
fixup: Cache kubeconfig
1 parent b0c67da commit 2a0ca73

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

tests/fixture/tmpnet/kube_runtime.go

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ type KubeRuntimeConfig struct {
8383

8484
type KubeRuntime struct {
8585
node *Node
86+
87+
kubeConfig *restclient.Config
8688
}
8789

8890
// readState reads the URI and staking address for the node if the node is running.
@@ -741,13 +743,23 @@ func (p *KubeRuntime) runtimeConfig() *KubeRuntimeConfig {
741743
return p.node.getRuntimeConfig().Kube
742744
}
743745

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.
744749
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
751763
}
752764

753765
func (p *KubeRuntime) getClientset() (*kubernetes.Clientset, error) {

0 commit comments

Comments
 (0)