Skip to content

Commit

Permalink
Adding directory creation on custom kubeconfig location (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
bigtallcampbell authored Jul 22, 2024
1 parent 0560180 commit e0b3ab2
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion .devcontainer/features/k3s-on-host/updateContent.sh
Original file line number Diff line number Diff line change
Expand Up @@ -443,10 +443,17 @@ function gen_kubeconfig_for_devcontainer() {
# Update kubeconfig to use the external ip of the host instead of the default 127.0.0.1
kubeconfig="${kubeconfig/127.0.0.1/${host_ip}}"

run_a_script "tee $KUBECONFIG > /dev/null << UPDATE_END
if [[ -n "${KUBECONFIG}" ]] && [[ "${KUBECONFIG}" != "/etc/rancher/k3s/k3s.yaml" ]]; then
debug_log "Detected custom KUBECONFIG. Writing to custom location: '${KUBECONFIG}'"
kubeconfigDir="$(dirname "${KUBECONFIG}")"
[[ ! -d "${kubeconfigDir}" ]] && run_a_script "mkdir -p ${kubeconfigDir}" --disable_log

run_a_script "tee $KUBECONFIG > /dev/null << UPDATE_END
${kubeconfig}
UPDATE_END" --disable_log

fi

# Write the local kubeconfig to the default location in the devcontainer
[[ ! -d "/etc/rancher/k3s" ]] && run_a_script "mkdir -p /etc/rancher/k3s" --disable_log

Expand Down

0 comments on commit e0b3ab2

Please sign in to comment.