Skip to content

Commit

Permalink
Make kubectl binary configurable with the k3s_kubectl_binary parameter
Browse files Browse the repository at this point in the history
Closes #566

Signed-off-by: Christian Berendt <[email protected]>
  • Loading branch information
berendt committed Aug 20, 2024
1 parent 3a0303d commit d67c69c
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 18 deletions.
2 changes: 2 additions & 0 deletions roles/k3s_server/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
---
extra_server_args: ""

k3s_kubectl_binary: k3s kubectl

group_name_master: master

kube_vip_arp: true
Expand Down
4 changes: 2 additions & 2 deletions roles/k3s_server/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
block:
- name: Verify that all nodes actually joined (check k3s-init.service if this fails)
ansible.builtin.command:
cmd: k3s kubectl get nodes -l "node-role.kubernetes.io/master=true" -o=jsonpath="{.items[*].metadata.name}"
cmd: "{{ k3s_kubectl_binary }} get nodes -l 'node-role.kubernetes.io/master=true' -o=jsonpath='{.items[*].metadata.name}'"
register: nodes
until: nodes.rc == 0 and (nodes.stdout.split() | length) == (groups[group_name_master | default('master')] | length) # yamllint disable-line rule:line-length
retries: "{{ retry_count | default(20) }}"
Expand Down Expand Up @@ -124,7 +124,7 @@

- name: Configure kubectl cluster to {{ endpoint_url }}
ansible.builtin.command: >-
k3s kubectl config set-cluster default
{{ k3s_kubectl_binary }} config set-cluster default
--server={{ endpoint_url }}
--kubeconfig {{ ansible_user_dir }}/.kube/config
changed_when: true
Expand Down
2 changes: 2 additions & 0 deletions roles/k3s_server_post/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
---
k3s_kubectl_binary: k3s kubectl

bpf_lb_algorithm: maglev
bpf_lb_mode: hybrid

Expand Down
6 changes: 3 additions & 3 deletions roles/k3s_server_post/tasks/calico.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

- name: Wait for Tigera Operator resources
ansible.builtin.command: >-
k3s kubectl wait {{ item.type }}/{{ item.name }}
{{ k3s_kubectl_binary }} wait {{ item.type }}/{{ item.name }}
--namespace='tigera-operator'
--for=condition=Available=True
--timeout=30s
Expand Down Expand Up @@ -78,12 +78,12 @@
- name: Wait for Calico system resources to be available
ansible.builtin.command: >-
{% if item.type == 'daemonset' %}
k3s kubectl wait pods
{{ k3s_kubectl_binary }} wait pods
--namespace='{{ item.namespace }}'
--selector={{ item.selector }}
--for=condition=Ready
{% else %}
k3s kubectl wait {{ item.type }}/{{ item.name }}
{{ k3s_kubectl_binary }} wait {{ item.type }}/{{ item.name }}
--namespace='{{ item.namespace }}'
--for=condition=Available
{% endif %}
Expand Down
11 changes: 6 additions & 5 deletions roles/k3s_server_post/tasks/cilium.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@
when: ping_result.rc != 0

