From eb3812354a5a811fd07566b4a1646fe000d0f695 Mon Sep 17 00:00:00 2001 From: Francesco Romani Date: Tue, 31 Oct 2023 09:51:28 +0100 Subject: [PATCH] k8s: add option to set kubeconfig add option to give the KUBECONFIG path explicitly. This is meant to be used in testing and in development. Signed-off-by: Francesco Romani --- cmd/resource-topology-exporter/main.go | 4 ++-- pkg/config/config.go | 2 ++ test/data/TestDefaults.expected.json | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/cmd/resource-topology-exporter/main.go b/cmd/resource-topology-exporter/main.go index fd9bdfa0..d996dce6 100644 --- a/cmd/resource-topology-exporter/main.go +++ b/cmd/resource-topology-exporter/main.go @@ -52,9 +52,9 @@ func main() { os.Exit(0) } - k8scli, err := k8shelpers.GetK8sClient("") + k8scli, err := k8shelpers.GetK8sClient(parsedArgs.KubeConfig) if err != nil { - klog.Fatalf("failed to get k8s client: %w", err) + klog.Fatalf("failed to get k8s client: %v", err) } cli, cleanup, err := podres.WaitForReady(podres.GetClient(parsedArgs.RTE.PodResourcesSocketPath)) diff --git a/pkg/config/config.go b/pkg/config/config.go index 036de0cc..966b0314 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -44,6 +44,7 @@ type ProgArgs struct { RTE resourcetopologyexporter.Args Version bool DumpConfig string + KubeConfig string } func (pa *ProgArgs) ToJson() ([]byte, error) { @@ -133,6 +134,7 @@ Special targets: . ".andexit" stdout and exit right after. . ".log" to dump in the log".`, ) + flags.StringVar(&pArgs.KubeConfig, "kubeconfig", "", "path to kubeconfig file.") err := flags.Parse(args) if err != nil { diff --git a/test/data/TestDefaults.expected.json b/test/data/TestDefaults.expected.json index 5e8b523d..162a5648 100644 --- a/test/data/TestDefaults.expected.json +++ b/test/data/TestDefaults.expected.json @@ -1 +1 @@ -{"NRTupdater":{"NoPublish":false,"Oneshot":false,"Hostname":"TEST_NODE"},"Resourcemonitor":{"Namespace":"","SysfsRoot":"/sys","ResourceExclude":null,"RefreshNodeResources":false,"PodSetFingerprint":true,"PodSetFingerprintMethod":"with-exclusive-resources","ExposeTiming":false,"PodSetFingerprintStatusFile":"","PodExclude":null,"ExcludeTerminalPods":false},"RTE":{"Debug":false,"ReferenceContainer":{"Namespace":"TEST_NS","PodName":"TEST_POD","ContainerName":"TEST_CONT"},"TopologyManagerPolicy":"","TopologyManagerScope":"","KubeletConfigFile":"/podresources/config.yaml","PodResourcesSocketPath":"unix:///podresources/kubelet.sock","SleepInterval":60000000000,"PodReadinessEnable":true,"NotifyFilePath":"","MaxEventsPerTimeUnit":1,"TimeUnitToLimitEvents":1000000000,"AddNRTOwnerEnable":true,"PrometheusMode":"disabled"},"Version":false,"DumpConfig":""} \ No newline at end of file +{"NRTupdater":{"NoPublish":false,"Oneshot":false,"Hostname":"TEST_NODE"},"Resourcemonitor":{"Namespace":"","SysfsRoot":"/sys","ResourceExclude":null,"RefreshNodeResources":false,"PodSetFingerprint":true,"PodSetFingerprintMethod":"with-exclusive-resources","ExposeTiming":false,"PodSetFingerprintStatusFile":"","PodExclude":null,"ExcludeTerminalPods":false},"RTE":{"Debug":false,"ReferenceContainer":{"Namespace":"TEST_NS","PodName":"TEST_POD","ContainerName":"TEST_CONT"},"TopologyManagerPolicy":"","TopologyManagerScope":"","KubeletConfigFile":"/podresources/config.yaml","PodResourcesSocketPath":"unix:///podresources/kubelet.sock","SleepInterval":60000000000,"PodReadinessEnable":true,"NotifyFilePath":"","MaxEventsPerTimeUnit":1,"TimeUnitToLimitEvents":1000000000,"AddNRTOwnerEnable":true,"PrometheusMode":"disabled"},"Version":false,"DumpConfig":"","KubeConfig":""} \ No newline at end of file