Skip to content

Commit a4ad3ee

Browse files
committed
Try Cilium CNI
Signed-off-by: peppi-lotta <[email protected]>
1 parent 19e63ce commit a4ad3ee

File tree

2 files changed

+76
-36
lines changed

2 files changed

+76
-36
lines changed

tests/roles/run_tests/tasks/verify.yml

Lines changed: 75 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -18,44 +18,83 @@
1818
create: yes
1919
block: "{{ kubeconfig_secret.resources[0].data.value | b64decode }}"
2020

21-
# Install Calico
22-
- name: Download Calico v3.25.x manifests
23-
get_url:
24-
url: "https://raw.githubusercontent.com/projectcalico/calico/{{ CALICO_MINOR_RELEASE }}/manifests/calico.yaml"
25-
dest: /tmp/
26-
mode: '664'
27-
register: calico_manifest
21+
# Install Cilium CLI
22+
- name: Get latest Cilium CLI version
23+
ansible.builtin.uri:
24+
url: https://raw.githubusercontent.com/cilium/cilium-cli/main/stable.txt
25+
return_content: yes
26+
register: cilium_version_response
2827

29-
- name: Pin calico version to v3.25.1
30-
ansible.builtin.replace:
31-
path: /tmp/calico.yaml
32-
regexp: 'image: docker.io/calico/(.+):v(.+)$'
33-
replace: 'image: {{ DOCKER_HUB_PROXY }}/calico/\1:{{ CALICO_PATCH_RELEASE }}'
28+
- name: Set Cilium CLI version and architecture
29+
ansible.builtin.set_fact:
30+
CILIUM_CLI_VERSION: "{{ cilium_version_response.content | trim }}"
31+
CLI_ARCH: "{{ 'arm64' if ansible_architecture == 'aarch64' else 'amd64' }}"
3432

35-
- name: Replace the POD_CIDR in calico config
36-
replace:
37-
path: /tmp/calico.yaml
38-
regexp: "192.168.0.0/16"
39-
replace: "{{ POD_CIDR }}"
40-
register: updated_manifest
33+
- name: Download Cilium CLI archive and checksum
34+
ansible.builtin.get_url:
35+
url: "https://github.com/cilium/cilium-cli/releases/download/{{ CILIUM_CLI_VERSION }}/cilium-linux-{{ CLI_ARCH }}.tar.gz{{ item }}"
36+
dest: "/tmp/cilium-linux-{{ CLI_ARCH }}.tar.gz{{ item }}"
37+
loop:
38+
- ""
39+
- ".sha256sum"
4140

42-
- name: Add IP_AUTODETECTION_METHOD in calico config Ubuntu
43-
blockinfile:
44-
path: /tmp/calico.yaml
45-
insertafter: "{{ POD_CIDR }}"
46-
block: |
47-
# for indentation
48-
- name: IP_AUTODETECTION_METHOD
49-
value: "cidr={{ EXTERNAL_SUBNET_V4_HOST }}/{{ EXTERNAL_SUBNET_V4_PREFIX }}"
41+
- name: Verify checksum of Cilium CLI archive
42+
ansible.builtin.stat:
43+
path: "/tmp/cilium-linux-{{ CLI_ARCH }}.tar.gz"
44+
checksum_algorithm: sha256
45+
get_checksum: yes
46+
register: cilium_archive_stat
47+
48+
- name: Read expected checksum
49+
ansible.builtin.slurp:
50+
src: "/tmp/cilium-linux-{{ CLI_ARCH }}.tar.gz.sha256sum"
51+
register: expected_checksum_file
52+
53+
- name: Extract expected checksum value
54+
ansible.builtin.set_fact:
55+
expected_checksum: "{{ (expected_checksum_file.content | b64decode).split()[0] }}"
56+
57+
- name: Verify checksum matches
58+
ansible.builtin.fail:
59+
msg: "Checksum verification failed"
60+
when: cilium_archive_stat.stat.checksum != expected_checksum
61+
62+
- name: Extract Cilium CLI to /usr/local/bin
63+
ansible.builtin.unarchive:
64+
src: "/tmp/cilium-linux-{{ CLI_ARCH }}.tar.gz"
65+
dest: /usr/local/bin
66+
mode: 0755
67+
become: true
68+
become_user: root
5069

51-
- name: Apply Calico manifest
52-
kubernetes.core.k8s:
53-
state: present
54-
src: "/tmp/calico.yaml"
55-
kubeconfig: "/tmp/kubeconfig-{{ CLUSTER_NAME }}.yaml"
56-
register: install_cni
70+
- name: Clean up downloaded files
71+
ansible.builtin.file:
72+
path: "/tmp/cilium-linux-{{ CLI_ARCH }}.tar.gz{{ item }}"
73+
state: absent
74+
loop:
75+
- ""
76+
- ".sha256sum"
77+
78+
- name: Check if Cilium is already installed
79+
ansible.builtin.command:
80+
cmd: cilium status
81+
environment:
82+
KUBECONFIG: /tmp/kubeconfig-{{ CLUSTER_NAME }}.yaml
83+
register: cilium_status
84+
failed_when: false
85+
changed_when: false
86+
87+
- name: Install Cilium using CLI
88+
ansible.builtin.command:
89+
cmd: >
90+
cilium install --version {{ CILIUM_VERSION }}
91+
--set ipam.operator.clusterPoolIPv4PodCIDRList={{ POD_CIDR }}
92+
environment:
93+
KUBECONFIG: /tmp/kubeconfig-{{ CLUSTER_NAME }}.yaml
94+
become: true
95+
when: cilium_status.rc != 0
5796

58-
- name: Wait (maximum 10 mins) until Calico pods start running
97+
- name: Wait (maximum 10 mins) until Cilium pods start running
5998
kubernetes.core.k8s_info:
6099
api_version: v1
61100
kind: Pod
@@ -65,9 +104,9 @@
65104
- status.phase!=Running
66105
retries: 60
67106
delay: 10
68-
register: calico_pods
69-
until: (calico_pods is succeeded) and
70-
(calico_pods.resources | length == 0)
107+
register: cilium_pods
108+
until: (cilium_pods is succeeded) and
109+
(cilium_pods.resources | length == 0)
71110

72111
# Check for pods & nodes on the target cluster
73112
- name: Wait for all pods to be in running state

tests/roles/run_tests/vars/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ IMAGE_USERNAME: "{{ lookup('env', 'IMAGE_USERNAME') | default('metal3', true) }}
5959
REGISTRY: "{{ lookup('env', 'REGISTRY') | default('192.168.111.1:5000', true) }}"
6060
CALICO_MINOR_RELEASE: "{{ lookup('env', 'CALICO_MINOR_RELEASE') | default('v3.25.1', true) }}"
6161
CALICO_PATCH_RELEASE: "{{ lookup('env', 'CALICO_PATCH_RELEASE') | default('v3.25.1', true) }}"
62+
CILIUM_VERSION: "{{ lookup('env', 'CILIUM_VERSION') | default('v1.17.6', true) }}"
6263
DOCKER_HUB_PROXY: "{{ lookup('env', 'DOCKER_HUB_PROXY') }}"
6364
WORKING_DIR: "{{ lookup('env', 'WORKING_DIR') | default('/opt/metal3-dev-env', true) }}"
6465

0 commit comments

Comments
 (0)