Skip to content

Commit

Permalink
Allow preserve structure in import
Browse files Browse the repository at this point in the history
Fix #21
  • Loading branch information
yujunz committed Sep 10, 2020
1 parent a335c4f commit 3d749a7
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions konfig
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ USAGE:
Merge multiple kubeconfigs into one.
-p prevents flattening which will make the result less portable.
konfig import [--save,-s] <CONFIG>..
konfig import [--save,-s] [--preserve-structure,-p] <CONFIG>..
Import the given configs into your current kubeconfig (respects KUBECONFIG env var).
-s writes the result to your ~/.kube/config
Expand Down Expand Up @@ -86,20 +86,20 @@ merge() {
import_ctx() {
local tmpcfg
local out=""
if [[ "${1}" = '--save' || "$1" = '-s' ]]; then
if [[ "$1" = '--save' || "$1" = '-s' ]]; then
out="${XDG_CACHE_HOME:-$HOME/.kube}/config"
shift 1
elif [[ "${1}" =~ ^-(.*) ]]; then
elif [[ "$1" =~ ^-(.*) && "$1" != '-p' && "$1" != '--preserve-structure' ]]; then
error "unrecognized flag \"$1\""
fi
tmpcfg=$(mktemp konfig_XXXXXX)
TMPFILES+=( "$tmpcfg" )
$KUBECTL config view --flatten > "$tmpcfg"
$KUBECTL config view --raw > "$tmpcfg"

if [[ -z "$out" ]]; then
merge "$tmpcfg" "$@"
merge "$@" "$tmpcfg"
else
merge "$tmpcfg" "$@" > "$out"
merge "$@" "$tmpcfg" > "$out"
fi
}

Expand Down

0 comments on commit 3d749a7

Please sign in to comment.