Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions common-lib/utils/k8s/bean.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,13 @@ type ClusterConfig struct {
}

func (clusterConfig *ClusterConfig) PopulateTlsConfigurationsInto(restConfig *rest.Config) {
restConfig.TLSClientConfig = rest.TLSClientConfig{Insecure: clusterConfig.InsecureSkipTLSVerify}
serverName, err := GetServerNameFromServerUrl(clusterConfig.Host)
if err != nil {
// making it non-blocking to avoid blocking the flow
fmt.Println("Error parsing server URL:", err, "clusterConfig.Host", clusterConfig.Host)
}
restConfig.TLSClientConfig = rest.TLSClientConfig{Insecure: clusterConfig.InsecureSkipTLSVerify, ServerName: serverName}
if clusterConfig.InsecureSkipTLSVerify == false {
restConfig.TLSClientConfig.ServerName = restConfig.ServerName
restConfig.TLSClientConfig.KeyData = []byte(clusterConfig.KeyData)
restConfig.TLSClientConfig.CertData = []byte(clusterConfig.CertData)
restConfig.TLSClientConfig.CAData = []byte(clusterConfig.CAData)
Expand Down
18 changes: 18 additions & 0 deletions common-lib/utils/k8s/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ import (
"k8s.io/client-go/discovery"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"net"
"net/http"
"net/url"
"strings"
)

Expand Down Expand Up @@ -226,3 +228,19 @@ func OverrideK8sHttpClientWithTracer(restConfig *rest.Config) (*http.Client, err
httpClientFor.Transport = otelhttp.NewTransport(httpClientFor.Transport)
return httpClientFor, nil
}

func GetServerNameFromServerUrl(serverURL string) (string, error) {
u, err := url.Parse(serverURL)
if err != nil {
return "", err
}

host := u.Host
if strings.Contains(host, ":") {
host, _, err = net.SplitHostPort(u.Host)
if err != nil {
return "", err
}
}
return host, nil
}