cleanup
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Robert Kaussow 2022-10-17 21:26:56 +02:00
parent f9edbc0f2a
commit 2a5e12dcad
Signed by: xoxys
GPG Key ID: 4E692A2EAECC03C0
7 changed files with 67 additions and 101 deletions

View File

@ -16,13 +16,13 @@ def test_k3s_running_and_enabled(host):
def test_k3s_node_ready(host): def test_k3s_node_ready(host):
jsonpth = '{range .items[*]}{@.metadata.name}:{range @.status.conditions[?(@.type=="Ready")]}{@.type}={@.status};{end}{end}' # noqa jsonpth = '{range .items[*]}{@.metadata.name}:{range @.status.conditions[?(@.type=="Ready")]}{@.type}={@.status};{end}{end}' # noqa
nodes = host.run(f"kubectl get nodes -o jsonpath='{jsonpth}'").stdout nodes = host.run(f"k3s kubectl get nodes -o jsonpath='{jsonpth}'").stdout
assert "rocky9-k3s:Ready=True;" in nodes assert "rocky9-k3s:Ready=True;" in nodes
def test_k3s_cluster_ready(host): def test_k3s_cluster_ready(host):
cluster = host.run("kubectl get --raw='/readyz'").stdout cluster = host.run("k3s kubectl get --raw='/readyz'").stdout
assert cluster == "ok" assert cluster == "ok"

View File

@ -20,7 +20,7 @@
-p RestartSec=2 -p RestartSec=2
-p Restart=on-failure -p Restart=on-failure
--unit=k3s-init --unit=k3s-init
k3s server {{ __k3s_server_init_args }} {{ __k3s_binary }} server {{ __k3s_server_init_args }}
creates: "{{ __k3s_service_file }}" creates: "{{ __k3s_service_file }}"
args: args:
warn: False warn: False
@ -31,7 +31,7 @@
- block: - block:
- name: Verify that all nodes actually joined - name: Verify that all nodes actually joined
command: >- command: >-
k3s kubectl get nodes {{ __k3s_binary }} kubectl get nodes
-l "node-role.kubernetes.io/master=true" -l "node-role.kubernetes.io/master=true"
-o=jsonpath="{.items[*].metadata.name}" -o=jsonpath="{.items[*].metadata.name}"
register: __k3s_init_nodes register: __k3s_init_nodes

View File

@ -83,17 +83,5 @@
when: when:
- ansible_hostname == hostvars[k3s_server_nodes[0]]['ansible_hostname'] - ansible_hostname == hostvars[k3s_server_nodes[0]]['ansible_hostname']
- not __k3s_installed.stat.exists - not __k3s_installed.stat.exists
- name: Create kubectl symlink
file:
src: /usr/local/bin/k3s
dest: /usr/local/bin/kubectl
state: link
- name: Create crictl symlink
file:
src: /usr/local/bin/k3s
dest: /usr/local/bin/crictl
state: link
become: True become: True
become_user: root become_user: root

View File

@ -1,5 +1,6 @@
--- ---
- name: Disable services - block:
- name: Disable services
service: service:
name: "{{ item }}" name: "{{ item }}"
state: stopped state: stopped
@ -8,14 +9,15 @@
loop: loop:
- k3s - k3s
- k3s-init - k3s-init
- kubepods
- name: Kill containerd-shim-runc - name: Kill containerd-shim-runc
register: __k3s_pkill_containerd_shim_runc register: __k3s_pkill_containerd_shim_runc
command: pkill -9 -f "k3s/data/[^/]+/bin/containerd-shim-runc" command: pkill -9 -f "k3s/data/[^/]+/bin/containerd-shim-runc"
changed_when: __k3s_pkill_containerd_shim_runc.rc == 0 changed_when: __k3s_pkill_containerd_shim_runc.rc == 0
failed_when: False failed_when: False
- name: Get the list of mounted filesystems - name: Get the list of mounted filesystems
shell: set -o pipefail && cat /proc/mounts | awk '{ print $2}' | grep -E "^{{ item }}" shell: set -o pipefail && cat /proc/mounts | awk '{ print $2}' | grep -E "^{{ item }}"
loop: loop:
- /run/k3s - /run/k3s
@ -31,13 +33,13 @@
failed_when: False failed_when: False
changed_when: False changed_when: False
- name: Umount filesystem - name: Umount filesystem
mount: mount:
path: "{{ item }}" path: "{{ item }}"
state: unmounted state: unmounted
loop: "{{ __k3s_mounted_fs.results | map(attribute='stdout_lines') | list | flatten | reverse }}" loop: "{{ __k3s_mounted_fs.results | map(attribute='stdout_lines') | list | flatten | reverse }}"
- name: Remove service files, binaries and data - name: Remove service files, binaries and data
file: file:
name: "{{ item }}" name: "{{ item }}"
state: absent state: absent
@ -51,8 +53,11 @@
- /run/k3s - /run/k3s
- /run/flannel - /run/flannel
- /var/lib/kubelet - /var/lib/kubelet
- /var/lib/cni/ - /var/lib/cni
- /var/run/netns
- name: Reload systemd daemon - name: Reload systemd daemon
systemd: systemd:
daemon_reload: True daemon_reload: True
become: True
become_user: root

