Skip to content

Add Harvester to workspace kubeconfig #7456

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitpod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ ports:
# Dev Theia
- port: 13444
tasks:
- name: Add Harvester kubeconfig
command: |
./dev/preview/download-and-merge-harvester-kubeconfig.sh
exit 0
- name: Java
init: |
leeway exec --package components/supervisor-api/java:lib --package components/gitpod-protocol/java:lib -- ./gradlew build
Expand Down
41 changes: 41 additions & 0 deletions dev/preview/download-and-merge-harvester-kubeconfig.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env bash

set -euo pipefail

function log {
echo "[$(date)] $*"
}

function has-dev-access {
kubectl --context=dev auth can-i get secrets > /dev/null 2>&1 || false
}

if ! has-dev-access; then
log "The workspace isn't configured to have core-dev access. Exiting."
exit 0
fi

KUBECONFIG_PATH="/home/gitpod/.kube/config"
HARVESTER_KUBECONFIG_PATH="$(mktemp)"
MERGED_KUBECONFIG_PATH="$(mktemp)"

log "Downloading and preparing Harvester kubeconfig"
kubectl -n werft get secret harvester-kubeconfig -o jsonpath='{.data}' \
| jq -r '.["harvester-kubeconfig.yml"]' \
| base64 -d \
| sed 's/default/harvester/g' \
> "${HARVESTER_KUBECONFIG_PATH}"

# Order of files is important, we have the original config first so we preserve
# the value of current-context
log "Merging kubeconfig files ${KUBECONFIG_PATH} ${HARVESTER_KUBECONFIG_PATH} into ${MERGED_KUBECONFIG_PATH}"
KUBECONFIG="${KUBECONFIG_PATH}:${HARVESTER_KUBECONFIG_PATH}" \
kubectl config view --flatten --merge > "${MERGED_KUBECONFIG_PATH}"

log "Overwriting ${KUBECONFIG_PATH}"
mv "${MERGED_KUBECONFIG_PATH}" "${KUBECONFIG_PATH}"

log "Cleaning up temporay Harveter kubeconfig"
rm "${HARVESTER_KUBECONFIG_PATH}"

log "Done"