Skip to content

Commit 824d64e

Browse files
committed
fix: make sure that the context without prefix is correctly computed
1 parent e00e251 commit 824d64e

1 file changed

Lines changed: 2 additions & 9 deletions

File tree

pkg/subcommands/set-context/set_context.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func SetContext(desiredContext string, stores []store.KubeconfigStore, config *t
5151

5252
kubeconfigStore := *discoveredContext.Store
5353

54-
contextWithoutPrefix := discoveredContext.Path
54+
contextWithoutPrefix := discoveredContext.Name
5555
if len(kubeconfigStore.GetContextPrefix(discoveredContext.Path)) > 0 && strings.HasPrefix(discoveredContext.Name, kubeconfigStore.GetContextPrefix(discoveredContext.Path)) {
5656
contextWithoutPrefix = strings.TrimPrefix(discoveredContext.Name, fmt.Sprintf("%s/", kubeconfigStore.GetContextPrefix(discoveredContext.Path)))
5757
}
@@ -73,14 +73,7 @@ func SetContext(desiredContext string, stores []store.KubeconfigStore, config *t
7373
originalContextBeforeAlias = contextWithoutPrefix
7474
}
7575

76-
// only if the desired context matches the ContextWithoutPrefix, then use it to set the current context
77-
// otherwise, use the desiredContext
78-
currentContextToSet := desiredContext
79-
if matchesContextWithoutPrefix {
80-
currentContextToSet = contextWithoutPrefix
81-
}
82-
83-
if err := kubeconfig.SetContext(currentContextToSet, originalContextBeforeAlias, kubeconfigStore.GetContextPrefix(discoveredContext.Path)); err != nil {
76+
if err := kubeconfig.SetContext(contextWithoutPrefix, originalContextBeforeAlias, kubeconfigStore.GetContextPrefix(discoveredContext.Path)); err != nil {
8477
return nil, err
8578
}
8679

0 commit comments

Comments
 (0)