Skip to content

Commit cf8f34a

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

File tree

4 files changed

+150
-52
lines changed

4 files changed

+150
-52
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Install Calico
2+
- name: Download Calico manifests
3+
get_url:
4+
url: "https://raw.githubusercontent.com/projectcalico/calico/{{ CALICO_VERSION }}/manifests/calico.yaml"
5+
dest: /tmp/
6+
mode: '664'
7+
register: calico_manifest
8+
9+
- name: Replace docker.io with proxy
10+
ansible.builtin.replace:
11+
path: /tmp/calico.yaml
12+
regexp: 'docker.io'
13+
replace: '{{ DOCKER_HUB_PROXY }}'
14+
15+
- name: Uncomment CALICO_IPV4POOL_CIDR name
16+
replace:
17+
path: /tmp/calico.yaml
18+
regexp: "# - name: CALICO_IPV4POOL_CIDR"
19+
replace: "- name: CALICO_IPV4POOL_CIDR"
20+
21+
- name: Uncomment CALICO_IPV4POOL_CIDR value and set POD_CIDR
22+
replace:
23+
path: /tmp/calico.yaml
24+
regexp: '# value: "192.168.0.0/16"'
25+
replace: ' value: "{{ POD_CIDR }}"'
26+
27+
- name: Add IP_AUTODETECTION_METHOD in calico config Ubuntu
28+
blockinfile:
29+
path: /tmp/calico.yaml
30+
insertafter: "{{ POD_CIDR }}"
31+
block: |
32+
# for indentation
33+
- name: IP_AUTODETECTION_METHOD
34+
value: "cidr={{ EXTERNAL_SUBNET_V4_HOST }}/{{ EXTERNAL_SUBNET_V4_PREFIX }}"
35+
36+
- name: Apply Calico manifest
37+
kubernetes.core.k8s:
38+
state: present
39+
src: "/tmp/calico.yaml"
40+
kubeconfig: "/tmp/kubeconfig-{{ CLUSTER_NAME }}.yaml"
41+
register: install_cni
42+
43+
- name: Wait (maximum 10 mins) until Calico pods start running
44+
kubernetes.core.k8s_info:
45+
api_version: v1
46+
kind: Pod
47+
namespace: kube-system
48+
kubeconfig: /tmp/kubeconfig-{{ CLUSTER_NAME }}.yaml
49+
field_selectors:
50+
- status.phase!=Running
51+
retries: 60
52+
delay: 10
53+
register: calico_pods
54+
until: (calico_pods is succeeded) and
55+
(calico_pods.resources | length == 0)
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# Install Cilium CLI
2+
- name: Get latest Cilium CLI version
3+
ansible.builtin.uri:
4+
url: https://raw.githubusercontent.com/cilium/cilium-cli/main/stable.txt
5+
return_content: yes
6+
register: cilium_version_response
7+
8+
- name: Set Cilium CLI version and architecture
9+
ansible.builtin.set_fact:
10+
CILIUM_CLI_VERSION: "{{ cilium_version_response.content | trim }}"
11+
CLI_ARCH: "{{ 'arm64' if ansible_architecture == 'aarch64' else 'amd64' }}"
12+
13+
- name: Download Cilium CLI archive and checksum
14+
ansible.builtin.get_url:
15+
url: "https://github.com/cilium/cilium-cli/releases/download/{{ CILIUM_CLI_VERSION }}/cilium-linux-{{ CLI_ARCH }}.tar.gz{{ item }}"
16+
dest: "/tmp/cilium-linux-{{ CLI_ARCH }}.tar.gz{{ item }}"
17+
loop:
18+
- ""
19+
- ".sha256sum"
20+
21+
- name: Verify checksum of Cilium CLI archive
22+
ansible.builtin.stat:
23+
path: "/tmp/cilium-linux-{{ CLI_ARCH }}.tar.gz"
24+
checksum_algorithm: sha256
25+
get_checksum: yes
26+
register: cilium_archive_stat
27+
28+
- name: Read expected checksum
29+
ansible.builtin.slurp:
30+
src: "/tmp/cilium-linux-{{ CLI_ARCH }}.tar.gz.sha256sum"
31+
register: expected_checksum_file
32+
33+
- name: Extract expected checksum value
34+
ansible.builtin.set_fact:
35+
expected_checksum: "{{ (expected_checksum_file.content | b64decode).split()[0] }}"
36+
37+
- name: Verify checksum matches
38+
ansible.builtin.fail:
39+
msg: "Checksum verification failed"
40+
when: cilium_archive_stat.stat.checksum != expected_checksum
41+
42+
- name: Extract Cilium CLI to /usr/local/bin
43+
ansible.builtin.unarchive:
44+
src: "/tmp/cilium-linux-{{ CLI_ARCH }}.tar.gz"
45+
dest: /usr/local/bin
46+
mode: 0755
47+
become: true
48+
become_user: root
49+
50+
- name: Clean up downloaded files
51+
ansible.builtin.file:
52+
path: "/tmp/cilium-linux-{{ CLI_ARCH }}.tar.gz{{ item }}"
53+
state: absent
54+
loop:
55+
- ""
56+
- ".sha256sum"
57+
58+
- name: Check if Cilium is already installed
59+
ansible.builtin.command:
60+
cmd: cilium status
61+
environment:
62+
KUBECONFIG: /tmp/kubeconfig-{{ CLUSTER_NAME }}.yaml
63+
register: cilium_status
64+
failed_when: false
65+
changed_when: false
66+
67+
- name: Install Cilium using CLI
68+
ansible.builtin.command:
69+
cmd: >
70+
cilium install --version {{ CILIUM_VERSION }}
71+
environment:
72+
KUBECONFIG: /tmp/kubeconfig-{{ CLUSTER_NAME }}.yaml
73+
become: true
74+
when: cilium_status.rc != 0
75+
76+
- name: Wait (maximum 10 mins) until Cilium pods start running
77+
kubernetes.core.k8s_info:
78+
api_version: v1
79+
kind: Pod
80+
namespace: kube-system
81+
kubeconfig: /tmp/kubeconfig-{{ CLUSTER_NAME }}.yaml
82+
field_selectors:
83+
- status.phase!=Running
84+
retries: 60
85+
delay: 10
86+
register: cilium_pods
87+
until: (cilium_pods is succeeded) and
88+
(cilium_pods.resources | length == 0)

