From 4e5b68fa730f1509268b871b73c055e2e7fc20eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20D=C3=BCpmeier?= Date: Thu, 7 Nov 2024 12:56:42 +0100 Subject: [PATCH] fix(k8s): honor options.RestConfig in tunnel.ForwardPortE The tunnel.ForwardPortE function does not honor the rest config configured inside the KubectlOptions. This leads to a mismatch with other functions. This commit uses the RestConfig if defined instead of getting a new one. --- modules/k8s/tunnel.go | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/modules/k8s/tunnel.go b/modules/k8s/tunnel.go index 49c017aa8..f825fed2c 100644 --- a/modules/k8s/tunnel.go +++ b/modules/k8s/tunnel.go @@ -189,15 +189,18 @@ func (tunnel *Tunnel) ForwardPortE(t testing.TestingT) error { tunnel.logger.Logf(t, "Error creating a new Kubernetes client: %s", err) return err } - kubeConfigPath, err := tunnel.kubectlOptions.GetConfigPath(t) - if err != nil { - tunnel.logger.Logf(t, "Error getting kube config path: %s", err) - return err - } - config, err := LoadApiClientConfigE(kubeConfigPath, tunnel.kubectlOptions.ContextName) - if err != nil { - tunnel.logger.Logf(t, "Error loading Kubernetes config: %s", err) - return err + config := tunnel.kubectlOptions.RestConfig + if config == nil { + kubeConfigPath, err := tunnel.kubectlOptions.GetConfigPath(t) + if err != nil { + tunnel.logger.Logf(t, "Error getting kube config path: %s", err) + return err + } + config, err = LoadApiClientConfigE(kubeConfigPath, tunnel.kubectlOptions.ContextName) + if err != nil { + tunnel.logger.Logf(t, "Error loading Kubernetes config: %s", err) + return err + } } // Find the pod to port forward to