#!/usr/bin/env bash playbook_add() { pkg install curl info "$BASHTARD_PLAYBOOK/add" "Writing config.yaml for k3s" mkdir -pv -- /etc/rancher/k3s { cat <<-EOF node-name: "${BASHTARD_PLATFORM[fqdn]}" node-ip: "$(config "$BASHTARD_PLAYBOOK.internal-ip" "127.0.0.1")" bind-address: "$(config "$BASHTARD_PLAYBOOK.bind-address" "0.0.0.0")" cluster-cidr: "$(config "$BASHTARD_PLAYBOOK.cluster-cidr" "172.19.0.0/16")" service-cidr: "$(config "$BASHTARD_PLAYBOOK.service-cidr" "172.20.0.0/16")" cluster-domain: "$(config "$BASHTARD_PLAYBOOK.cluster-domain" "cluster.local")" service-node-port-range: "$(config "$BASHTARD_PLAYBOOK.service-node-port-min" "30000")-$(config "$BASHTARD_PLAYBOOK.service-node-port-max" "32767")" flannel-ipv6-masq: true disable: - traefik EOF if [[ -n "$(config_subkeys "$BASHTARD_PLAYBOOK.flannel.interfaces")" ]] then printf "flannel-iface:\n" while read -r iface do printf -- "- %s\n" "$(config "$BASHTARD_PLAYBOOK.flannel.interfaces.$iface")" done < <( config_subkeys "$BASHTARD_PLAYBOOK.flannel.interfaces" ) fi if [[ -n "$(config "$BASHTARD_PLAYBOOK.external-ip" "")" ]] then printf "%s: \"%s\"\n" "node-external-ip" "$(config "$BASHTARD_PLAYBOOK.external-ip" "")" fi } > "$(config "fs.etcdir")/rancher/k3s/config.yaml" info "$BASHTARD_PLAYBOOK/add" "Installing k3s" curl -sfL https://get.k3s.io | sh -s - server --cluster-init # I hate this notice "$BASHTARD_PLAYBOOK/add" "Creating data directories" mkdir -pv -- "$(playbook_path "data")/manifests.d" notice "$BASHTARD_PLAYBOOK/add" "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 kubeconfig local manifest_prefix local values data="$(playbook_path "data")" kubeconfig="$(config "fs.etcdir")/rancher/k3s/k3s.yaml" notice "$BASHTARD_PLAYBOOK/sync" "Applying manifests.d" kubectl --kubeconfig "$kubeconfig" apply --recursive --filename "$data/manifests.d" || true } playbook_del() { /usr/local/bin/k3s-uninstall.sh }