Compare commits

...

4 Commits

5 changed files with 158 additions and 23 deletions

View File

@ -16,4 +16,4 @@
[log]
date = local
[init]
defaultBranch = master
defaultBranch = main

View File

@ -4,27 +4,106 @@ set -euo pipefail
IFS=$'\n\t'
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
: ${cpu:="500m"}
: ${memory:="2Gi"}
############## Setup #########################
overrides=""
if [ ! -z "${highmem:-}" ]; then
overrides=$(jq --compact-output '.' <<EOF
{
"spec": {
"tolerations": [
{
"key": "dedicated",
"operator": "Equal",
"value": "background-highmem",
"effect": "NoSchedule"
}
],
"nodeSelector": {"dedicated": "background-highmem"}
}
function cleanup {
for f in "${pods[@]}"; do
log "Deleting $f"
kubectl delete pod --force=true --grace-period=0 --namespace homepage "$f"
done
}
EOF
)
fi
pods=()
for sig in EXIT INT QUIT HUP TERM; do
trap "set +e; cleanup" "$sig"
done
exec kubectl run --rm -i -t --image alpine:3.13 --overrides="$overrides" --requests "cpu=$cpu,memory=$memory" --limits "cpu=$cpu,memory=$memory" --pod-running-timeout 10m "tom-$(uuidgen | cut -d '-' -f 1)" -- /bin/sh "$@"
function die {
local status_code="$1"
shift
(>&2 echo "${@}")
exit "$status_code"
}
function log {
(>&2 echo "${@}")
}
############## Program #########################
function main {
local pod_name="tom-$(uuidgen | cut -d '-' -f 1)"
pods+=("$pod_name")
create_pod "$pod_name"
kubectl wait pods -n homepage "$pod_name" --for condition=Ready --timeout=90s
kubectl exec -i -t --namespace homepage "$pod_name" -- "${@}"
}
function create_pod {
local pod_name="$1"
kubectl apply -f - <<EOF
apiVersion: v1
kind: Pod
metadata:
labels:
run: $pod_name
name: $pod_name
namespace: homepage
spec:
imagePullSecrets:
- name: registry-credentials
containers:
- args:
- /bin/sleep
- infinity
image: harbor.fizz.buzz/dockerhub/library/alpine:3.18
imagePullPolicy: IfNotPresent
name: $pod_name
stdin: true
stdinOnce: true
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
tty: true
volumeMounts:
- mountPath: /var/run/secrets/kubernetes.io/serviceaccount
name: kube-api-access-hskj7
readOnly: true
# serviceAccount: default
# serviceAccountName: default
terminationGracePeriodSeconds: 30
tolerations:
- effect: NoExecute
key: node.kubernetes.io/not-ready
operator: Exists
tolerationSeconds: 300
- effect: NoExecute
key: node.kubernetes.io/unreachable
operator: Exists
tolerationSeconds: 300
volumes:
- name: kube-api-access-hskj7
projected:
defaultMode: 420
sources:
- serviceAccountToken:
expirationSeconds: 3607
path: token
- configMap:
items:
- key: ca.crt
path: ca.crt
name: kube-root-ca.crt
- downwardAPI:
items:
- fieldRef:
apiVersion: v1
fieldPath: metadata.namespace
path: namespace
EOF
}
function delete_pod {
local pod_name="$1"
kubectl delete pod --force=true --grace-period=0 --namespace homepage "$pod_name"
}
main "$@"

View File

@ -0,0 +1,45 @@
#!/usr/bin/env bash
#
# Kill the virtual machines, take a snapshot, and start the virtual machines up again.
set -euo pipefail
IFS=$'\n\t'
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
############## Setup #########################
function die {
local status_code="$1"
shift
(>&2 echo "${@}")
exit "$status_code"
}
function log {
(>&2 echo "${@}")
}
############## Program #########################
function main {
snapshot_name="$1"
kill_all_bhyve
log "Taking snapshot $1"
for worker in worker0 worker1 worker2 controller0 controller1 controller2; do
doas zfs snapshot -r zdata/vm/${worker}/disk0@${snapshot_name}
done
doas zfs snapshot zdata/k8spersistent@${snapshot_name}
launch_all_bhyve
log "Done."
}
function kill_all_bhyve {
log "Killing all virtual machines."
doas killall bhyve; while true; do tmux ls || break; sleep 2; done;
}
function launch_all_bhyve {
log "Launching all virtual machines."
for vm in poudriere controller0 controller1 controller2 worker0 worker1 worker2; do tmux new -d -s $vm doas bhyve_netgraph_bridge start $vm zdata/vm/$vm /vm/$vm; sleep 5; done
}
main "$@"

View File

@ -39,3 +39,14 @@
group: wheel
loop:
- /k8spersistent
- name: Install scripts
copy:
src: "files/{{ item.src }}"
dest: "{{ item.dest }}"
mode: 0755
owner: root
group: wheel
loop:
- src: "k8s_snapshot.bash"
dest: /usr/local/bin/k8s_snapshot

View File

@ -14,4 +14,4 @@ export MOZ_ENABLE_WAYLAND=1
# Wayland seems enabled by default for qt5 with qt5-wayland installed but if a proprietary program bundles their own qt then I may have to set QT_QPA_PLATFORM="wayland;xcb"
# Wayland does not seem enabled for gtk apps and setting GDK_BACKEND=wayland did not change that.
exec ck-launch-session dbus-launch sway -d &> $HOME/.config/swaylog
exec ck-launch-session dbus-run-session sway -d &> $HOME/.config/swaylog