From 33e58dcb8328836f053b3443664b31c21f77dede Mon Sep 17 00:00:00 2001 From: Robert Kaussow Date: Tue, 25 Oct 2022 09:58:53 +0200 Subject: [PATCH] feat: add option to patch kubernetes resources (#1) --- defaults/main.yml | 7 ++++++- molecule/rocky9/converge.yml | 2 -- tasks/prepare.yml | 2 +- tasks/setup.yml | 12 ++++++++++++ 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/defaults/main.yml b/defaults/main.yml index 77e5556..ba0af6c 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,10 +1,13 @@ --- k3s_version: v1.25.0+k3s1 -k3s_packages_extra: +k3s_packages: + - python3-kubernetes - container-selinux - selinux-policy-base +k3s_packages_extra: [] + k3s_reset: False k3s_token: "secure-token" k3s_node_ip: "{{ ansible_default_ipv4.address }}" @@ -40,3 +43,5 @@ k3s_server_admission_configuration: - type: User qps: 10 burst: 50 + +k3s_server_resource_patches: [] diff --git a/molecule/rocky9/converge.yml b/molecule/rocky9/converge.yml index ac7c677..d4998b1 100644 --- a/molecule/rocky9/converge.yml +++ b/molecule/rocky9/converge.yml @@ -4,8 +4,6 @@ vars: k3s_reset: False k3s_packages_extra: - - container-selinux - - selinux-policy-base - https://github.com/k3s-io/k3s-selinux/releases/download/v1.2.stable.2/k3s-selinux-1.2-2.el8.noarch.rpm k3s_server_flannel_backend_enabled: False k3s_server_network_policy_enabled: False diff --git a/tasks/prepare.yml b/tasks/prepare.yml index d12850e..aa52c1a 100644 --- a/tasks/prepare.yml +++ b/tasks/prepare.yml @@ -9,7 +9,7 @@ package: name: "{{ item }}" state: present - loop: "{{ k3s_packages_extra }}" + loop: "{{ k3s_packages + k3s_packages_extra }}" - name: Check if cluster is installed stat: diff --git a/tasks/setup.yml b/tasks/setup.yml index d991e2c..d6a4838 100644 --- a/tasks/setup.yml +++ b/tasks/setup.yml @@ -38,6 +38,18 @@ changed_when: False when: k3s_server | bool + - name: Patch existing resources + k8s: + kind: "{{ item.kind }}" + name: "{{ item.name }}" + kubeconfig: "{{ __k3s_config_dir }}/k3s.yaml" + state: patched + definition: "{{ item.definition }}" + loop: "{{ k3s_server_resource_patches }}" + loop_control: + label: "{{ item.kind }}/{{ item.name }}" + when: k3s_server | bool + - name: Remove auto-deploying manifests file: path: "{{ __k3s_manifests_dir }}/{{ item.dest | default(item.url) | default(item) | basename | replace('.j2', '') }}"