From ded061af8f54a7c0b058cd3e85c5c7577fc21035 Mon Sep 17 00:00:00 2001 From: Jayson Grace Date: Wed, 27 Dec 2023 09:00:56 -0700 Subject: [PATCH 1/3] Add conditional snapshotter for PXE-booted systems **Added:** - PXE Boot Check - Introduced tasks to check if the system is PXE-booted by analyzing `/proc/cmdline` in `roles/k3s_agent/tasks/main.yml`. - Conditional Snapshotter in Template - Added logic in `k3s.service.j2` template to conditionally set `--snapshotter native` for PXE-booted systems. **Changed:** - `k3s.service.j2` Template Update - Modified the `ExecStart` line to include a conditional check for `is_pxe_booted` fact, dynamically setting the `--snapshotter` option for NFS-mounted systems. - `main.yml` Task Modification - Added tasks to set `is_pxe_booted` fact based on the presence of `root=/dev/nfs` in the system's boot command line. This update allows k3s agents on PXE-booted systems to use the native snapshotter when running on NFS, addressing compatibility issues with OverlayFS. --- roles/k3s_agent/tasks/main.yml | 9 +++++++++ roles/k3s_agent/templates/k3s.service.j2 | 9 ++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/roles/k3s_agent/tasks/main.yml b/roles/k3s_agent/tasks/main.yml index 3146697..28799c2 100644 --- a/roles/k3s_agent/tasks/main.yml +++ b/roles/k3s_agent/tasks/main.yml @@ -1,4 +1,13 @@ --- +- name: Check if system is PXE-booted + command: cat /proc/cmdline + register: boot_cmdline + changed_when: false + +- name: Set fact for PXE-booted system + set_fact: + is_pxe_booted: "{{ 'root=/dev/nfs' in boot_cmdline.stdout }}" + when: boot_cmdline is defined - name: Deploy K3s http_proxy conf include_tasks: http_proxy.yml diff --git a/roles/k3s_agent/templates/k3s.service.j2 b/roles/k3s_agent/templates/k3s.service.j2 index 3be92e3..dac88de 100644 --- a/roles/k3s_agent/templates/k3s.service.j2 +++ b/roles/k3s_agent/templates/k3s.service.j2 @@ -7,11 +7,14 @@ After=network-online.target Type=notify ExecStartPre=-/sbin/modprobe br_netfilter ExecStartPre=-/sbin/modprobe overlay -ExecStart=/usr/local/bin/k3s agent --server https://{{ apiserver_endpoint | ansible.utils.ipwrap }}:6443 --token {{ hostvars[groups[group_name_master | default('master')][0]]['token'] | default(k3s_token) }} {{ extra_agent_args | default("") }} +# Conditional snapshotter based on PXE boot status +ExecStart=/usr/local/bin/k3s agent \ + --server https://{{ apiserver_endpoint | ansible.utils.ipwrap }}:6443 \ + {% if is_pxe_booted | default(false) %}--snapshotter native \ + {% endif %}--token {{ hostvars[groups[group_name_master | default('master')][0]]['token'] | default(k3s_token) }} \ + {{ extra_agent_args | default("") }} KillMode=process Delegate=yes -# Having non-zero Limit*s causes performance problems due to accounting overhead -# in the kernel. We recommend using cgroups to do container-local accounting. LimitNOFILE=1048576 LimitNPROC=infinity LimitCORE=infinity From ab4a261cacf5a57f242aceb8782b997e31339adc Mon Sep 17 00:00:00 2001 From: Jayson Grace Date: Wed, 27 Dec 2023 21:48:30 -0700 Subject: [PATCH 2/3] Introduce idiomatic practices for affected areas from previous commits **Added:** - Structured HTTP Proxy Configuration Block - Added a structured block in `http_proxy.yml` for managing HTTP proxy settings, aligning with Ansible's recommended practices. This includes creating directories and deploying configuration files in a clear, modular fashion. - Conditional Execution for Proxy Setup - Implemented conditional execution for the proxy setup in `http_proxy.yml`, utilizing `proxy_env` to adhere to Ansible's best practices for conditional tasks. - Improved PXE-Boot System Check Block - Introduced a more structured approach in `main.yml` for checking PXE-booted systems, enhancing readability and maintainability. **Changed:** - Adopted Ansible Builtin Modules - Transitioned existing tasks to use `ansible.builtin` modules, ensuring compatibility and future-proofing the role. - Refined Task Grouping - Reorganized tasks into logical blocks, improving the overall structure and readability, and showcasing Ansible's capabilities for efficient task management. - Updated K3s Service Configuration - Modified the K3s service configuration task in `main.yml` for a more streamlined approach using Ansible's template module, reflecting community-driven best practices. **Removed:** - Streamlined Task Definitions - Optimized task definitions to reduce redundancy, focusing on clarity and adherence to the evolving Ansible community standards. --- roles/k3s_agent/tasks/http_proxy.yml | 1 - roles/k3s_agent/tasks/main.yml | 33 +++++++++++++++++----------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/roles/k3s_agent/tasks/http_proxy.yml b/roles/k3s_agent/tasks/http_proxy.yml index d4943e2..839f2e2 100644 --- a/roles/k3s_agent/tasks/http_proxy.yml +++ b/roles/k3s_agent/tasks/http_proxy.yml @@ -1,5 +1,4 @@ --- - - name: Create k3s-node.service.d directory file: path: '{{ systemd_dir }}/k3s-node.service.d' diff --git a/roles/k3s_agent/tasks/main.yml b/roles/k3s_agent/tasks/main.yml index 28799c2..3ab1b7f 100644 --- a/roles/k3s_agent/tasks/main.yml +++ b/roles/k3s_agent/tasks/main.yml @@ -1,28 +1,35 @@ --- -- name: Check if system is PXE-booted - command: cat /proc/cmdline - register: boot_cmdline - changed_when: false +- name: Check for PXE-booted system + block: + - name: Check if system is PXE-booted + ansible.builtin.command: + cmd: cat /proc/cmdline + register: boot_cmdline + changed_when: false + check_mode: false -- name: Set fact for PXE-booted system - set_fact: - is_pxe_booted: "{{ 'root=/dev/nfs' in boot_cmdline.stdout }}" - when: boot_cmdline is defined + - name: Set fact for PXE-booted system + ansible.builtin.set_fact: + is_pxe_booted: "{{ 'root=/dev/nfs' in boot_cmdline.stdout }}" + when: boot_cmdline.stdout is defined + + - name: Include http_proxy configuration tasks + ansible.builtin.include_tasks: http_proxy.yml - name: Deploy K3s http_proxy conf include_tasks: http_proxy.yml when: proxy_env is defined -- name: Copy K3s service file - template: +- name: Configure the k3s service + ansible.builtin.template: src: "k3s.service.j2" dest: "{{ systemd_dir }}/k3s-node.service" owner: root group: root - mode: 0755 + mode: '0755' -- name: Enable and check K3s service - systemd: +- name: Manage k3s service + ansible.builtin.systemd: name: k3s-node daemon_reload: true state: restarted From 4742400db89b08df14e1ca949f6118fa200ba415 Mon Sep 17 00:00:00 2001 From: Jayson Grace Date: Tue, 6 Feb 2024 00:03:12 -0700 Subject: [PATCH 3/3] Added missing checks causing failures for agents --- roles/k3s_agent/tasks/http_proxy.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/roles/k3s_agent/tasks/http_proxy.yml b/roles/k3s_agent/tasks/http_proxy.yml index 839f2e2..7575e9c 100644 --- a/roles/k3s_agent/tasks/http_proxy.yml +++ b/roles/k3s_agent/tasks/http_proxy.yml @@ -6,7 +6,7 @@ owner: root group: root mode: '0755' - + when: proxy_env is defined - name: Copy K3s http_proxy conf file template: @@ -15,3 +15,4 @@ owner: root group: root mode: '0755' + when: proxy_env is defined