refactor!: project updates (#1326)

* refactor!: flux is required again

Signed-off-by: Devin Buhl <devin@buhl.casa>

* fix: delimiter that chomps

Signed-off-by: Devin Buhl <devin@buhl.casa>

* fix: bootstrap_cloudflare logic

Signed-off-by: Devin Buhl <devin@buhl.casa>

* fix: update tests

Signed-off-by: Devin Buhl <devin@buhl.casa>

* fix: remove last quote

Signed-off-by: Devin Buhl <devin@buhl.casa>

* chore: update readme

Signed-off-by: Devin Buhl <devin@buhl.casa>

---------

Signed-off-by: Devin Buhl <devin@buhl.casa>
This commit is contained in:
Devin Buhl authored and GitHub committed 2024-02-15 20:03:24 -05:00
1 parent 04ff4ef994
commit c17d543b21
93 files changed
+591 -755

No files matched your search

+1 -1
View File
@@ -1 +1 @@
main = lambda data: data.get("distribution", {}).get("type", "k3s") in ["k3s"]
main = lambda data: data.get("bootstrap_distribution", "k3s") in ["k3s"]
@@ -1,13 +1,13 @@
---
k3s_control_node: true
k3s_server:
{% if feature_gates.dual_stack_ipv4_first %}
cluster-cidr: "{{ cluster.pod_network.split(',')[0] }},{{ cluster.pod_network.split(',')[1] }}"
service-cidr: "{{ cluster.service_network.split(',')[0] }},{{ cluster.service_network.split(',')[1] }}"
{% else %}
cluster-cidr: "{{ cluster.pod_network }}"
service-cidr: "{{ cluster.service_network }}"
{% endif %}
#% if bootstrap_feature_gates.dual_stack_ipv4_first %#
cluster-cidr: "#{ bootstrap_pod_network.split(',')[0] }#,#{ bootstrap_pod_network.split(',')[1] }#"
service-cidr: "#{ bootstrap_service_network.split(',')[0] }#,#{ bootstrap_service_network.split(',')[1] }#"
#% else %#
cluster-cidr: "#{ bootstrap_pod_network }#"
service-cidr: "#{ bootstrap_service_network }#"
#% endif %#
disable: ["flannel", "local-storage", "metrics-server", "servicelb", "traefik"]
disable-cloud-controller: true
disable-kube-proxy: true
@@ -25,16 +25,16 @@ k3s_server:
kubelet-arg:
- "image-gc-high-threshold=55"
- "image-gc-low-threshold=50"
{% if feature_gates.dual_stack_ipv4_first %}
node-ip: "{% raw %}{{ ansible_host }}{% endraw %},{% raw %}{{ ansible_default_ipv6.address }}{% endraw %}"
{% else %}
node-ip: "{% raw %}{{ ansible_host }}{% endraw %}"
{% endif %}
#% if bootstrap_feature_gates.dual_stack_ipv4_first %#
node-ip: "{{ ansible_host }},{{ ansible_default_ipv6.address }}"
#% else %#
node-ip: "{{ ansible_host }}"
#% endif %#
pause-image: registry.k8s.io/pause:3.9
secrets-encryption: true
tls-san:
- "{{ cluster.endpoint_vip }}"
{% for item in cluster.tls_sans %}
- "{{ item }}"
{% endfor %}
- "#{ bootstrap_controllers_vip }#"
#% for item in bootstrap_tls_sans %#
- "#{ item }#"
#% endfor %#
write-kubeconfig-mode: "644"
@@ -2,7 +2,7 @@
k3s_become: true
k3s_etcd_datastore: true
k3s_install_hard_links: true
k3s_registration_address: "{{ cluster.endpoint_vip }}"
k3s_registration_address: "#{ bootstrap_controllers_vip }#"
k3s_registries:
mirrors:
docker.io:
@@ -1,9 +1,9 @@
main = lambda data: (
data.get("distribution").get("type", "k3s") in ["k3s"] and
data.get("bootstrap_distribution", "k3s") in ["k3s"] and
len(
list(
filter(
lambda item: "controller" in item and item["controller"] is False, data.get("nodes").get("inventory")
lambda item: "controller" in item and item["controller"] is False, data.get("bootstrap_node_inventory")
)
)
) > 0
@@ -4,9 +4,9 @@ k3s_agent:
kubelet-arg:
- "image-gc-high-threshold=55"
- "image-gc-low-threshold=50"
{% if feature_gates.dual_stack_ipv4_first %}
node-ip: "{% raw %}{{ ansible_host }}{% endraw %},{% raw %}{{ ansible_default_ipv6.address }}{% endraw %}"
{% else %}
node-ip: "{% raw %}{{ ansible_host }}{% endraw %}"
{% endif %}
#% if bootstrap_feature_gates.dual_stack_ipv4_first %#
node-ip: "{{ ansible_host }},{{ ansible_default_ipv6.address }}"
#% else %#
node-ip: "{{ ansible_host }}"
#% endif %#
pause-image: registry.k8s.io/pause:3.9
@@ -3,21 +3,21 @@ kubernetes:
children:
controllers:
hosts:
{% for item in nodes.inventory %}
{% if item.controller %}
"{{ item.name }}":
ansible_user: "{{ item.ssh_username }}"
ansible_host: "{{ item.address }}"
{% endif %}
{% endfor %}
{% if nodes.inventory | selectattr('controller', 'equalto', False) | list | length %}
#% for item in bootstrap_node_inventory %#
#% if item.controller %#
"#{ item.name }#":
ansible_user: "#{ item.ssh_user }#"
ansible_host: "#{ item.address }#"
#% endif %#
#% endfor %#
#% if bootstrap_node_inventory | selectattr('controller', 'equalto', False) | list | length %#
workers:
hosts:
{% for item in nodes.inventory %}
{% if not item.controller %}
"{{ item.name }}":
ansible_user: "{{ item.ssh_username }}"
ansible_host: "{{ item.address }}"
{% endif %}
{% endfor %}
{% endif %}
#% for item in bootstrap_node_inventory %#
#% if not item.controller %#
"#{ item.name }#":
ansible_user: "#{ item.ssh_user }#"
ansible_host: "#{ item.address }#"
#% endif %#
#% endfor %#
#% endif %#
@@ -42,9 +42,9 @@
or k3s_server_manifests_urls | length > 0)
kubernetes.core.k8s_info:
kubeconfig: /etc/rancher/k3s/k3s.yaml
kind: "{% raw %}{{ item.kind }}{% endraw %}"
name: "{% raw %}{{ item.name }}{% endraw %}"
namespace: "{% raw %}{{ item.namespace | default('') }}{% endraw %}"
kind: "{{ item.kind }}"
name: "{{ item.name }}"
namespace: "{{ item.namespace | default('') }}"
wait: true
wait_sleep: 10
wait_timeout: 360
@@ -20,5 +20,5 @@
- name: Upgrade kube-vip
ansible.builtin.template:
src: templates/kube-vip-ds.yaml.j2
dest: "{% raw %}{{ k3s_server_manifests_dir }}{% endraw %}/kube-vip-ds.yaml"
dest: "{{ k3s_server_manifests_dir }}/kube-vip-ds.yaml"
mode: preserve
@@ -36,17 +36,17 @@
block:
- name: Networking | Delete Cilium links
ansible.builtin.command:
cmd: "ip link delete {% raw %}{{ item }}{% endraw %}"
removes: "/sys/class/net/{% raw %}{{ item }}{% endraw %}"
cmd: "ip link delete {{ item }}"
removes: "/sys/class/net/{{ item }}"
loop: ["cilium_host", "cilium_net", "cilium_vxlan"]
- name: Networking | Flush iptables
ansible.builtin.iptables:
table: "{% raw %}{{ item }}{% endraw %}"
table: "{{ item }}"
flush: true
loop: ["filter", "nat", "mangle", "raw"]
- name: Networking | Flush ip6tables
ansible.builtin.iptables:
table: "{% raw %}{{ item }}{% endraw %}"
table: "{{ item }}"
flush: true
ip_version: ipv6
loop: ["filter", "nat", "mangle", "raw"]
@@ -86,7 +86,7 @@
- k3s_install_hard_links
- not ansible_check_mode
ansible.builtin.file:
path: "{% raw %}{{ k3s_install_dir }}{% endraw %}/{% raw %}{{ item }}{% endraw %}"
path: "{{ k3s_install_dir }}/{{ item }}"
state: absent
loop: ["kubectl", "crictl", "ctr"]
@@ -15,7 +15,7 @@
block:
- name: Locale | Set timezone
community.general.timezone:
name: "{{ timezone }}"
name: "#{ bootstrap_timezone }#"
- name: Packages
block:
@@ -32,12 +32,12 @@
block:
- name: Network Configuration | Set hostname
ansible.builtin.hostname:
name: "{% raw %}{{ inventory_hostname }}{% endraw %}"
name: "{{ inventory_hostname }}"
- name: Network Configuration | Update hosts
ansible.builtin.copy:
content: |
127.0.0.1 localhost
127.0.1.1 {% raw %}{{ inventory_hostname }}{% endraw %}
127.0.1.1 {{ inventory_hostname }}
# The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
@@ -61,10 +61,10 @@
mode: '0644'
dest: /etc/resolv.conf
content: |
search {{ nodes.search_domain|default('.', true) }}
{% for item in nodes.dns_servers | default(['1.1.1.1', '1.0.0.1']) %}
nameserver {{ item }}
{% endfor %}
search #{ bootstrap_search_domain|default('.', true) }#
#% for item in bootstrap_dns_servers | default(['1.1.1.1', '1.0.0.1']) %#
nameserver #{ item }#
#% endfor %#
- name: System Configuration
notify: Reboot
@@ -77,15 +77,15 @@
masked: true
- name: System Configuration | Disable swap
ansible.posix.mount:
name: "{% raw %}{{ item }}{% endraw %}"
name: "{{ item }}"
fstype: swap
state: absent
loop: ["none", "swap"]
- name: System Configuration | Create Kernel modules
ansible.builtin.copy:
dest: "/etc/modules-load.d/{% raw %}{{ item }}{% endraw %}.conf"
dest: "/etc/modules-load.d/{{ item }}.conf"
mode: "0644"
content: "{% raw %}{{ item }}{% endraw %}"
content: "{{ item }}"
loop: ["br_netfilter", "ceph", "ip_vs", "ip_vs_rr", "nbd", "overlay", "rbd"]
register: modules_status
- name: System Configuration | Reload Kernel modules # noqa: no-changed-when no-handler
@@ -95,11 +95,11 @@
state: restarted
- name: System Configuration | Sysctl
ansible.posix.sysctl:
name: "{% raw %}{{ item.key }}{% endraw %}"
value: "{% raw %}{{ item.value }}{% endraw %}"
name: "{{ item.key }}"
value: "{{ item.value }}"
sysctl_file: /etc/sysctl.d/99-kubernetes.conf
reload: true
with_dict: "{% raw %}{{ sysctl_config }}{% endraw %}"
with_dict: "{{ sysctl_config }}"
vars:
sysctl_config:
fs.inotify.max_queued_events: 65536
@@ -11,9 +11,9 @@
seconds: 5
tasks:
- name: Details
ansible.builtin.command: "k3s kubectl get node {% raw %}{{ inventory_hostname }}{% endraw %} -o json"
ansible.builtin.command: "k3s kubectl get node {{ inventory_hostname }} -o json"
register: kubectl_get_node
delegate_to: "{% raw %}{{ groups['controllers'][0] }}{% endraw %}"
delegate_to: "{{ groups['controllers'][0] }}"
failed_when: false
changed_when: false
@@ -26,14 +26,14 @@
block:
- name: Cordon
kubernetes.core.k8s_drain:
name: "{% raw %}{{ inventory_hostname }}{% endraw %}"
name: "{{ inventory_hostname }}"
kubeconfig: /etc/rancher/k3s/k3s.yaml
state: cordon
delegate_to: "{% raw %}{{ groups['controllers'][0] }}{% endraw %}"
delegate_to: "{{ groups['controllers'][0] }}"
- name: Drain
kubernetes.core.k8s_drain:
name: "{% raw %}{{ inventory_hostname }}{% endraw %}"
name: "{{ inventory_hostname }}"
kubeconfig: /etc/rancher/k3s/k3s.yaml
state: drain
delete_options:
@@ -43,7 +43,7 @@
wait_timeout: 900
pod_selectors:
- app!=rook-ceph-osd # Rook Ceph
delegate_to: "{% raw %}{{ groups['controllers'][0] }}{% endraw %}"
delegate_to: "{{ groups['controllers'][0] }}"
- name: Update
ansible.builtin.apt:
@@ -64,7 +64,7 @@
- name: Uncordon
kubernetes.core.k8s_drain:
name: "{% raw %}{{ inventory_hostname }}{% endraw %}"
name: "{{ inventory_hostname }}"
kubeconfig: /etc/rancher/k3s/k3s.yaml
state: uncordon
delegate_to: "{% raw %}{{ groups['controllers'][0] }}{% endraw %}"
delegate_to: "{{ groups['controllers'][0] }}"
@@ -3,7 +3,7 @@
block:
- name: Cruft | Get list of custom manifests
ansible.builtin.find:
paths: "{% raw %}{{ k3s_server_manifests_dir }}{% endraw %}"
paths: "{{ k3s_server_manifests_dir }}"
file_type: file
use_regex: true
patterns: ["^custom-.*"]
@@ -11,9 +11,9 @@
- name: Cruft | Delete custom manifests
ansible.builtin.file:
path: "{% raw %}{{ item.path }}{% endraw %}"
path: "{{ item.path }}"
state: absent
loop: "{% raw %}{{ custom_manifest.files }}{% endraw %}"
loop: "{{ custom_manifest.files }}"
- name: Cruft | Get list of custom addons
kubernetes.core.k8s_info:
@@ -24,8 +24,8 @@
- name: Cruft | Delete addons
kubernetes.core.k8s:
kubeconfig: /etc/rancher/k3s/k3s.yaml
name: "{% raw %}{{ item.metadata.name }}{% endraw %}"
name: "{{ item.metadata.name }}"
kind: Addon
namespace: kube-system
state: absent
loop: "{% raw %}{{ addons_list.resources | selectattr('metadata.name', 'match', '^custom-.*') | list }}{% endraw %}"
loop: "{{ addons_list.resources | selectattr('metadata.name', 'match', '^custom-.*') | list }}"
@@ -13,7 +13,7 @@
when: k3s_primary_control_node
ansible.builtin.fetch:
src: /etc/rancher/k3s/k3s.yaml
dest: "{% raw %}{{ repository_path.stdout }}{% endraw %}/kubeconfig"
dest: "{{ repository_path.stdout }}/kubeconfig"
flat: true
- name: Update kubeconfig with the correct load balancer address
@@ -21,6 +21,6 @@
become: false
run_once: true
ansible.builtin.replace:
path: "{% raw %}{{ repository_path.stdout }}{% endraw %}/kubeconfig"
path: "{{ repository_path.stdout }}/kubeconfig"
regexp: https://127.0.0.1:6443
replace: "https://{% raw %}{{ k3s_registration_address }}{% endraw %}:6443"
replace: "https://{{ k3s_registration_address }}:6443"
@@ -9,10 +9,9 @@
- name: Extract k3s version
ansible.builtin.set_fact:
current_k3s_version: "{% raw %}{{ k3s_version.stdout | regex_replace('(?im)k3s version (?P<version>[a-z0-9\\.\\+]+).*\n.*', '\\g<version>') }}{% endraw %}"
current_k3s_version: "{{ k3s_version.stdout | regex_replace('(?im)k3s version (?P<version>[a-z0-9\\.\\+]+).*\n.*', '\\g<version>') }}"
- name: Check if upgrades are allowed
ansible.builtin.assert:
that:
- "k3s_release_version is version(current_k3s_version, '>=')"
that: ["k3s_release_version is version(current_k3s_version, '>=')"]
fail_msg: "Unable to upgrade k3s because the deployed version is higher than the one specified in the configuration"
@@ -12,6 +12,6 @@ spec:
targetNamespace: kube-system
bootstrap: true
valuesContent: |-
{% filter indent(width=4, first=True) %}
{% include 'partials/cilium-values-init.partial.yaml.j2' %}
{% endfilter %}
#% filter indent(width=4, first=True) %#
#% include 'partials/cilium-values-init.partial.yaml.j2' %#
#% endfilter %#
@@ -1,2 +1,2 @@
---
{% include 'partials/kube-vip-ds.partial.yaml.j2' %}
#% include 'partials/kube-vip-ds.partial.yaml.j2' %#
@@ -1,2 +1,2 @@
---
{% include 'partials/kube-vip-rbac.partial.yaml.j2' %}
#% include 'partials/kube-vip-rbac.partial.yaml.j2' %#