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