Skip to content

Commit

Permalink
feat: add talos support
Browse files Browse the repository at this point in the history
Signed-off-by: Devin Buhl <devin@buhl.casa>
  • Loading branch information
onedr0p committed Jan 18, 2024
1 parent 0c4f026 commit 624f2a3
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 2 deletions.
41 changes: 41 additions & 0 deletions .taskfiles/Talos/Taskfile.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
version: "3"

vars:
TALOS_DIR: "{{.ROOT_DIR}}/kubernetes/talos"

tasks:

genconfig:
desc: Generate talos config
dir: "{{.TALOS_DIR}}"
cmd: talhelper genconfig
preconditions:
- { msg: "Missing talhelper config file", sh: "test -f {{.TALOS_DIR}}/talhelper.yaml" }

apply-config:
desc: Apply talos config on a node
cmd: talosctl -n {{.node}} apply-config -f "{{.TALOS_DIR}}/clusterconfig/k8s-{{.node}}.yaml"
vars:
node: '{{ or .node (fail "Argument (node) is required") }}'
preconditions:
- { msg: "Missing Talos config file", sh: "test -f {{.TALOS_DIR}}/clusterconfig/k8s-{{.node}}.yaml" }
- { msg: "Node not found", sh: "talosctl -n {{.node}} get mc" }

upgrade-talos:
desc: Upgrade talos on a node
cmd: talosctl -n {{.node}} upgrade --image {{.image}} --preserve=true --reboot-mode=powercycle
vars:
image: '{{ or .image (fail "Argument (image) is required") }}'
node: '{{ or .node (fail "Argument (node) is required") }}'
preconditions:
- { msg: "Node not found", sh: "talosctl -n {{.node}} get mc" }

upgrade-k8s:
desc: Upgrade k8s on a node
cmd: talosctl -n {{.node}} upgrade-k8s --to {{.to}}
vars:
node: '{{ or .node (fail "Argument (node) is required") }}'
to: '{{ or .to (fail "Argument (to) is required") }}'
preconditions:
- { msg: "Node not found", sh: "talosctl -n {{.node}} get mc" }
1 change: 1 addition & 0 deletions .taskfiles/Workstation/Archfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ moreutils
sops
stern-bin
talhelper-bin
talosctl
2 changes: 2 additions & 0 deletions .taskfiles/Workstation/Brewfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
tap "fluxcd/tap"
tap "go-task/tap"
tap "k0sproject/tap"
tap "siderolabs/talos"
brew "age"
brew "cloudflared"
brew "direnv"
Expand All @@ -16,4 +17,5 @@ brew "moreutils"
brew "sops"
brew "stern"
brew "talhelper"
brew "talosctl"
brew "yq"
1 change: 1 addition & 0 deletions Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ includes:
repository:
aliases: ["repo"]
taskfile: .taskfiles/Repository/Taskfile.yaml
talos: .taskfiles/Talos/Taskfile.yaml
sops: .taskfiles/Sops/Taskfile.yaml
workstation: .taskfiles/Workstation/Taskfile.yaml

Expand Down
10 changes: 10 additions & 0 deletions bootstrap/tasks/validation/cli.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,13 @@
check_mode: false
register: result
failed_when: result.rc != 0 and result.rc != 127

- name: Check if required CLI tools are present for talos
when: bootstrap_distribution == "k0s"
ansible.builtin.shell: |
command -v {{ item }} >/dev/null 2>&1
loop: ["talhelper"]
changed_when: false
check_mode: false
register: result
failed_when: result.rc != 0 and result.rc != 127
2 changes: 1 addition & 1 deletion bootstrap/tasks/validation/vars.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

- name: Check if bootstrap distribution is valid
ansible.builtin.assert:
that: bootstrap_distribution in ['k0s', 'k3s']
that: bootstrap_distribution in ['k0s', 'k3s', 'talos']
success_msg: Distribution {{ bootstrap_distribution }} is valid
fail_msg: Distribution {{ bootstrap_distribution }} is not valid

Expand Down
8 changes: 8 additions & 0 deletions bootstrap/templates/kubernetes/talos/talhelper.yaml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#% if bootstrap_distribution == 'talos' %#
---
clusterName: &cluster k8s
clusterPodNets:
- "#{ bootstrap_cluster_cidr.split(',')[0] }#"
clusterSvcNets:
- "#{ bootstrap_service_cidr.split(',')[0] }#"
#% endif %#
2 changes: 1 addition & 1 deletion bootstrap/vars/config.sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Bootstrap configuration - config.yaml is gitignored
#

# Distribution can either be 'k3s' or 'k0s'
# Distribution can either be 'k3s', 'k0s', or 'talos'
bootstrap_distribution: k3s

# Github username (e.g. onedr0p)
Expand Down

0 comments on commit 624f2a3

Please sign in to comment.