Fix completion of context (#7389)

Fix completion of context to use context name rather than cluster name

Fixes #7362

Signed-off-by: Takumi Sue <u630868b@alumni.osaka-u.ac.jp>
This commit is contained in:
Takumi Sue 2021-12-03 19:26:28 +09:00 committed by GitHub
parent 4170b49b33
commit 45349dd4db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 7 deletions

View File

@ -113,13 +113,12 @@ func ConfigureKubeContextFlagCompletion(cmd *cobra.Command, kubeconfigPath strin
}
suggestions := []string{}
uniqClusters := map[string]struct{}{}
for _, ctx := range config.Contexts {
clusterName := ctx.Cluster
if strings.HasPrefix(clusterName, toComplete) {
if _, ok := uniqClusters[clusterName]; !ok {
suggestions = append(suggestions, ctx.Cluster)
uniqClusters[clusterName] = struct{}{}
uniqContexts := map[string]struct{}{}
for ctxName := range config.Contexts {
if strings.HasPrefix(ctxName, toComplete) {
if _, ok := uniqContexts[ctxName]; !ok {
suggestions = append(suggestions, ctxName)
uniqContexts[ctxName] = struct{}{}
}
}
}