summaryrefslogtreecommitdiff
path: root/playbooks.d/k3s-master/playbook.bash
diff options
context:
space:
mode:
Diffstat (limited to 'playbooks.d/k3s-master/playbook.bash')
-rw-r--r--playbooks.d/k3s-master/playbook.bash65
1 files changed, 65 insertions, 0 deletions
diff --git a/playbooks.d/k3s-master/playbook.bash b/playbooks.d/k3s-master/playbook.bash
new file mode 100644
index 0000000..cc6cd29
--- /dev/null
+++ b/playbooks.d/k3s-master/playbook.bash
@@ -0,0 +1,65 @@
+#!/usr/bin/env bash
+
+playbook_add() {
+ # TODO: Install kubectl, helm!
+ info "$BASHTARD_PLAYBOOK" "Installing k3s"
+ curl -sfL https://get.k3s.io | sh - # I hate this
+
+ notice "$BASHTARD_PLAYBOOK" "Creating data directories"
+ mkdir -pv -- "$(playbook_path "data")/manifests.d"
+ mkdir -pv -- "$(playbook_path "data")/helm.d"
+
+ notice "$BASHTARD_PLAYBOOK" "Waiting for node to become available"
+ { grep -q -m 1 "${BASHTARD_PLATFORM[fqdn]}[[:space:]]\+Ready"; kill $!; } < <(k3s kubectl get node -w)
+
+ playbook_sync
+}
+
+playbook_sync() {
+ local data
+ local helm_cmd
+ local kubeconfig
+
+ data="$(playbook_path "data")"
+ kubeconfig="$(config "fs.etcdir")/rancher/k3s/k3s.yaml"
+
+ notice "$BASHTARD_PLAYBOOK/manifests" "Applying manifests.d"
+ kubectl --kubeconfig "$kubeconfig" apply --recursive --filename "$data/manifests.d"
+
+ notice "$BASHTARD_PLAYBOOK/helm" "Ensure all Helm repos exist"
+ while read -r repo
+ do
+ helm repo add "$repo" "$(config "$BASHTARD_PLAYBOOK.helm.repos.$repo.url")"
+ done < <(config_subkeys "$BASHTARD_PLAYBOOK.helm.repos")
+
+ notice "$BASHTARD_PLAYBOOK/helm" "Updating Helm repository contents"
+ helm repo update
+
+ notice "$BASHTARD_PLAYBOOK/helm" "Upgrading Helm charts"
+ while read -r app
+ do
+ helm_cmd=(
+ "helm" "upgrade"
+ "--install"
+ "--kubeconfig" "$kubeconfig"
+ "--timeout" "$(config "$BASHTARD_PLAYBOOK.helm.timeout" "30s")"
+ "--namespace" "$(config "$BASHTARD_PLAYBOOK.helm.apps.$app.namespace" "default")"
+ )
+
+ # Add values
+ helm_cmd+=("--values" "$data/helm.d/$(config "$BASHTARD_PLAYBOOK.helm.apps.$app.values")")
+
+ # Set which chart to upgrade
+ helm_cmd+=("$app")
+ helm_cmd+=("$(config "$BASHTARD_PLAYBOOK.helm.apps.$app.repo")/$(config "$BASHTARD_PLAYBOOK.helm.apps.$app.chart")")
+
+ notice "$BASHTARD_PLAYBOOK/helm/$app" "> ${helm_cmd[*]}"
+ ${helm_cmd[@]}
+
+ unset helm_cmd
+ done < <(config_subkeys "$BASHTARD_PLAYBOOK.helm.apps")
+}
+
+playbook_del() {
+ /usr/local/bin/k3s-uninstall.sh
+}