Skip to content

Commit

Permalink
Merge pull request #2270 from headlamp-k8s/dns_friendly_content_name
Browse files Browse the repository at this point in the history
backend: Make sure context name is DNS compatible
  • Loading branch information
yolossn authored Aug 29, 2024
2 parents 247e8f8 + 33bffb0 commit 0fa13bc
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions backend/pkg/kubeconfig/kubeconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
}

0 comments on commit 0fa13bc

Please sign in to comment.