Skip to content
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

Improve devx of preview scripts #9758

Merged
merged 8 commits into from
May 4, 2022
2 changes: 1 addition & 1 deletion .gitpod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ ports:
tasks:
- name: Add Harvester kubeconfig
command: |
./dev/preview/download-and-merge-harvester-kubeconfig.sh
./dev/preview/util/download-and-merge-harvester-kubeconfig.sh
exit 0
- name: Java
init: |
Expand Down
15 changes: 9 additions & 6 deletions dev/preview/install-k3s-kubeconfig.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,23 @@

set -euo pipefail

source ./dev/preview/util/preview-name-from-branch.sh
THIS_DIR="$(dirname "$0")"

source "$THIS_DIR/util/preview-name-from-branch.sh"

VM_NAME="$(preview-name-from-branch)"
if [[ -z "${VM_NAME:-}" ]]; then
VM_NAME="$(preview-name-from-branch)"
fi

PRIVATE_KEY=$HOME/.ssh/vm_id_rsa
PUBLIC_KEY=$HOME/.ssh/vm_id_rsa.pub
THIS_DIR="$(dirname "$0")"
USER="ubuntu"

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

K3S_CONTEXT="k3s-preview-environment"
K3S_CONTEXT="${VM_NAME}"
K3S_ENDPOINT="${VM_NAME}.kube.gitpod-dev.com"

while getopts n:p:u: flag
Expand All @@ -34,15 +37,15 @@ function log {
function set-up-ssh {
if [[ (! -f $PRIVATE_KEY) || (! -f $PUBLIC_KEY) ]]; then
log Setting up ssh-keys
"$THIS_DIR"/install-vm-ssh-keys.sh
"$THIS_DIR"/util/install-vm-ssh-keys.sh
fi
}

set-up-ssh

"$THIS_DIR"/ssh-vm.sh \
-c "sudo cat /etc/rancher/k3s/k3s.yaml" \
| sed 's/default/'${K3S_CONTEXT}'/g' \
| sed "s/default/${K3S_CONTEXT}/g" \
| sed -e 's/127.0.0.1/'"${K3S_ENDPOINT}"'/g' \
> "${K3S_KUBECONFIG_PATH}"

Expand Down
5 changes: 5 additions & 0 deletions dev/preview/list-vms.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

set -eup pipefail

kubectl --context=harvester get vms -A -o=jsonpath='{.items[*].metadata.name}' | xargs -n 1 echo
4 changes: 2 additions & 2 deletions dev/preview/portforward-monitoring-satellite.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ done


if [[ $CONTEXT == 'core-dev' ]]; then
"$THIS_DIR"/portforward-monitoring-satellite-core-dev.sh
"$THIS_DIR"/util/portforward-monitoring-satellite-core-dev.sh
elif [[ $CONTEXT == 'harvester' ]]; then
"$THIS_DIR"/portforward-monitoring-satellite-harvester.sh
"$THIS_DIR"/util/portforward-monitoring-satellite-harvester.sh
else
log "Error: context should be one of the following: ['core-dev', 'harvester']"
log "Usage: './dev/preview/portforward-monitoring-satellite.sh -c harvester' or './dev/preview/portforward-monitoring-satellite.sh -c core-dev'"
Expand Down
17 changes: 10 additions & 7 deletions dev/preview/ssh-vm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@

set -euo pipefail

source ./dev/preview/util/preview-name-from-branch.sh
THIS_DIR="$(dirname "$0")"

VM_NAME="$(preview-name-from-branch)"
NAMESPACE="preview-${VM_NAME}"
source "$THIS_DIR/util/preview-name-from-branch.sh"

if [[ -z "${VM_NAME:-}" ]]; then
VM_NAME="$(preview-name-from-branch)"
fi

NAMESPACE="preview-${VM_NAME}"
PRIVATE_KEY=$HOME/.ssh/vm_id_rsa
PUBLIC_KEY=$HOME/.ssh/vm_id_rsa.pub
PORT=8022
THIS_DIR="$(dirname "$0")"
USER="ubuntu"
COMMAND=""

Expand Down Expand Up @@ -41,13 +44,13 @@ function has-harvester-access {
function set-up-ssh {
if [[ (! -f $PRIVATE_KEY) || (! -f $PUBLIC_KEY) ]]; then
echo Setting up ssh-keys
"$THIS_DIR"/install-vm-ssh-keys.sh
"$THIS_DIR"/util/install-vm-ssh-keys.sh
fi
}

if ! has-harvester-access; then
echo Setting up kubeconfig
"$THIS_DIR"/download-and-merge-harvester-kubeconfig.sh
"$THIS_DIR"/util/download-and-merge-harvester-kubeconfig.sh
fi

set-up-ssh
Expand All @@ -56,7 +59,7 @@ ssh "$USER"@127.0.0.1 \
-o UserKnownHostsFile=/dev/null \
-o StrictHostKeyChecking=no \
-o LogLevel=ERROR \
-o "ProxyCommand=$THIS_DIR/ssh-proxy-command.sh -p $PORT -n $NAMESPACE -v $VM_NAME" \
-o "ProxyCommand=$THIS_DIR/util/ssh-proxy-command.sh -p $PORT -n $NAMESPACE -v $VM_NAME" \
-i "$HOME/.ssh/vm_id_rsa" \
-p "$PORT" \
"$COMMAND"
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ do
esac
done

// We don't delete the namespace "distribute-${IMAGEID} because we want to avoid
// images from being garbage collected
# We don't delete the namespace "distribute-${IMAGEID} because we want to avoid
# images from being garbage collected
NODES=$(kubectl get nodes -o=jsonpath='{.items[*].metadata.name}')
NAMESPACE="distribute-${IMAGEID}"

Expand Down Expand Up @@ -78,4 +78,4 @@ spec:
persistentVolumeClaim:
claimName: ${PVC}
YAML
done
done
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
# Exposes Prometheus and Grafana's UI
#

source ./dev/preview/util/preview-name-from-branch.sh
THIS_DIR="$(dirname "$0")"

source "$THIS_DIR/preview-name-from-branch.sh"

PREVIEW_NAME="$(preview-name-from-branch)"
NAMESPACE="staging-${PREVIEW_NAME}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@
# Exposes Prometheus and Grafana's UI
#

source ./dev/preview/util/preview-name-from-branch.sh
THIS_DIR="$(dirname "$0")"

source "$THIS_DIR/preview-name-from-branch.sh"

if [[ -z "${VM_NAME:-}" ]]; then
VM_NAME="$(preview-name-from-branch)"
fi

VM_NAME="$(preview-name-from-branch)"
NAMESPACE="preview-${VM_NAME}"

function log {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
#!/usr/bin/env bash

source ./dev/preview/util/preview-name-from-branch.sh

VM_NAME="$(preview-name-from-branch)"
NAMESPACE="preview-${VM_NAME}"

while getopts n:p:v: flag
do
case "${flag}" in
Expand All @@ -15,6 +10,13 @@ do
esac
done

if [[ -z "${VM_NAME:-}" ]]; then
echo "VM_NAME not specified"
exit 1
fi

NAMESPACE="preview-${VM_NAME}"

pkill -f "kubectl --context=harvester (.*)${PORT}:2200"
kubectl \
--context=harvester \
Expand Down