- name: Test for existing Cilium install
ansible.builtin.command: k3s kubectl -n kube-system get daemonsets cilium
ansible.builtin.command: |
{{ k3s_kubectl_binary }} -n kube-system get daemonsets cilium
register: cilium_installed
failed_when: false
changed_when: false
Expand Down Expand Up @@ -192,12 +193,12 @@
- name: Wait for Cilium resources
ansible.builtin.command: >-
{% if item.type == 'daemonset' %}
k3s kubectl wait pods
{{ k3s_kubectl_binary }} wait pods
--namespace=kube-system
--selector='k8s-app=cilium'
--for=condition=Ready
{% else %}
k3s kubectl wait {{ item.type }}/{{ item.name }}
{{ k3s_kubectl_binary }} wait {{ item.type }}/{{ item.name }}
--namespace=kube-system
--for=condition=Available
{% endif %}
Expand Down Expand Up @@ -244,8 +245,8 @@
- name: Test for BGP config resources
ansible.builtin.command: "{{ item }}"
loop:
- k3s kubectl get CiliumBGPPeeringPolicy.cilium.io
- k3s kubectl get CiliumLoadBalancerIPPool.cilium.io
- {{ k3s_kubectl_binary }} get CiliumBGPPeeringPolicy.cilium.io
- {{ k3s_kubectl_binary }} get CiliumLoadBalancerIPPool.cilium.io
changed_when: false
loop_control:
label: "{{ item }}"
16 changes: 8 additions & 8 deletions roles/k3s_server_post/tasks/metallb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
ansible.builtin.shell: |-
set -o pipefail
REPLICAS=$(k3s kubectl --namespace='metallb-system' get replicasets \
REPLICAS=$({{ k3s_kubectl_binary }} --namespace='metallb-system' get replicasets \
-l 'component=controller,app=metallb' \
-o jsonpath='{.items[0].spec.template.spec.containers[0].image}, {.items[0].metadata.name}' 2>/dev/null || true)
REPLICAS_SETS=$(echo ${REPLICAS} | grep -v '{{ metal_lb_controller_tag_version }}' | sed -e "s/^.*\s//g")
if [ -n "${REPLICAS_SETS}" ] ; then
for REPLICAS in "${REPLICAS_SETS}"
do
k3s kubectl --namespace='metallb-system' \
{{ k3s_kubectl_binary }} --namespace='metallb-system' \
delete rs "${REPLICAS}"
done
fi
Expand All @@ -40,14 +40,14 @@

- name: Test metallb-system namespace
ansible.builtin.command: >-
k3s kubectl -n metallb-system
{{ k3s_kubectl_binary }} -n metallb-system
changed_when: false
with_items: "{{ groups[group_name_master | default('master')] }}"
run_once: true

- name: Wait for MetalLB resources
ansible.builtin.command: >-
k3s kubectl wait {{ item.resource }}
{{ k3s_kubectl_binary }} wait {{ item.resource }}
--namespace='metallb-system'
{% if item.name | default(False) -%}{{ item.name }}{%- endif %}
{% if item.selector | default(False) -%}--selector='{{ item.selector }}'{%- endif %}
Expand Down Expand Up @@ -99,14 +99,14 @@
- name: Test metallb-system webhook-service endpoint
ansible.builtin.command: >-
k3s kubectl -n metallb-system get endpoints {{ metallb_webhook_service_name }}
{{ k3s_kubectl_binary }} -n metallb-system get endpoints {{ metallb_webhook_service_name }}
changed_when: false
with_items: "{{ groups[group_name_master | default('master')] }}"
run_once: true

- name: Apply metallb CRs
ansible.builtin.command: >-
k3s kubectl apply -f /tmp/k3s/metallb-crs.yaml
{{ k3s_kubectl_binary }} apply -f /tmp/k3s/metallb-crs.yaml
--timeout='{{ metal_lb_available_timeout }}'
register: this
changed_when: false
Expand All @@ -116,7 +116,7 @@

- name: Test metallb-system resources for Layer 2 configuration
ansible.builtin.command: >-
k3s kubectl -n metallb-system get {{ item }}
{{ k3s_kubectl_binary }} -n metallb-system get {{ item }}
changed_when: false
run_once: true
when: metal_lb_mode == "layer2"
Expand All @@ -126,7 +126,7 @@

- name: Test metallb-system resources for BGP configuration
ansible.builtin.command: >-
k3s kubectl -n metallb-system get {{ item }}
{{ k3s_kubectl_binary }} -n metallb-system get {{ item }}
changed_when: false
run_once: true
when: metal_lb_mode == "bgp"
Expand Down

0 comments on commit d67c69c

Please sign in to comment.