Skip to content

Commit

Permalink
fix: cluster and user name conflict on add kubeconfig with same conte…
Browse files Browse the repository at this point in the history
…xt cluster and user
  • Loading branch information
poneding committed Dec 31, 2024
1 parent c509a69 commit 68f8274
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions cmd/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/spf13/cobra"
"golang.org/x/exp/slices"
"k8s.io/apimachinery/pkg/util/rand"
"k8s.io/client-go/tools/clientcmd"
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
)
Expand Down Expand Up @@ -245,7 +246,7 @@ func (kc *KubeConfigOption) handleContext(oldConfig *clientcmdapi.Config,

isClusterNameExist, isUserNameExist := checkClusterAndUserName(oldConfig, ctx.Cluster, ctx.AuthInfo)
newConfig := clientcmdapi.NewConfig()
suffix := HashSufString(name)
suffix := rand.String(10)

if isClusterNameExist {
clusterNameSuffix = "-" + suffix
Expand Down Expand Up @@ -278,7 +279,7 @@ func (kc *KubeConfigOption) handleContext(oldConfig *clientcmdapi.Config,
func addExample() string {
return `
# Merge test.yaml with $HOME/.kube/config
kubecm add -f test.yaml
kubecm add -f test.yaml
# Merge test.yaml with $HOME/.kube/config and add a prefix before context name
kubecm add -cf test.yaml --context-prefix test
# Merge test.yaml with $HOME/.kube/config and define the attributes used for composing the context name
Expand Down

0 comments on commit 68f8274

Please sign in to comment.