From 33bffb038f68f1526fd631f6f8968daa26aac44a Mon Sep 17 00:00:00 2001 From: yolossn Date: Tue, 27 Aug 2024 18:32:16 +0530 Subject: [PATCH] backend: Make sure context name is DNS compatible this patch makes sure the context name is DNS compatible. Signed-off-by: yolossn --- backend/pkg/kubeconfig/kubeconfig.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/backend/pkg/kubeconfig/kubeconfig.go b/backend/pkg/kubeconfig/kubeconfig.go index 4062aea0f6..eeaed0df22 100644 --- a/backend/pkg/kubeconfig/kubeconfig.go +++ b/backend/pkg/kubeconfig/kubeconfig.go @@ -261,6 +261,9 @@ func LoadContextsFromAPIConfig(config *api.Config, skipProxySetup bool) ([]Conte // Note: nil authInfo is valid as authInfo can be provided by token. authInfo := config.AuthInfos[context.AuthInfo] + // Make contextName DNS friendly. + contextName = makeDNSFriendly(contextName) + context := Context{ Name: contextName, KubeContext: context, @@ -408,3 +411,11 @@ func LoadAndStoreKubeConfigs(kubeConfigStore ContextStore, kubeConfigs string, s return nil } + +// makeDNSFriendly converts a string to a DNS-friendly format. +func makeDNSFriendly(name string) string { + name = strings.ReplaceAll(name, "/", "--") + name = strings.ReplaceAll(name, " ", "__") + + return name +}