summaryrefslogtreecommitdiff
path: root/playbooks.d/k3s-node/playbook.bash
blob: 540dccd9795b8ed1012e83483308c2ca863511c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env bash

BASHTARD_PLAYBOOK_VARS[$BASHTARD_PLAYBOOK.entry.host]="required"
BASHTARD_PLAYBOOK_VARS[$BASHTARD_PLAYBOOK.entry.token]="required"

playbook_add() {
	pkg install curl nfs-common

	info "$BASHTARD_PLAYBOOK" "Writing config.yaml for k3s"
	mkdir -pv -- /etc/rancher/k3s
	cat <<-EOF > /etc/rancher/k3s/config.yaml
	cluster-cidr: "$(config "$BASHTARD_PLAYBOOK.cluster-cidr" "172.19.0.0/16")"
	cluster-domain: "$(config "$BASHTARD_PLAYBOOK.cluster-domain" "cluster.local")"
	node-ip: "$(config "$BASHTARD_PLAYBOOK.node-ip" "$(config "bashtard.ssh.host")")"
	node-name: "${BASHTARD_PLATFORM[fqdn]}"
	server: "https://$(config "$BASHTARD_PLAYBOOK.entry.host"):$(config "$BASHTARD_PLAYBOOK.entry.port" "6443")"
	service-cidr: "$(config "$BASHTARD_PLAYBOOK.service-cidr" "172.20.0.0/16")"
	service-node-port-range: "$(config "$BASHTARD_PLAYBOOK.service-node-port-min" "30000")-$(config "$BASHTARD_PLAYBOOK.service-node-port-max" "32767")"
	token: "$(config "$BASHTARD_PLAYBOOK.entry.token")"
	EOF

	info "$BASHTARD_PLAYBOOK" "Installing k3s"
	curl -sfL https://get.k3s.io | sh -s - "$(config "$BASHTARD_PLAYBOOK.role" "agent")"

	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_del() {
	/usr/local/bin/k3s-uninstall.sh
}