View File

@ -19,46 +19,16 @@
enabled: True enabled: True
state: started state: started
- name: Wait for node-token
wait_for:
path: "{{ __k3s_data_dir }}/server/node-token"
- name: Read node-token from server
slurp:
path: "{{ __k3s_data_dir }}/server/node-token"
register: __k3s_node_token
- name: Store server node-token
set_fact:
token: "{{ __k3s_node_token.content | b64decode | regex_replace('\n', '') }}"
- name: Set server address - name: Set server address
command: >- command: >-
k3s kubectl config set-cluster default {{ __k3s_binary }} kubectl config set-cluster default
--server=https://{{ __k3s_server_ip }}:6443 --server=https://{{ __k3s_server_ip }}:6443
--kubeconfig {{ __k3s_config_dir }}/k3s.yaml --kubeconfig {{ __k3s_config_dir }}/k3s.yaml
changed_when: False changed_when: False
- name: Create directory .kube
file:
path: "{{ ansible_user_dir }}/.kube"
state: directory
owner: "{{ ansible_user }}"
group: "{{ ansible_user }}"
mode: 0740
- name: Copy kube config to user home
copy:
src: "{{ __k3s_config_dir }}/k3s.yaml"
dest: "{{ ansible_user_dir }}/.kube/config"
remote_src: True
owner: "{{ ansible_user }}"
group: "{{ ansible_user }}"
mode: "preserve"
- name: Wait for initial setup - name: Wait for initial setup
command: >- command: >-
kubectl get deployment coredns {{ __k3s_binary }} kubectl get deployment coredns
-n kube-system -n kube-system
-o go-template={% raw %}'{{ .status.availableReplicas }}'{% endraw %} -o go-template={% raw %}'{{ .status.availableReplicas }}'{% endraw %}
register: __k3s_init_setup register: __k3s_init_setup
@ -66,6 +36,7 @@
retries: 6 retries: 6
delay: 10 delay: 10
changed_when: False changed_when: False
when: k3s_server | bool
- name: Remove auto-deploying manifests - name: Remove auto-deploying manifests
file: file:
@ -74,5 +45,6 @@
loop: "{{ k3s_server_manifests_urls + k3s_server_manifests_templates }}" loop: "{{ k3s_server_manifests_urls + k3s_server_manifests_templates }}"
loop_control: loop_control:
label: "{{ __k3s_manifests_dir }}/{{ item.dest | default(item.url) | default(item) | basename | replace('.j2', '') }}" label: "{{ __k3s_manifests_dir }}/{{ item.dest | default(item.url) | default(item) | basename | replace('.j2', '') }}"
when: ansible_hostname == hostvars[k3s_server_nodes[0]]['ansible_hostname']
become: True become: True
become_user: root become_user: root

View File

@ -9,7 +9,7 @@ After=network-online.target
Type=notify Type=notify
ExecStartPre=-/sbin/modprobe br_netfilter ExecStartPre=-/sbin/modprobe br_netfilter
ExecStartPre=-/sbin/modprobe overlay ExecStartPre=-/sbin/modprobe overlay
ExecStart=/usr/local/bin/k3s {{ "server" if k3s_server | bool else "agent" }} --config {{ __k3s_config_dir }}/config.yaml ExecStart={{ __k3s_binary }} {{ "server" if k3s_server | bool else "agent" }} --config {{ __k3s_config_dir }}/config.yaml
KillMode=process KillMode=process
Delegate=yes Delegate=yes
LimitNOFILE=1048576 LimitNOFILE=1048576

View File

@ -1,4 +1,5 @@
--- ---
__k3s_binary: /usr/local/bin/k3s
__k3s_server_ip: "{{ hostvars[k3s_server_nodes[0]].k3s_node_ip }}" __k3s_server_ip: "{{ hostvars[k3s_server_nodes[0]].k3s_node_ip }}"
__k3s_server_init_args: >- __k3s_server_init_args: >-