Skip to content

Commit c732acb

Browse files
mads-hartmannroboquat
authored andcommitted
Add Harvester kubectl context to kubeconfig
1 parent ebf03b0 commit c732acb

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

.gitpod.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ ports:
2525
# Dev Theia
2626
- port: 13444
2727
tasks:
28+
- name: Add Harvester kubeconfig
29+
command: |
30+
./dev/preview/download-and-merge-harvester-kubeconfig.sh
31+
exit 0
2832
- name: Java
2933
init: |
3034
leeway exec --package components/supervisor-api/java:lib --package components/gitpod-protocol/java:lib -- ./gradlew build
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
function log {
6+
echo "[$(date)] $*"
7+
}
8+
9+
function has-dev-access {
10+
kubectl --context=dev auth can-i get secrets > /dev/null 2>&1 || false
11+
}
12+
13+
if ! has-dev-access; then
14+
log "The workspace isn't configured to have core-dev access. Exiting."
15+
exit 0
16+
fi
17+
18+
KUBECONFIG_PATH="/home/gitpod/.kube/config"
19+
HARVESTER_KUBECONFIG_PATH="$(mktemp)"
20+
MERGED_KUBECONFIG_PATH="$(mktemp)"
21+
22+
log "Downloading and preparing Harvester kubeconfig"
23+
kubectl -n werft get secret harvester-kubeconfig -o jsonpath='{.data}' \
24+
| jq -r '.["harvester-kubeconfig.yml"]' \
25+
| base64 -d \
26+
| sed 's/default/harvester/g' \
27+
> "${HARVESTER_KUBECONFIG_PATH}"
28+
29+
# Order of files is important, we have the original config first so we preserve
30+
# the value of current-context
31+
log "Merging kubeconfig files ${KUBECONFIG_PATH} ${HARVESTER_KUBECONFIG_PATH} into ${MERGED_KUBECONFIG_PATH}"
32+
KUBECONFIG="${KUBECONFIG_PATH}:${HARVESTER_KUBECONFIG_PATH}" \
33+
kubectl config view --flatten --merge > "${MERGED_KUBECONFIG_PATH}"
34+
35+
log "Overwriting ${KUBECONFIG_PATH}"
36+
mv "${MERGED_KUBECONFIG_PATH}" "${KUBECONFIG_PATH}"
37+
38+
log "Cleaning up temporay Harveter kubeconfig"
39+
rm "${HARVESTER_KUBECONFIG_PATH}"
40+
41+
log "Done"

0 commit comments

Comments
 (0)