2024-06-18 12:06:23 -05:00
|
|
|
---
|
|
|
|
# yaml-language-server: $schema=https://taskfile.dev/schema.json
|
|
|
|
version: "3"
|
|
|
|
|
2024-09-05 00:00:06 -05:00
|
|
|
vars:
|
|
|
|
RESOURCES_DIR: "{{.ROOT_DIR}}/.taskfiles/talos/resources"
|
|
|
|
CONTROLLER:
|
|
|
|
sh: talosctl --context {{.cluster}} config info --output json | jq --raw-output '.endpoints[]' | shuf -n 1
|
|
|
|
cluster: theshire
|
|
|
|
|
2024-06-18 12:06:23 -05:00
|
|
|
tasks:
|
|
|
|
bootstrap:
|
|
|
|
desc: Bootstrap Talos
|
|
|
|
summary: |
|
|
|
|
Args:
|
2024-09-04 13:35:14 -05:00
|
|
|
cluster: Cluster to run command against (default: theshire)
|
2024-06-18 12:06:23 -05:00
|
|
|
controller: Controller node to run command against (required) (IP/DNS)
|
2024-09-05 00:00:06 -05:00
|
|
|
dotenv: ["{{.RESOURCES_DIR}}/.env"]
|
2024-06-18 12:06:23 -05:00
|
|
|
prompt: Bootstrap Talos on the cluster... continue?
|
|
|
|
cmds:
|
|
|
|
- task: bootstrap-etcd
|
|
|
|
vars: &vars
|
|
|
|
controller: "{{.controller}}"
|
|
|
|
- task: fetch-kubeconfig
|
|
|
|
vars: *vars
|
|
|
|
- task: bootstrap-integrations
|
|
|
|
vars: *vars
|
|
|
|
requires:
|
|
|
|
vars:
|
|
|
|
- controller
|
|
|
|
|
|
|
|
bootstrap-etcd:
|
|
|
|
desc: Bootstrap Etcd
|
2024-09-05 00:00:06 -05:00
|
|
|
dotenv: ["{{.RESOURCES_DIR}}/.env"]
|
|
|
|
cmd: until talosctl --context $CLUSTER --nodes {{.controller}} bootstrap; do sleep 10; done
|
2024-06-18 12:06:23 -05:00
|
|
|
requires:
|
|
|
|
vars:
|
|
|
|
- controller
|
|
|
|
|
|
|
|
bootstrap-integrations:
|
|
|
|
desc: Bootstrap core integrations needed for Talos
|
2024-09-05 00:00:06 -05:00
|
|
|
dotenv: ["{{.RESOURCES_DIR}}/.env"]
|
2024-06-18 12:06:23 -05:00
|
|
|
cmds:
|
2024-09-05 00:00:06 -05:00
|
|
|
- until kubectl --context $CLUSTER wait --for=condition=Ready=False nodes --all --timeout=600s; do sleep 10; done
|
|
|
|
- helmfile --kube-context $CLUSTER --file {{.KUBERNETES_DIR}}/bootstrap/helmfile.yaml apply --skip-diff-on-install --suppress-diff
|
|
|
|
- until kubectl --context $CLUSTER wait --for=condition=Ready nodes --all --timeout=600s; do sleep 10; done
|
2024-06-18 12:06:23 -05:00
|
|
|
preconditions:
|
|
|
|
- which helmfile
|
2024-09-05 00:00:06 -05:00
|
|
|
- sh: kubectl config get-contexts $CLUSTER
|
|
|
|
msg: "Kubectl context $CLUSTER not found"
|
2024-06-18 12:06:23 -05:00
|
|
|
- test -f {{.KUBERNETES_DIR}}/bootstrap/helmfile.yaml
|
|
|
|
|
|
|
|
fetch-kubeconfig:
|
|
|
|
desc: Fetch kubeconfig from Talos controllers
|
2024-09-05 00:00:06 -05:00
|
|
|
dotenv: ["{{.RESOURCES_DIR}}/.env"]
|
|
|
|
env: *vars
|
2024-06-18 12:06:23 -05:00
|
|
|
cmd: |
|
2024-09-05 00:00:06 -05:00
|
|
|
talosctl --context $CLUSTER kubeconfig --nodes {{ .CONTROLLER }} \
|
|
|
|
--force --force-context-name $CLUSTER {{.ROOT_DIR}}/kubeconfig
|
2024-06-18 12:06:23 -05:00
|
|
|
preconditions:
|
2024-09-05 00:00:06 -05:00
|
|
|
- talosctl config get-contexts | grep $CLUSTER
|
2024-06-18 12:06:23 -05:00
|
|
|
|
|
|
|
generate-clusterconfig:
|
|
|
|
desc: Generate clusterconfig for Talos
|
2024-09-05 00:00:06 -05:00
|
|
|
dotenv: ["{{.RESOURCES_DIR}}/.env"]
|
2024-06-18 12:06:23 -05:00
|
|
|
cmds:
|
|
|
|
- talhelper genconfig
|
|
|
|
--env-file {{.KUBERNETES_DIR}}/bootstrap/talos/talenv.sops.yaml
|
|
|
|
--secret-file {{.KUBERNETES_DIR}}/bootstrap/talos/talsecret.sops.yaml
|
|
|
|
--config-file {{.KUBERNETES_DIR}}/bootstrap/talos/talconfig.yaml
|
|
|
|
--out-dir {{.KUBERNETES_DIR}}/bootstrap/talos/clusterconfig
|
|
|
|
preconditions:
|
|
|
|
- which talhelper
|
|
|
|
- test -f {{.KUBERNETES_DIR}}/bootstrap/talos/talenv.sops.yaml
|
|
|
|
- test -f {{.KUBERNETES_DIR}}/bootstrap/talos/talsecret.sops.yaml
|
|
|
|
- test -f {{.KUBERNETES_DIR}}/bootstrap/talos/talconfig.yaml
|
|
|
|
|
|
|
|
upgrade:
|
|
|
|
desc: Upgrade Talos version for a node
|
2024-09-05 00:00:06 -05:00
|
|
|
dotenv: ["{{.RESOURCES_DIR}}/.env"]
|
2024-06-18 12:06:23 -05:00
|
|
|
vars:
|
|
|
|
TALOS_VERSION:
|
|
|
|
sh: |
|
|
|
|
yq -r ".talosVersion" {{.KUBERNETES_DIR}}/bootstrap/talos/talconfig.yaml
|
|
|
|
TALOS_IMAGE:
|
|
|
|
sh: |
|
|
|
|
talhelper genurl installer \
|
|
|
|
--env-file {{.KUBERNETES_DIR}}/bootstrap/talos/talenv.sops.yaml \
|
|
|
|
--config-file {{.KUBERNETES_DIR}}/bootstrap/talos/talconfig.yaml
|
|
|
|
cmds:
|
2024-09-05 00:00:06 -05:00
|
|
|
- talosctl --context $CLUSTER upgrade -n {{.node}} --image {{.TALOS_IMAGE }}
|
2024-06-18 12:06:23 -05:00
|
|
|
requires:
|
|
|
|
vars:
|
|
|
|
- node
|
|
|
|
preconditions:
|
|
|
|
- which talhelper
|
2024-09-05 00:00:06 -05:00
|
|
|
- talosctl config get-contexts | grep $CLUSTER
|
2024-06-18 12:06:23 -05:00
|
|
|
- test -f {{.KUBERNETES_DIR}}/bootstrap/talos/talenv.sops.yaml
|
|
|
|
- test -f {{.KUBERNETES_DIR}}/bootstrap/talos/talconfig.yaml
|
|
|
|
- msg: "Talos image could not be determined for {{.node}}"
|
|
|
|
sh: 'test -n "{{.TALOS_IMAGE}}"'
|
|
|
|
|
|
|
|
upgrade-k8s:
|
|
|
|
desc: Upgrade Kubernetes version for a Talos cluster
|
2024-09-05 00:00:06 -05:00
|
|
|
dotenv: ["{{.RESOURCES_DIR}}/.env"]
|
2024-06-18 12:06:23 -05:00
|
|
|
vars:
|
|
|
|
KUBERNETES_VERSION:
|
|
|
|
sh: |
|
|
|
|
yq -r ".kubernetesVersion" {{.KUBERNETES_DIR}}/bootstrap/talos/talconfig.yaml
|
|
|
|
CONTROLPLANE_NODE:
|
|
|
|
sh: |
|
2024-09-05 00:00:06 -05:00
|
|
|
talosctl --context $CLUSTER config info \
|
2024-06-18 12:06:23 -05:00
|
|
|
| grep Endpoints: \
|
|
|
|
| awk '{split($0,u," "); print u[2]}' \
|
|
|
|
| sed -E 's/,//'
|
|
|
|
cmds:
|
|
|
|
- talosctl upgrade-k8s -n {{.CONTROLPLANE_NODE}} --to {{.KUBERNETES_VERSION}}
|
|
|
|
preconditions:
|
|
|
|
- which talhelper
|
2024-09-05 00:00:06 -05:00
|
|
|
- talosctl config get-contexts | grep $CLUSTER
|
2024-06-18 12:06:23 -05:00
|
|
|
- test -f {{.KUBERNETES_DIR}}/bootstrap/talos/talenv.sops.yaml
|
|
|
|
- test -f {{.KUBERNETES_DIR}}/bootstrap/talos/talconfig.yaml
|
2024-09-05 00:00:06 -05:00
|
|
|
- msg: "Kubernetes version could not be determined for cluster $CLUSTER"
|
2024-06-18 12:06:23 -05:00
|
|
|
sh: 'test -n "{{.KUBERNETES_VERSION}}"'
|
2024-09-05 00:00:06 -05:00
|
|
|
- msg: "Control plane node could not be determined for cluster $CLUSTER"
|
2024-06-18 12:06:23 -05:00
|
|
|
sh: 'test -n "{{.CONTROLPLANE_NODE}}"'
|
|
|
|
|
|
|
|
apply-clusterconfig:
|
|
|
|
desc: Apply clusterconfig for a Talos cluster
|
2024-09-05 00:00:06 -05:00
|
|
|
dotenv: ["{{.RESOURCES_DIR}}/.env"]
|
2024-06-18 12:06:23 -05:00
|
|
|
vars:
|
|
|
|
CLUSTERCONFIG_FILES:
|
|
|
|
sh: find {{.KUBERNETES_DIR}}/bootstrap/talos/clusterconfig -type f -name '*.yaml' -printf '%f\n'
|
|
|
|
cmds:
|
|
|
|
- for:
|
|
|
|
var: CLUSTERCONFIG_FILES
|
|
|
|
task: _apply-machineconfig
|
|
|
|
vars:
|
|
|
|
filename: "{{.ITEM}}"
|
|
|
|
hostname: |-
|
|
|
|
{{ trimPrefix (printf "%s-" .cluster) .ITEM | trimSuffix ".yaml" }}
|
|
|
|
dry_run: "{{ .dry_run }}"
|
|
|
|
preconditions:
|
2024-09-05 00:00:06 -05:00
|
|
|
- talosctl config get-contexts | grep $CLUSTER
|
2024-06-18 12:06:23 -05:00
|
|
|
- test -d {{.KUBERNETES_DIR}}/bootstrap/talos/clusterconfig
|
|
|
|
|
|
|
|
_apply-machineconfig:
|
|
|
|
internal: true
|
|
|
|
desc: Apply a single Talos machineConfig to a Talos node
|
2024-09-05 00:00:06 -05:00
|
|
|
dotenv: ["{{.RESOURCES_DIR}}/.env"]
|
2024-06-18 12:06:23 -05:00
|
|
|
cmds:
|
2024-09-05 00:00:06 -05:00
|
|
|
- talosctl --context theshire apply-config
|
2024-06-18 12:06:23 -05:00
|
|
|
--nodes "{{.hostname}}"
|
|
|
|
--file "{{.KUBERNETES_DIR}}/bootstrap/talos/clusterconfig/{{.filename}}"
|
|
|
|
{{ if eq "true" .dry_run }}--dry-run{{ end }}
|
2024-09-04 13:35:14 -05:00
|
|
|
#--insecure
|
2024-06-18 12:06:23 -05:00
|
|
|
requires:
|
|
|
|
vars:
|
|
|
|
- hostname
|
|
|
|
- filename
|
|
|
|
preconditions:
|
2024-09-05 00:00:06 -05:00
|
|
|
- talosctl config get-contexts | grep $CLUSTER
|
2024-06-18 12:06:23 -05:00
|
|
|
- test -f {{.KUBERNETES_DIR}}/bootstrap/talos/clusterconfig/{{.filename}}
|
2024-09-05 00:00:06 -05:00
|
|
|
version:
|
|
|
|
desc: Show Talos version
|
|
|
|
cmd: talosctl version
|