|
18 | 18 | create: yes |
19 | 19 | block: "{{ kubeconfig_secret.resources[0].data.value | b64decode }}" |
20 | 20 |
|
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 |
28 | 27 |
|
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' }}" |
34 | 32 |
|
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" |
41 | 40 |
|
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 |
50 | 69 |
|
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 |
57 | 96 |
|
58 | | - - name: Wait (maximum 10 mins) until Calico pods start running |
| 97 | + - name: Wait (maximum 10 mins) until Cilium pods start running |
59 | 98 | kubernetes.core.k8s_info: |
60 | 99 | api_version: v1 |
61 | 100 | kind: Pod |
|
65 | 104 | - status.phase!=Running |
66 | 105 | retries: 60 |
67 | 106 | 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) |
71 | 110 |
|
72 | 111 | # Check for pods & nodes on the target cluster |
73 | 112 | - name: Wait for all pods to be in running state |
|
0 commit comments