Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PXE boot support to k3s_agent role #409

Merged
merged 3 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions roles/k3s_agent/tasks/http_proxy.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
---

- name: Create k3s-node.service.d directory
file:
path: '{{ systemd_dir }}/k3s-node.service.d'
state: directory
owner: root
group: root
mode: '0755'

when: proxy_env is defined

- name: Copy K3s http_proxy conf file
template:
Expand All @@ -16,3 +15,4 @@
owner: root
group: root
mode: '0755'
when: proxy_env is defined
26 changes: 21 additions & 5 deletions roles/k3s_agent/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,35 @@
---
- 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
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
Expand Down
9 changes: 6 additions & 3 deletions roles/k3s_agent/templates/k3s.service.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading