mirror of
https://github.com/kubenetworks/kubevpn.git
synced 2025-09-26 19:31:17 +08:00
hotfix: fix create temp kubeconfig but name container path separator (#599)
This commit is contained in:
@@ -132,7 +132,7 @@ func GetAPIServerFromKubeConfigBytes(kubeconfigBytes []byte) *net.IPNet {
|
||||
func ConvertToTempKubeconfigFile(kubeconfigBytes []byte) (string, error) {
|
||||
pattern := "*.kubeconfig"
|
||||
cluster, ns, _ := GetCluster(kubeconfigBytes)
|
||||
if cluster != "" {
|
||||
if cluster != "" && !containerPathSeparator(cluster) && !containerPathSeparator(ns) {
|
||||
pattern = fmt.Sprintf("%s_%s_%s", cluster, ns, pattern)
|
||||
pattern = strings.ReplaceAll(pattern, string(os.PathSeparator), "-")
|
||||
}
|
||||
@@ -155,6 +155,15 @@ func ConvertToTempKubeconfigFile(kubeconfigBytes []byte) (string, error) {
|
||||
return temp.Name(), nil
|
||||
}
|
||||
|
||||
func containerPathSeparator(pattern string) bool {
|
||||
for i := 0; i < len(pattern); i++ {
|
||||
if os.IsPathSeparator(pattern[i]) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func GetCluster(kubeConfigBytes []byte) (cluster string, ns string, err error) {
|
||||
var clientConfig clientcmd.ClientConfig
|
||||
clientConfig, err = clientcmd.NewClientConfigFromBytes(kubeConfigBytes)
|
||||
|
Reference in New Issue
Block a user