tests/roles/run_tests/tasks/verify.yml

Lines changed: 4 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -18,56 +18,10 @@
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
28-
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 }}'
34-
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
41-
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 }}"
50-
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
57-
58-
- name: Wait (maximum 10 mins) until Calico pods start running
59-
kubernetes.core.k8s_info:
60-
api_version: v1
61-
kind: Pod
62-
namespace: kube-system
63-
kubeconfig: /tmp/kubeconfig-{{ CLUSTER_NAME }}.yaml
64-
field_selectors:
65-
- status.phase!=Running
66-
retries: 60
67-
delay: 10
68-
register: calico_pods
69-
until: (calico_pods is succeeded) and
70-
(calico_pods.resources | length == 0)
21+
- name: Install CNI based on CNI_NAME
22+
include_tasks: "{{ cni_task_file }}"
23+
vars:
24+
cni_task_file: "{{ 'install_calico.yaml' if (CNI_NAME | default('calico')) == 'calico' else 'install_cilium.yaml' }}"
7125

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

tests/roles/run_tests/vars/main.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,9 @@ SSH_PRIVATE_KEY: "{{ lookup('env', 'SSH_KEY') }}"
5757
SSH_PUB_KEY_CONTENT: "{{ lookup('file', '{{ HOME }}/.ssh/id_rsa.pub') }}"
5858
IMAGE_USERNAME: "{{ lookup('env', 'IMAGE_USERNAME') | default('metal3', true) }}"
5959
REGISTRY: "{{ lookup('env', 'REGISTRY') | default('192.168.111.1:5000', true) }}"
60-
CALICO_MINOR_RELEASE: "{{ lookup('env', 'CALICO_MINOR_RELEASE') | default('v3.25.1', true) }}"
61-
CALICO_PATCH_RELEASE: "{{ lookup('env', 'CALICO_PATCH_RELEASE') | default('v3.25.1', true) }}"
60+
CALICO_VERSION: "{{ lookup('env', 'CALICO_VERSION') | default('v3.30.3', true) }}"
61+
CILIUM_VERSION: "{{ lookup('env', 'CILIUM_VERSION') | default('v1.18.0', true) }}"
62+
CNI_NAME: "{{ lookup('env', 'CNI_NAME') | default('calico', 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)