|
2 | 2 | # yaml-language-server: $schema=https://taskfile.dev/schema.json
|
3 | 3 | version: "3"
|
4 | 4 |
|
5 |
| -x-vars: &vars |
6 |
| - TALOS_VERSION: |
7 |
| - sh: yq 'select(document_index == 1).spec.postBuild.substitute.TALOS_VERSION' {{.KUBERNETES_DIR}}/{{.cluster}}/apps/system-upgrade/system-upgrade-controller/ks.yaml |
8 |
| - TALOS_SCHEMATIC_ID: |
9 |
| - sh: yq 'select(document_index == 1).spec.postBuild.substitute.TALOS_SCHEMATIC_ID' {{.KUBERNETES_DIR}}/{{.cluster}}/apps/system-upgrade/system-upgrade-controller/ks.yaml |
10 |
| - KUBERNETES_VERSION: |
11 |
| - sh: yq 'select(document_index == 1).spec.postBuild.substitute.KUBERNETES_VERSION' {{.KUBERNETES_DIR}}/{{.cluster}}/apps/system-upgrade/system-upgrade-controller/ks.yaml |
12 |
| - CONTROLLER: |
13 |
| - sh: talosctl --context {{.cluster}} config info --output json | jq --raw-output '.endpoints[]' | shuf -n 1 |
| 5 | +vars: |
| 6 | + BOOTSTRAP_TALOS_DIR: "{{.KUBERNETES_DIR}}/{{.cluster}}/bootstrap/talos" |
| 7 | + TALHELPER_CLUSTER_DIR: "{{.BOOTSTRAP_TALOS_DIR}}/clusterconfig" |
| 8 | + TALHELPER_SECRET_FILE: "{{.BOOTSTRAP_TALOS_DIR}}/talsecret.sops.yaml" |
| 9 | + TALHELPER_CONFIG_FILE: "{{.BOOTSTRAP_TALOS_DIR}}/talconfig.yaml" |
| 10 | + HELMFILE_FILE: "{{.KUBERNETES_DIR}}/{{.cluster}}/bootstrap/helmfile.yaml" |
| 11 | + TALOSCONFIG_FILE: "{{.TALHELPER_CLUSTER_DIR}}/talosconfig" |
| 12 | + |
| 13 | +env: |
| 14 | + TALOSCONFIG: "{{.TALOSCONFIG_FILE}}" |
14 | 15 |
|
15 | 16 | tasks:
|
16 | 17 | bootstrap:
|
17 | 18 | desc: Bootstrap the Talos cluster
|
18 |
| - dir: "{{.KUBERNETES_DIR}}/{{.cluster}}/bootstrap/talos" |
| 19 | + dir: "/{{.BOOTSTRAP_TALOS_DIR}}" |
19 | 20 | cmds:
|
20 | 21 | - |
|
21 |
| - if [ ! -f "{{.KUBERNETES_DIR}}/{{.cluster}}/bootstrap/talos/talsecret.sops.yaml" ]; then |
22 |
| - talhelper gensecret > {{.KUBERNETES_DIR}}/{{.cluster}}/bootstrap/talos/talsecret.sops.yaml |
23 |
| - sops --encrypt --in-place {{.KUBERNETES_DIR}}/{{.cluster}}/bootstrap/talos/talsecret.sops.yaml |
| 22 | + if [ ! -f "{{.TALHELPER_SECRET_FILE}}" ]; then |
| 23 | + talhelper gensecret > {{.TALHELPER_SECRET_FILE}} |
| 24 | + sops --encrypt --in-place {{.TALHELPER_SECRET_FILE}} |
24 | 25 | fi
|
25 |
| - - talhelper genconfig --config-file {{.KUBERNETES_DIR}}/{{.cluster}}/bootstrap/talos/talconfig.yaml --secret-file {{.KUBERNETES_DIR}}/{{.cluster}}/bootstrap/talos/talsecret.sops.yaml --out-dir {{.KUBERNETES_DIR}}/{{.cluster}}/bootstrap/talos/clusterconfig |
26 |
| - - talhelper gencommand apply --config-file {{.KUBERNETES_DIR}}/{{.cluster}}/bootstrap/talos/talconfig.yaml --out-dir {{.KUBERNETES_DIR}}/{{.cluster}}/bootstrap/talos/clusterconfig --extra-flags="--insecure" | bash |
27 |
| - - until talhelper gencommand bootstrap --config-file {{.KUBERNETES_DIR}}/{{.cluster}}/bootstrap/talos/talconfig.yaml --out-dir {{.KUBERNETES_DIR}}/{{.cluster}}/bootstrap/talos/clusterconfig | bash; do sleep 10; done |
| 26 | + - talhelper genconfig --config-file {{.TALHELPER_CONFIG_FILE}} --secret-file {{.TALHELPER_SECRET_FILE}} --out-dir {{.TALHELPER_CLUSTER_DIR}} |
| 27 | + - talhelper gencommand apply --config-file {{.TALHELPER_CONFIG_FILE}} --out-dir {{.TALHELPER_CLUSTER_DIR}} --extra-flags="--insecure" | bash |
| 28 | + - until talhelper gencommand bootstrap --config-file {{.TALHELPER_CONFIG_FILE}} --out-dir {{.TALHELPER_CLUSTER_DIR}} | bash; do sleep 10; done |
28 | 29 | - task: fetch-kubeconfig
|
29 | 30 | - task: install-helm-apps
|
30 |
| - - talosctl --context {{.cluster}} health --server=false |
| 31 | + - task: health |
31 | 32 | requires:
|
32 | 33 | vars: ["cluster"]
|
33 | 34 | preconditions:
|
34 | 35 | - msg: Missing talhelper config file
|
35 |
| - sh: test -f {{.KUBERNETES_DIR}}/{{.cluster}}/bootstrap/talos/talconfig.yaml |
| 36 | + sh: test -f {{.TALHELPER_CONFIG_FILE}} |
36 | 37 | - msg: Missing Sops config file
|
37 | 38 | sh: test -f {{.SOPS_CONFIG_FILE}}
|
38 | 39 | - msg: Missing Sops Age key file
|
39 | 40 | sh: test -f {{.AGE_FILE}}
|
40 | 41 |
|
41 |
| - fetch-kubeconfig: |
42 |
| - desc: Fetch kubeconfig |
43 |
| - dir: "{{.KUBERNETES_DIR}}/{{.cluster}}/bootstrap/talos" |
44 |
| - cmd: | |
45 |
| - until talhelper gencommand kubeconfig --config-file {{.KUBERNETES_DIR}}/{{.cluster}}/bootstrap/talos/talconfig.yaml \ |
46 |
| - --out-dir {{.KUBERNETES_DIR}}/{{.cluster}}/bootstrap/talos/clusterconfig \ |
47 |
| - --extra-flags="{{.ROOT_DIR}} --force --force-context-name {{.cluster}}" \ |
48 |
| - | bash; do sleep 10; done |
| 42 | + health: |
| 43 | + desc: Get Talos cluster health |
| 44 | + dir: "/{{.BOOTSTRAP_TALOS_DIR}}" |
| 45 | + cmd: "talosctl health --server=false" |
49 | 46 | requires:
|
50 | 47 | vars: ["cluster"]
|
51 | 48 | preconditions:
|
52 |
| - - msg: Missing talhelper config file |
53 |
| - sh: test -f {{.KUBERNETES_DIR}}/{{.cluster}}/bootstrap/talos/talconfig.yaml |
| 49 | + - msg: Missing talosconfig |
| 50 | + sh: test -f {{.TALOSCONFIG_FILE}} |
54 | 51 |
|
55 |
| - apply-config: |
56 |
| - desc: Apply Talos configuration to a node |
57 |
| - cmd: | |
58 |
| - sops --decrypt {{.KUBERNETES_DIR}}/{{.cluster}}/bootstrap/talos/assets/{{.hostname}}.secret.sops.yaml | \ |
59 |
| - envsubst | \ |
60 |
| - talosctl --context {{.cluster}} apply-config --mode={{.mode}} --nodes {{.hostname}} --file /dev/stdin |
61 |
| - env: *vars |
62 |
| - vars: |
63 |
| - mode: '{{.mode | default "no-reboot"}}' |
| 52 | + fetch-kubeconfig: |
| 53 | + desc: Fetch kubeconfig |
| 54 | + dir: "/{{.BOOTSTRAP_TALOS_DIR}}" |
| 55 | + cmd: until talhelper gencommand kubeconfig --config-file {{.TALHELPER_CONFIG_FILE}} --out-dir {{.TALHELPER_CLUSTER_DIR}} --extra-flags="{{.ROOT_DIR}} --force" | bash; do sleep 10; done |
64 | 56 | requires:
|
65 |
| - vars: ["cluster", "hostname"] |
| 57 | + vars: ["cluster"] |
66 | 58 | preconditions:
|
67 |
| - - test -f {{.KUBERNETES_DIR}}/{{.cluster}}/talosconfig |
68 |
| - - test -f {{.KUBERNETES_DIR}}/{{.cluster}}/bootstrap/talos/assets/{{.hostname}}.secret.sops.yaml |
69 |
| - - talosctl --context {{.cluster}} --nodes {{.hostname}} get machineconfig >/dev/null 2>&1 |
70 |
| - |
| 59 | + - msg: Missing talhelper config file |
| 60 | + sh: test -f {{.TALHELPER_CONFIG_FILE}} |
71 | 61 |
|
72 | 62 | install-helm-apps:
|
73 | 63 | desc: Bootstrap core apps needed for Talos
|
74 |
| - dir: "{{.KUBERNETES_DIR}}/bootstrap/talos" |
| 64 | + dir: "/{{.BOOTSTRAP_TALOS_DIR}}" |
75 | 65 | cmds:
|
76 |
| - - until kubectl --kube-context {{.cluster}} wait --for=condition=Ready=False nodes --all --timeout=600s; do sleep 10; done |
77 |
| - - helmfile --kube-context {{.cluster}} --file {{.KUBERNETES_DIR}}/{{.cluster}}/bootstrap/helmfile.yaml apply --skip-diff-on-install --suppress-diff |
78 |
| - - until kubectl --kube-context {{.cluster}} wait --for=condition=Ready nodes --all --timeout=600s; do sleep 10; done |
| 66 | + - until kubectl --kubeconfig {{.KUBECONFIG_FILE}} wait --for=condition=Ready=False nodes --all --timeout=600s; do sleep 10; done |
| 67 | + - helmfile --kubeconfig {{.KUBECONFIG_FILE}} --file {{.HELMFILE_FILE}} apply --skip-diff-on-install --suppress-diff |
| 68 | + - until kubectl --kubeconfig {{.KUBECONFIG_FILE}} wait --for=condition=Ready nodes --all --timeout=600s; do sleep 10; done |
79 | 69 | requires:
|
80 | 70 | vars: ["cluster"]
|
81 | 71 | preconditions:
|
82 |
| - - msg: Missing talosconfig |
83 |
| - sh: test -f {{.KUBERNETES_DIR}}/{{.cluster}}/talosconfig |
84 |
| - - msg: Unable to retrieve Talos config |
85 |
| - sh: talosctl --context {{.cluster}} config info >/dev/null 2>&1 |
| 72 | + - msg: Missing kubeconfig |
| 73 | + sh: test -f {{.KUBECONFIG_FILE}} |
86 | 74 | - msg: Missing helmfile
|
87 |
| - sh: test -f {{.KUBERNETES_DIR}}/{{.cluster}}/bootstrap/helmfile.yaml |
| 75 | + sh: test -f {{.HELMFILE_FILE}} |
88 | 76 |
|
89 | 77 | upgrade:
|
90 | 78 | desc: Upgrade Talos on a node
|
91 |
| - dir: "{{.KUBERNETES_DIR}}/bootstrap/talos" |
| 79 | + dir: "/{{.BOOTSTRAP_TALOS_DIR}}" |
92 | 80 | cmds:
|
93 |
| - - talosctl --context {{.cluster}} --nodes {{.node}} upgrade --image {{.image}} --wait=true --timeout=10m --preserve=true --reboot-mode={{.mode}} |
94 |
| - - talosctl --context {{.cluster}} --nodes {{.node}} health --wait-timeout=10m --server=false |
| 81 | + - "talosctl --nodes {{.node}} upgrade --image {{.image}} --wait=true --timeout=10m --preserve=true --reboot-mode={{.mode}}" |
| 82 | + - "talosctl --nodes {{.node}} health --wait-timeout=10m --server=false" |
95 | 83 | vars:
|
96 | 84 | mode: '{{.mode | default "default"}}'
|
97 | 85 | requires:
|
98 | 86 | vars: ["cluster", "node", "image"]
|
99 | 87 | preconditions:
|
100 | 88 | - msg: Missing talosconfig
|
101 |
| - sh: test -f {{.KUBERNETES_DIR}}/{{.cluster}}/talosconfig |
| 89 | + sh: test -f {{.TALOSCONFIG_FILE}} |
102 | 90 | - msg: Unable to retrieve Talos config
|
103 |
| - sh: talosctl --context {{.cluster}} config info >/dev/null 2>&1 |
| 91 | + sh: "talosctl config info >/dev/null 2>&1" |
104 | 92 | - msg: Node not found
|
105 |
| - sh: talosctl --context {{.cluster}} --nodes {{.node}} get machineconfig >/dev/null 2>&1 |
| 93 | + sh: "talosctl --nodes {{.node}} get machineconfig >/dev/null 2>&1" |
106 | 94 |
|
107 | 95 | upgrade-k8s:
|
108 | 96 | desc: Upgrade Kubernetes across the cluster
|
109 |
| - dir: "{{.KUBERNETES_DIR}}/{{.cluster}}/bootstrap/talos" |
110 |
| - cmd: talosctl --context {{.cluster}} --nodes {{.controller}} upgrade-k8s --to {{.to}} |
| 97 | + dir: "/{{.BOOTSTRAP_TALOS_DIR}}" |
| 98 | + cmd: "talosctl --nodes {{.controller}} upgrade-k8s --to {{.to}}" |
111 | 99 | requires:
|
112 | 100 | vars: ["cluster", "controller", "to"]
|
113 | 101 | preconditions:
|
114 | 102 | - msg: Missing talosconfig
|
115 |
| - sh: test -f {{.KUBERNETES_DIR}}/{{.cluster}}/talosconfig |
| 103 | + sh: test -f {{.TALOSCONFIG_FILE}} |
116 | 104 | - msg: Unable to retrieve Talos config
|
117 |
| - sh: talosctl --context {{.cluster}} config info >/dev/null 2>&1 |
| 105 | + sh: "talosctl config info >/dev/null 2>&1" |
118 | 106 | - msg: Node not found
|
119 |
| - sh: talosctl --context {{.cluster}} --nodes {{.controller}} get machineconfig >/dev/null 2>&1 |
| 107 | + sh: "talosctl --nodes {{.controller}} get machineconfig >/dev/null 2>&1" |
120 | 108 |
|
121 |
| - nuke: |
| 109 | + destroy: |
122 | 110 | desc: Resets nodes back to maintenance mode
|
123 |
| - dir: "{{.KUBERNETES_DIR}}/{{.cluster}}/bootstrap/talos" |
| 111 | + dir: "/{{.BOOTSTRAP_TALOS_DIR}}" |
124 | 112 | prompt: This will destroy your cluster and reset the nodes back to maintenance mode... continue?
|
125 |
| - cmd: talhelper gencommand reset --config-file {{.KUBERNETES_DIR}}/{{.cluster}}/bootstrap/talos/talconfig.yaml --out-dir {{.KUBERNETES_DIR}}/{{.cluster}}/bootstrap/talos/clusterconfig --extra-flags="--reboot {{- if eq .CLI_FORCE false }} --system-labels-to-wipe STATE --system-labels-to-wipe EPHEMERAL{{ end }} --graceful=false --wait=false" | bash |
| 113 | + cmd: talhelper gencommand reset --config-file {{.TALHELPER_CONFIG_FILE}} --out-dir {{.TALHELPER_CLUSTER_DIR}} --extra-flags="--reboot {{- if eq .CLI_FORCE false }} --system-labels-to-wipe STATE --system-labels-to-wipe EPHEMERAL{{ end }} --graceful=false --wait=false" | bash |
126 | 114 | requires:
|
127 | 115 | vars: ["cluster"]
|
0 commit comments