Skip to content

Commit 75113cd

Browse files
committed
Do not append cluster name twice
1 parent 8205d57 commit 75113cd

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

scripts/dev/rename-kubeconfig-ctx.jq

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
#!/usr/bin/env -S jq -f
2+
#
3+
# Pass JSON kubeconfig to this jq script to rename
4+
# the contexts to the referenced cluster names,
5+
# and the cluster names to the referenced user names.
6+
# This should help to merge kubeconfigs with non-unique
7+
# contexts and user names.
8+
#
29
. as $cfg
310
| (
411
# Build context_map as an array of objects with name transformations.
@@ -8,7 +15,11 @@
815
cluster: .context.cluster,
916
old_user: .context.user,
1017
new_name: .context.cluster,
11-
new_user: (.context.user + "@" + .context.cluster)
18+
new_user: (.context as $ctx
19+
| .context.user
20+
| (if endswith($ctx.cluster)
21+
then . else (. + "@" + $ctx.cluster) end)
22+
)
1223
})
1324
) as $context_map
1425
# Reconstruct the config from scratch.

0 commit comments

Comments
 (0)