Skip to content

Commit

Permalink
chore: update multiple kubeconfig merge logic
Browse files Browse the repository at this point in the history
Signed-off-by: Vibhu Prashar <[email protected]>
  • Loading branch information
vprashar2929 committed Nov 22, 2023
1 parent 8d635ff commit dfe6655
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
19 changes: 9 additions & 10 deletions main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,16 @@ cluster_up() {
local kubeconfig
kubeconfig="$("${CLUSTER_PROVIDER}"_kubeconfig)"

mkdir -p "$(basename "$KUBECONFIG_ROOT_DIR"/)"
mv -f "$kubeconfig" "$KUBECONFIG_ROOT_DIR"/"$KEPLER_KUBECONFIG"

kubeconfig=$(find "$KUBECONFIG_ROOT_DIR" -type f -name "*config*" | tr '\n' ':')
KUBECONFIG=$kubeconfig kubectl config view --flatten > all-in-one-kubeconfig.yaml
mv -f all-in-one-kubeconfig.yaml "$KUBECONFIG_ROOT_DIR"/config
export KUBECONFIG="$KUBECONFIG_ROOT_DIR"/config
mkdir -p "$(basename "$KUBECONFIG_ROOT_DIR")"
mv -f "$kubeconfig" "${KUBECONFIG_ROOT_DIR}/${KEPLER_KUBECONFIG}"

kubectl config --kubeconfig="$KUBECONFIG" set-cluster kind-kepler
kubeconfig="$KUBECONFIG_ROOT_DIR/config":$(find "$KUBECONFIG_ROOT_DIR" \
-type f -name "*config*" | tr '\n' ':')
kubeconfig=${kubeconfig%:}
KUBECONFIG=$kubeconfig kubectl config view --merge --flatten >all-in-one-kubeconfig.yaml
mv -f all-in-one-kubeconfig.yaml "${KUBECONFIG_ROOT_DIR}/config"

export KUBECONFIG="${KUBECONFIG_ROOT_DIR}/config"

if is_set "$PROMETHEUS_ENABLE" || is_set "$GRAFANA_ENABLE"; then
source "$PROJECT_ROOT/lib/prometheus.sh"
Expand All @@ -80,8 +81,6 @@ cluster_up() {
cluster_down() {
"$CLUSTER_PROVIDER"_down
rm "$KUBECONFIG_ROOT_DIR/$KEPLER_KUBECONFIG"
export KUBECONFIG="$KUBECONFIG_ROOT_DIR"/config
kubectl --kubeconfig="$KUBECONFIG" config unset clusters.kind-kepler
}

print_config() {
Expand Down
2 changes: 1 addition & 1 deletion providers/kind/kind.sh
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ _setup_kind() {
run kind create cluster --name="${KIND_CLUSTER_NAME}" -v6 --config="$KIND_CONFIG_YAML"

info "Generating kubeconfig"
kind get kubeconfig --name="${KIND_CLUSTER_NAME}" | sed 's/kind-kind/kind-kepler/' > "$KIND_KUBECONFIG"
kind get kubeconfig --name="${KIND_CLUSTER_NAME}" >"$KIND_KUBECONFIG"

# NOTE: all providers are expected to
ok "copied kubeconfig to $KIND_KUBECONFIG"
Expand Down

0 comments on commit dfe6655

Please sign in to comment.