2018-08-23 22:17:18 +08:00
|
|
|
---
|
2021-06-25 18:22:45 +08:00
|
|
|
- name: Calico | Install Wireguard packages
|
|
|
|
package:
|
|
|
|
name: "{{ item }}"
|
|
|
|
state: present
|
|
|
|
with_items: "{{ calico_wireguard_packages }}"
|
|
|
|
register: calico_package_install
|
|
|
|
until: calico_package_install is succeeded
|
|
|
|
retries: 4
|
|
|
|
when: calico_wireguard_enabled
|
|
|
|
|
2019-04-15 19:24:04 +08:00
|
|
|
- name: Calico | Copy calicoctl binary from download dir
|
|
|
|
copy:
|
2023-05-25 13:30:50 +08:00
|
|
|
src: "{{ downloads.calicoctl.dest }}"
|
2019-04-15 19:24:04 +08:00
|
|
|
dest: "{{ bin_dir }}/calicoctl"
|
2024-07-26 09:42:20 +08:00
|
|
|
mode: "0755"
|
2024-08-28 13:30:56 +08:00
|
|
|
remote_src: true
|
2019-04-15 19:24:04 +08:00
|
|
|
|
2018-08-23 22:17:18 +08:00
|
|
|
- name: Calico | Create calico certs directory
|
|
|
|
file:
|
|
|
|
dest: "{{ calico_cert_dir }}"
|
|
|
|
state: directory
|
2024-07-26 09:42:20 +08:00
|
|
|
mode: "0750"
|
2018-08-23 22:17:18 +08:00
|
|
|
owner: root
|
|
|
|
group: root
|
2019-07-15 16:59:06 +08:00
|
|
|
when: calico_datastore == "etcd"
|
2018-08-23 22:17:18 +08:00
|
|
|
|
|
|
|
- name: Calico | Link etcd certificates for calico-node
|
|
|
|
file:
|
|
|
|
src: "{{ etcd_cert_dir }}/{{ item.s }}"
|
|
|
|
dest: "{{ calico_cert_dir }}/{{ item.d }}"
|
|
|
|
state: hard
|
2024-07-26 09:42:20 +08:00
|
|
|
mode: "0640"
|
2024-08-28 13:30:56 +08:00
|
|
|
force: true
|
2018-08-23 22:17:18 +08:00
|
|
|
with_items:
|
2019-04-19 21:01:54 +08:00
|
|
|
- {s: "{{ kube_etcd_cacert_file }}", d: "ca_cert.crt"}
|
|
|
|
- {s: "{{ kube_etcd_cert_file }}", d: "cert.crt"}
|
|
|
|
- {s: "{{ kube_etcd_key_file }}", d: "key.pem"}
|
2019-07-15 16:59:06 +08:00
|
|
|
when: calico_datastore == "etcd"
|
2018-08-23 22:17:18 +08:00
|
|
|
|
2019-10-17 22:02:38 +08:00
|
|
|
- name: Calico | Generate typha certs
|
|
|
|
include_tasks: typha_certs.yml
|
|
|
|
when:
|
|
|
|
- typha_secure
|
2021-03-24 08:26:05 +08:00
|
|
|
- inventory_hostname == groups['kube_control_plane'][0]
|
2019-10-17 22:02:38 +08:00
|
|
|
|
2022-04-08 15:02:42 +08:00
|
|
|
- name: Calico | Generate apiserver certs
|
|
|
|
include_tasks: calico_apiserver_certs.yml
|
|
|
|
when:
|
|
|
|
- calico_apiserver_enabled
|
|
|
|
- inventory_hostname == groups['kube_control_plane'][0]
|
|
|
|
|
2019-04-15 19:24:04 +08:00
|
|
|
- name: Calico | Install calicoctl wrapper script
|
2018-08-23 22:17:18 +08:00
|
|
|
template:
|
2019-07-08 17:20:03 +08:00
|
|
|
src: "calicoctl.{{ calico_datastore }}.sh.j2"
|
2019-04-15 19:24:04 +08:00
|
|
|
dest: "{{ bin_dir }}/calicoctl.sh"
|
2024-07-26 09:42:20 +08:00
|
|
|
mode: "0755"
|
2018-08-23 22:17:18 +08:00
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
|
|
|
|
- name: Calico | wait for etcd
|
|
|
|
uri:
|
|
|
|
url: "{{ etcd_access_addresses.split(',') | first }}/health"
|
2024-08-28 13:30:56 +08:00
|
|
|
validate_certs: false
|
2019-06-21 02:12:51 +08:00
|
|
|
client_cert: "{{ calico_cert_dir }}/cert.crt"
|
|
|
|
client_key: "{{ calico_cert_dir }}/key.pem"
|
2018-08-23 22:17:18 +08:00
|
|
|
register: result
|
|
|
|
until: result.status == 200 or result.status == 401
|
|
|
|
retries: 10
|
|
|
|
delay: 5
|
|
|
|
run_once: true
|
2019-07-15 16:59:06 +08:00
|
|
|
when: calico_datastore == "etcd"
|
2018-08-23 22:17:18 +08:00
|
|
|
|
2020-09-03 14:55:40 +08:00
|
|
|
- name: Calico | Check if calico network pool has already been configured
|
2023-06-30 17:51:57 +08:00
|
|
|
# noqa risky-shell-pipe - grep will exit 1 if no match found
|
2018-08-23 22:17:18 +08:00
|
|
|
shell: >
|
2019-04-15 19:24:04 +08:00
|
|
|
{{ bin_dir }}/calicoctl.sh get ippool | grep -w "{{ calico_pool_cidr | default(kube_pods_subnet) }}" | wc -l
|
2020-09-03 14:55:40 +08:00
|
|
|
args:
|
|
|
|
executable: /bin/bash
|
2018-08-23 22:17:18 +08:00
|
|
|
register: calico_conf
|
|
|
|
retries: 4
|
2020-04-21 22:20:56 +08:00
|
|
|
until: calico_conf.rc == 0
|
2018-08-23 22:17:18 +08:00
|
|
|
delay: "{{ retry_stagger | random + 3 }}"
|
2019-02-26 12:09:30 +08:00
|
|
|
changed_when: false
|
2019-07-15 16:59:06 +08:00
|
|
|
when:
|
2021-03-24 08:26:05 +08:00
|
|
|
- inventory_hostname == groups['kube_control_plane'][0]
|
2018-08-23 22:17:18 +08:00
|
|
|
|
2019-02-01 05:39:13 +08:00
|
|
|
- name: Calico | Ensure that calico_pool_cidr is within kube_pods_subnet when defined
|
|
|
|
assert:
|
2023-10-17 15:45:11 +08:00
|
|
|
that: "[calico_pool_cidr] | ansible.utils.ipaddr(kube_pods_subnet) | length == 1"
|
2019-02-01 05:39:13 +08:00
|
|
|
msg: "{{ calico_pool_cidr }} is not within or equal to {{ kube_pods_subnet }}"
|
|
|
|
when:
|
2021-03-24 08:26:05 +08:00
|
|
|
- inventory_hostname == groups['kube_control_plane'][0]
|
2019-02-01 05:39:13 +08:00
|
|
|
- 'calico_conf.stdout == "0"'
|
|
|
|
- calico_pool_cidr is defined
|
|
|
|
|
2020-10-26 15:10:53 +08:00
|
|
|
- name: Calico | Check if calico IPv6 network pool has already been configured
|
2023-06-30 17:51:57 +08:00
|
|
|
# noqa risky-shell-pipe - grep will exit 1 if no match found
|
2020-10-26 15:10:53 +08:00
|
|
|
shell: >
|
|
|
|
{{ bin_dir }}/calicoctl.sh get ippool | grep -w "{{ calico_pool_cidr_ipv6 | default(kube_pods_subnet_ipv6) }}" | wc -l
|
|
|
|
args:
|
|
|
|
executable: /bin/bash
|
|
|
|
register: calico_conf_ipv6
|
|
|
|
retries: 4
|
|
|
|
until: calico_conf_ipv6.rc == 0
|
|
|
|
delay: "{{ retry_stagger | random + 3 }}"
|
|
|
|
changed_when: false
|
|
|
|
when:
|
2021-03-24 08:26:05 +08:00
|
|
|
- inventory_hostname == groups['kube_control_plane'][0]
|
2020-10-26 15:10:53 +08:00
|
|
|
- enable_dual_stack_networks
|
|
|
|
|
|
|
|
- name: Calico | Ensure that calico_pool_cidr_ipv6 is within kube_pods_subnet_ipv6 when defined
|
|
|
|
assert:
|
2023-10-17 15:45:11 +08:00
|
|
|
that: "[calico_pool_cidr_ipv6] | ansible.utils.ipaddr(kube_pods_subnet_ipv6) | length == 1"
|
2020-10-26 15:10:53 +08:00
|
|
|
msg: "{{ calico_pool_cidr_ipv6 }} is not within or equal to {{ kube_pods_subnet_ipv6 }}"
|
|
|
|
when:
|
2021-03-24 08:26:05 +08:00
|
|
|
- inventory_hostname == groups['kube_control_plane'][0]
|
2020-10-26 15:10:53 +08:00
|
|
|
- calico_conf_ipv6.stdout is defined and calico_conf_ipv6.stdout == "0"
|
|
|
|
- calico_pool_cidr_ipv6 is defined
|
|
|
|
- enable_dual_stack_networks
|
|
|
|
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Calico | kdd specific configuration
|
2023-08-10 15:57:27 +08:00
|
|
|
when:
|
2024-09-21 20:09:09 +08:00
|
|
|
- ('kube_control_plane' in group_names)
|
2023-08-10 15:57:27 +08:00
|
|
|
- calico_datastore == "kdd"
|
2023-07-26 22:36:22 +08:00
|
|
|
block:
|
2022-02-16 08:35:02 +08:00
|
|
|
- name: Calico | Check if extra directory is needed
|
|
|
|
stat:
|
2023-07-05 11:36:54 +08:00
|
|
|
path: "{{ local_release_dir }}/calico-{{ calico_version }}-kdd-crds/{{ 'kdd' if (calico_version is version('v3.22.3', '<')) else 'crd' }}"
|
2022-02-16 08:35:02 +08:00
|
|
|
register: kdd_path
|
2022-06-01 04:27:23 +08:00
|
|
|
- name: Calico | Set kdd path when calico < v3.22.3
|
2022-02-16 08:35:02 +08:00
|
|
|
set_fact:
|
|
|
|
calico_kdd_path: "{{ local_release_dir }}/calico-{{ calico_version }}-kdd-crds{{ '/kdd' if kdd_path.stat.exists is defined and kdd_path.stat.exists }}"
|
2022-06-01 04:27:23 +08:00
|
|
|
when:
|
|
|
|
- calico_version is version('v3.22.3', '<')
|
|
|
|
- name: Calico | Set kdd path when calico > v3.22.2
|
|
|
|
set_fact:
|
|
|
|
calico_kdd_path: "{{ local_release_dir }}/calico-{{ calico_version }}-kdd-crds{{ '/crd' if kdd_path.stat.exists is defined and kdd_path.stat.exists }}"
|
|
|
|
when:
|
|
|
|
- calico_version is version('v3.22.2', '>')
|
2021-03-19 08:06:36 +08:00
|
|
|
- name: Calico | Create calico manifests for kdd
|
|
|
|
assemble:
|
2022-02-16 08:35:02 +08:00
|
|
|
src: "{{ calico_kdd_path }}"
|
2021-03-19 08:06:36 +08:00
|
|
|
dest: "{{ kube_config_dir }}/kdd-crds.yml"
|
2024-07-26 09:42:20 +08:00
|
|
|
mode: "0644"
|
2021-04-22 01:45:51 +08:00
|
|
|
delimiter: "---\n"
|
2021-03-19 08:06:36 +08:00
|
|
|
regexp: ".*\\.yaml"
|
|
|
|
remote_src: true
|
|
|
|
|
|
|
|
- name: Calico | Create Calico Kubernetes datastore resources
|
|
|
|
kube:
|
|
|
|
kubectl: "{{ bin_dir }}/kubectl"
|
|
|
|
filename: "{{ kube_config_dir }}/kdd-crds.yml"
|
|
|
|
state: "latest"
|
2023-05-16 12:21:36 +08:00
|
|
|
register: kubectl_result
|
|
|
|
until: kubectl_result is succeeded
|
|
|
|
retries: 5
|
2021-03-19 08:06:36 +08:00
|
|
|
when:
|
2021-03-24 08:26:05 +08:00
|
|
|
- inventory_hostname == groups['kube_control_plane'][0]
|
2019-07-08 17:20:03 +08:00
|
|
|
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Calico | Configure Felix
|
2023-08-10 15:57:27 +08:00
|
|
|
when:
|
|
|
|
- inventory_hostname == groups['kube_control_plane'][0]
|
2023-07-26 22:36:22 +08:00
|
|
|
block:
|
2022-05-12 20:02:19 +08:00
|
|
|
- name: Calico | Get existing FelixConfiguration
|
|
|
|
command: "{{ bin_dir }}/calicoctl.sh get felixconfig default -o json"
|
|
|
|
register: _felix_cmd
|
2024-08-28 13:30:56 +08:00
|
|
|
ignore_errors: true
|
|
|
|
changed_when: false
|
2022-05-12 20:02:19 +08:00
|
|
|
|
|
|
|
- name: Calico | Set kubespray FelixConfiguration
|
|
|
|
set_fact:
|
|
|
|
_felix_config: >
|
|
|
|
{
|
|
|
|
"kind": "FelixConfiguration",
|
|
|
|
"apiVersion": "projectcalico.org/v3",
|
|
|
|
"metadata": {
|
|
|
|
"name": "default",
|
|
|
|
},
|
|
|
|
"spec": {
|
|
|
|
"ipipEnabled": {{ calico_ipip_mode != 'Never' }},
|
|
|
|
"reportingInterval": "{{ calico_felix_reporting_interval }}",
|
|
|
|
"bpfLogLevel": "{{ calico_bpf_log_level }}",
|
|
|
|
"bpfEnabled": {{ calico_bpf_enabled | bool }},
|
|
|
|
"bpfExternalServiceMode": "{{ calico_bpf_service_mode }}",
|
|
|
|
"wireguardEnabled": {{ calico_wireguard_enabled | bool }},
|
|
|
|
"logSeverityScreen": "{{ calico_felix_log_severity_screen }}",
|
2022-09-02 19:58:05 +08:00
|
|
|
"vxlanEnabled": {{ calico_vxlan_mode != 'Never' }},
|
2023-01-19 07:42:34 +08:00
|
|
|
"featureDetectOverride": "{{ calico_feature_detect_override }}",
|
|
|
|
"floatingIPs": "{{ calico_felix_floating_ips }}"
|
2022-05-12 20:02:19 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- name: Calico | Process FelixConfiguration
|
|
|
|
set_fact:
|
|
|
|
_felix_config: "{{ _felix_cmd.stdout | from_json | combine(_felix_config, recursive=True) }}"
|
|
|
|
when:
|
|
|
|
- _felix_cmd is success
|
|
|
|
|
|
|
|
- name: Calico | Configure calico FelixConfiguration
|
|
|
|
command:
|
|
|
|
cmd: "{{ bin_dir }}/calicoctl.sh apply -f -"
|
2023-07-05 11:36:54 +08:00
|
|
|
stdin: "{{ _felix_config is string | ternary(_felix_config, _felix_config | to_json) }}"
|
2024-08-28 13:30:56 +08:00
|
|
|
changed_when: false
|
2021-06-07 19:58:39 +08:00
|
|
|
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Calico | Configure Calico IP Pool
|
2023-08-10 15:57:27 +08:00
|
|
|
when:
|
|
|
|
- inventory_hostname == groups['kube_control_plane'][0]
|
2023-07-26 22:36:22 +08:00
|
|
|
block:
|
2022-05-12 20:25:26 +08:00
|
|
|
- name: Calico | Get existing calico network pool
|
|
|
|
command: "{{ bin_dir }}/calicoctl.sh get ippool {{ calico_pool_name }} -o json"
|
|
|
|
register: _calico_pool_cmd
|
2024-08-28 13:30:56 +08:00
|
|
|
ignore_errors: true
|
|
|
|
changed_when: false
|
2022-05-12 20:25:26 +08:00
|
|
|
|
|
|
|
- name: Calico | Set kubespray calico network pool
|
|
|
|
set_fact:
|
|
|
|
_calico_pool: >
|
|
|
|
{
|
|
|
|
"kind": "IPPool",
|
|
|
|
"apiVersion": "projectcalico.org/v3",
|
|
|
|
"metadata": {
|
|
|
|
"name": "{{ calico_pool_name }}",
|
|
|
|
},
|
|
|
|
"spec": {
|
2023-12-12 21:38:36 +08:00
|
|
|
"blockSize": {{ calico_pool_blocksize }},
|
2022-05-12 20:25:26 +08:00
|
|
|
"cidr": "{{ calico_pool_cidr | default(kube_pods_subnet) }}",
|
|
|
|
"ipipMode": "{{ calico_ipip_mode }}",
|
|
|
|
"vxlanMode": "{{ calico_vxlan_mode }}",
|
2023-07-05 11:36:54 +08:00
|
|
|
"natOutgoing": {{ nat_outgoing | default(false) }}
|
2022-05-12 20:25:26 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- name: Calico | Process calico network pool
|
|
|
|
when:
|
|
|
|
- _calico_pool_cmd is success
|
2023-10-31 00:37:43 +08:00
|
|
|
block:
|
|
|
|
- name: Calico | Get current calico network pool blocksize
|
|
|
|
set_fact:
|
|
|
|
_calico_blocksize: >
|
|
|
|
{
|
|
|
|
"spec": {
|
|
|
|
"blockSize": {{ (_calico_pool_cmd.stdout | from_json).spec.blockSize }}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
- name: Calico | Merge calico network pool
|
|
|
|
set_fact:
|
|
|
|
_calico_pool: "{{ _calico_pool_cmd.stdout | from_json | combine(_calico_pool, _calico_blocksize, recursive=True) }}"
|
2022-05-12 20:25:26 +08:00
|
|
|
|
|
|
|
- name: Calico | Configure calico network pool
|
|
|
|
command:
|
|
|
|
cmd: "{{ bin_dir }}/calicoctl.sh apply -f -"
|
2023-07-05 11:36:54 +08:00
|
|
|
stdin: "{{ _calico_pool is string | ternary(_calico_pool, _calico_pool | to_json) }}"
|
2024-08-28 13:30:56 +08:00
|
|
|
changed_when: false
|
2018-09-11 20:14:10 +08:00
|
|
|
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Calico | Configure Calico IPv6 Pool
|
2023-08-10 15:57:27 +08:00
|
|
|
when:
|
|
|
|
- inventory_hostname == groups['kube_control_plane'][0]
|
|
|
|
- enable_dual_stack_networks | bool
|
2023-07-26 22:36:22 +08:00
|
|
|
block:
|
2022-05-12 20:25:26 +08:00
|
|
|
- name: Calico | Get existing calico ipv6 network pool
|
|
|
|
command: "{{ bin_dir }}/calicoctl.sh get ippool {{ calico_pool_name }}-ipv6 -o json"
|
|
|
|
register: _calico_pool_ipv6_cmd
|
2024-08-28 13:30:56 +08:00
|
|
|
ignore_errors: true
|
|
|
|
changed_when: false
|
2022-05-12 20:25:26 +08:00
|
|
|
|
|
|
|
- name: Calico | Set kubespray calico network pool
|
|
|
|
set_fact:
|
|
|
|
_calico_pool_ipv6: >
|
|
|
|
{
|
|
|
|
"kind": "IPPool",
|
|
|
|
"apiVersion": "projectcalico.org/v3",
|
|
|
|
"metadata": {
|
|
|
|
"name": "{{ calico_pool_name }}-ipv6",
|
|
|
|
},
|
|
|
|
"spec": {
|
2023-12-12 21:38:36 +08:00
|
|
|
"blockSize": {{ calico_pool_blocksize_ipv6 }},
|
2022-05-12 20:25:26 +08:00
|
|
|
"cidr": "{{ calico_pool_cidr_ipv6 | default(kube_pods_subnet_ipv6) }}",
|
|
|
|
"ipipMode": "{{ calico_ipip_mode_ipv6 }}",
|
|
|
|
"vxlanMode": "{{ calico_vxlan_mode_ipv6 }}",
|
2023-07-05 11:36:54 +08:00
|
|
|
"natOutgoing": {{ nat_outgoing_ipv6 | default(false) }}
|
2022-05-12 20:25:26 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- name: Calico | Process calico ipv6 network pool
|
|
|
|
when:
|
|
|
|
- _calico_pool_ipv6_cmd is success
|
2023-10-31 00:37:43 +08:00
|
|
|
block:
|
|
|
|
- name: Calico | Get current calico ipv6 network pool blocksize
|
|
|
|
set_fact:
|
|
|
|
_calico_blocksize_ipv6: >
|
|
|
|
{
|
|
|
|
"spec": {
|
|
|
|
"blockSize": {{ (_calico_pool_ipv6_cmd.stdout | from_json).spec.blockSize }}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
- name: Calico | Merge calico ipv6 network pool
|
|
|
|
set_fact:
|
|
|
|
_calico_pool_ipv6: "{{ _calico_pool_ipv6_cmd.stdout | from_json | combine(_calico_pool_ipv6, _calico_blocksize_ipv6, recursive=True) }}"
|
2022-05-12 20:25:26 +08:00
|
|
|
|
|
|
|
- name: Calico | Configure calico ipv6 network pool
|
|
|
|
command:
|
|
|
|
cmd: "{{ bin_dir }}/calicoctl.sh apply -f -"
|
2023-07-05 11:36:54 +08:00
|
|
|
stdin: "{{ _calico_pool_ipv6 is string | ternary(_calico_pool_ipv6, _calico_pool_ipv6 | to_json) }}"
|
2024-08-28 13:30:56 +08:00
|
|
|
changed_when: false
|
2020-10-26 15:10:53 +08:00
|
|
|
|
2020-11-25 21:34:39 +08:00
|
|
|
- name: Populate Service External IPs
|
|
|
|
set_fact:
|
2023-07-05 11:36:54 +08:00
|
|
|
_service_external_ips: "{{ _service_external_ips | default([]) + [{'cidr': item}] }}"
|
2020-11-25 21:34:39 +08:00
|
|
|
with_items: "{{ calico_advertise_service_external_ips }}"
|
2024-08-28 13:30:56 +08:00
|
|
|
run_once: true
|
2020-11-25 21:34:39 +08:00
|
|
|
|
2021-05-12 20:22:17 +08:00
|
|
|
- name: Populate Service LoadBalancer IPs
|
|
|
|
set_fact:
|
2023-07-05 11:36:54 +08:00
|
|
|
_service_loadbalancer_ips: "{{ _service_loadbalancer_ips | default([]) + [{'cidr': item}] }}"
|
2021-05-12 20:22:17 +08:00
|
|
|
with_items: "{{ calico_advertise_service_loadbalancer_ips }}"
|
2024-08-28 13:30:56 +08:00
|
|
|
run_once: true
|
2021-05-12 20:22:17 +08:00
|
|
|
|
2018-08-23 22:17:18 +08:00
|
|
|
- name: "Determine nodeToNodeMesh needed state"
|
|
|
|
set_fact:
|
|
|
|
nodeToNodeMeshEnabled: "false"
|
|
|
|
when:
|
2023-07-05 11:36:54 +08:00
|
|
|
- peer_with_router | default(false) or peer_with_calico_rr | default(false)
|
2024-09-21 20:09:09 +08:00
|
|
|
- ('k8s_cluster' in group_names)
|
2024-08-28 13:30:56 +08:00
|
|
|
run_once: true
|
2018-08-23 22:17:18 +08:00
|
|
|
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Calico | Configure Calico BGP
|
2023-08-10 15:57:27 +08:00
|
|
|
when:
|
|
|
|
- inventory_hostname == groups['kube_control_plane'][0]
|
2023-07-26 22:36:22 +08:00
|
|
|
block:
|
2022-05-12 20:43:33 +08:00
|
|
|
- name: Calico | Get existing BGP Configuration
|
|
|
|
command: "{{ bin_dir }}/calicoctl.sh get bgpconfig default -o json"
|
|
|
|
register: _bgp_config_cmd
|
2024-08-28 13:30:56 +08:00
|
|
|
ignore_errors: true
|
|
|
|
changed_when: false
|
2022-05-12 20:43:33 +08:00
|
|
|
|
|
|
|
- name: Calico | Set kubespray BGP Configuration
|
|
|
|
set_fact:
|
2023-07-05 11:36:54 +08:00
|
|
|
# noqa: jinja[spacing]
|
2022-05-12 20:43:33 +08:00
|
|
|
_bgp_config: >
|
|
|
|
{
|
|
|
|
"kind": "BGPConfiguration",
|
|
|
|
"apiVersion": "projectcalico.org/v3",
|
|
|
|
"metadata": {
|
|
|
|
"name": "default",
|
|
|
|
},
|
|
|
|
"spec": {
|
|
|
|
"listenPort": {{ calico_bgp_listen_port }},
|
|
|
|
"logSeverityScreen": "Info",
|
2023-07-05 11:36:54 +08:00
|
|
|
{% if not calico_no_global_as_num | default(false) %}"asNumber": {{ global_as_num }},{% endif %}
|
|
|
|
"nodeToNodeMeshEnabled": {{ nodeToNodeMeshEnabled | default('true') }} ,
|
|
|
|
{% if calico_advertise_cluster_ips | default(false) %}
|
2022-05-12 20:43:33 +08:00
|
|
|
"serviceClusterIPs": [{"cidr": "{{ kube_service_addresses }}" } {{ ',{"cidr":"' + kube_service_addresses_ipv6 + '"}' if enable_dual_stack_networks else '' }}],{% endif %}
|
2023-07-05 11:36:54 +08:00
|
|
|
{% if calico_advertise_service_loadbalancer_ips | length > 0 %}"serviceLoadBalancerIPs": {{ _service_loadbalancer_ips }},{% endif %}
|
|
|
|
"serviceExternalIPs": {{ _service_external_ips | default([]) }}
|
2022-05-12 20:43:33 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- name: Calico | Process BGP Configuration
|
|
|
|
set_fact:
|
|
|
|
_bgp_config: "{{ _bgp_config_cmd.stdout | from_json | combine(_bgp_config, recursive=True) }}"
|
|
|
|
when:
|
|
|
|
- _bgp_config_cmd is success
|
|
|
|
|
|
|
|
- name: Calico | Set up BGP Configuration
|
|
|
|
command:
|
|
|
|
cmd: "{{ bin_dir }}/calicoctl.sh apply -f -"
|
2023-07-05 11:36:54 +08:00
|
|
|
stdin: "{{ _bgp_config is string | ternary(_bgp_config, _bgp_config | to_json) }}"
|
2024-08-28 13:30:56 +08:00
|
|
|
changed_when: false
|
2018-08-23 22:17:18 +08:00
|
|
|
|
2019-07-15 16:59:06 +08:00
|
|
|
- name: Calico | Create calico manifests
|
|
|
|
template:
|
|
|
|
src: "{{ item.file }}.j2"
|
|
|
|
dest: "{{ kube_config_dir }}/{{ item.file }}"
|
2024-07-26 09:42:20 +08:00
|
|
|
mode: "0644"
|
2019-07-15 16:59:06 +08:00
|
|
|
with_items:
|
|
|
|
- {name: calico-config, file: calico-config.yml, type: cm}
|
|
|
|
- {name: calico-node, file: calico-node.yml, type: ds}
|
|
|
|
- {name: calico, file: calico-node-sa.yml, type: sa}
|
|
|
|
- {name: calico, file: calico-cr.yml, type: clusterrole}
|
|
|
|
- {name: calico, file: calico-crb.yml, type: clusterrolebinding}
|
2021-06-07 19:58:39 +08:00
|
|
|
- {name: kubernetes-services-endpoint, file: kubernetes-services-endpoint.yml, type: cm }
|
2019-07-15 16:59:06 +08:00
|
|
|
register: calico_node_manifests
|
|
|
|
when:
|
2024-09-21 20:09:09 +08:00
|
|
|
- ('kube_control_plane' in group_names)
|
2019-07-15 16:59:06 +08:00
|
|
|
- rbac_enabled or item.type not in rbac_resources
|
|
|
|
|
|
|
|
- name: Calico | Create calico manifests for typha
|
|
|
|
template:
|
|
|
|
src: "{{ item.file }}.j2"
|
|
|
|
dest: "{{ kube_config_dir }}/{{ item.file }}"
|
2024-07-26 09:42:20 +08:00
|
|
|
mode: "0644"
|
2019-07-15 16:59:06 +08:00
|
|
|
with_items:
|
|
|
|
- {name: calico, file: calico-typha.yml, type: typha}
|
|
|
|
register: calico_node_typha_manifest
|
|
|
|
when:
|
2024-09-21 20:09:09 +08:00
|
|
|
- ('kube_control_plane' in group_names)
|
2022-04-08 15:02:42 +08:00
|
|
|
- typha_enabled
|
|
|
|
|
|
|
|
- name: Calico | get calico apiserver caBundle
|
|
|
|
command: "{{ bin_dir }}/kubectl get secret -n calico-apiserver calico-apiserver-certs -o jsonpath='{.data.apiserver\\.crt}'"
|
|
|
|
changed_when: false
|
|
|
|
register: calico_apiserver_cabundle
|
|
|
|
when:
|
|
|
|
- inventory_hostname == groups['kube_control_plane'][0]
|
|
|
|
- calico_apiserver_enabled
|
|
|
|
|
|
|
|
- name: Calico | set calico apiserver caBundle fact
|
|
|
|
set_fact:
|
|
|
|
calico_apiserver_cabundle: "{{ calico_apiserver_cabundle.stdout }}"
|
|
|
|
when:
|
|
|
|
- inventory_hostname == groups['kube_control_plane'][0]
|
|
|
|
- calico_apiserver_enabled
|
|
|
|
|
|
|
|
- name: Calico | Create calico manifests for apiserver
|
|
|
|
template:
|
|
|
|
src: "{{ item.file }}.j2"
|
|
|
|
dest: "{{ kube_config_dir }}/{{ item.file }}"
|
2024-07-26 09:42:20 +08:00
|
|
|
mode: "0644"
|
2022-04-08 15:02:42 +08:00
|
|
|
with_items:
|
|
|
|
- {name: calico, file: calico-apiserver.yml, type: calico-apiserver}
|
|
|
|
register: calico_apiserver_manifest
|
|
|
|
when:
|
2024-09-21 20:09:09 +08:00
|
|
|
- ('kube_control_plane' in group_names)
|
2022-04-08 15:02:42 +08:00
|
|
|
- calico_apiserver_enabled
|
2019-07-15 16:59:06 +08:00
|
|
|
|
|
|
|
- name: Start Calico resources
|
|
|
|
kube:
|
|
|
|
name: "{{ item.item.name }}"
|
|
|
|
namespace: "kube-system"
|
|
|
|
kubectl: "{{ bin_dir }}/kubectl"
|
|
|
|
resource: "{{ item.item.type }}"
|
|
|
|
filename: "{{ kube_config_dir }}/{{ item.item.file }}"
|
|
|
|
state: "latest"
|
|
|
|
with_items:
|
|
|
|
- "{{ calico_node_manifests.results }}"
|
|
|
|
- "{{ calico_node_typha_manifest.results }}"
|
|
|
|
when:
|
2021-03-24 08:26:05 +08:00
|
|
|
- inventory_hostname == groups['kube_control_plane'][0]
|
2019-07-15 16:59:06 +08:00
|
|
|
- not item is skipped
|
|
|
|
loop_control:
|
|
|
|
label: "{{ item.item.file }}"
|
|
|
|
|
2022-04-08 15:02:42 +08:00
|
|
|
- name: Start Calico apiserver resources
|
|
|
|
kube:
|
|
|
|
name: "{{ item.item.name }}"
|
|
|
|
namespace: "calico-apiserver"
|
|
|
|
kubectl: "{{ bin_dir }}/kubectl"
|
|
|
|
resource: "{{ item.item.type }}"
|
|
|
|
filename: "{{ kube_config_dir }}/{{ item.item.file }}"
|
|
|
|
state: "latest"
|
|
|
|
with_items:
|
|
|
|
- "{{ calico_apiserver_manifest.results }}"
|
|
|
|
when:
|
|
|
|
- inventory_hostname == groups['kube_control_plane'][0]
|
|
|
|
- not item is skipped
|
|
|
|
loop_control:
|
|
|
|
label: "{{ item.item.file }}"
|
|
|
|
|
2019-07-15 16:59:06 +08:00
|
|
|
- name: Wait for calico kubeconfig to be created
|
|
|
|
wait_for:
|
|
|
|
path: /etc/cni/net.d/calico-kubeconfig
|
2023-04-18 21:58:58 +08:00
|
|
|
timeout: "{{ calico_kubeconfig_wait_timeout }}"
|
2019-07-15 16:59:06 +08:00
|
|
|
when:
|
2021-03-24 08:26:05 +08:00
|
|
|
- inventory_hostname not in groups['kube_control_plane']
|
2019-07-15 16:59:06 +08:00
|
|
|
- calico_datastore == "kdd"
|
|
|
|
|
2022-05-20 02:13:20 +08:00
|
|
|
- name: Calico | Create Calico ipam manifests
|
|
|
|
template:
|
|
|
|
src: "{{ item.file }}.j2"
|
|
|
|
dest: "{{ kube_config_dir }}/{{ item.file }}"
|
2024-07-26 09:42:20 +08:00
|
|
|
mode: "0644"
|
2022-05-20 02:13:20 +08:00
|
|
|
with_items:
|
|
|
|
- {name: calico, file: calico-ipamconfig.yml, type: ipam}
|
|
|
|
when:
|
2024-09-21 20:09:09 +08:00
|
|
|
- ('kube_control_plane' in group_names)
|
2022-08-30 13:41:00 +08:00
|
|
|
- calico_datastore == "kdd"
|
2022-05-20 02:13:20 +08:00
|
|
|
|
|
|
|
- name: Calico | Create ipamconfig resources
|
|
|
|
kube:
|
|
|
|
kubectl: "{{ bin_dir }}/kubectl"
|
|
|
|
filename: "{{ kube_config_dir }}/calico-ipamconfig.yml"
|
|
|
|
state: "latest"
|
2022-08-31 12:13:01 +08:00
|
|
|
register: resource_result
|
|
|
|
until: resource_result is succeeded
|
|
|
|
retries: 4
|
2022-03-08 14:58:33 +08:00
|
|
|
when:
|
2022-05-18 00:52:27 +08:00
|
|
|
- inventory_hostname == groups['kube_control_plane'][0]
|
2022-08-30 13:41:00 +08:00
|
|
|
- calico_datastore == "kdd"
|
2022-08-18 15:52:37 +08:00
|
|
|
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Calico | Peer with Calico Route Reflector
|
|
|
|
include_tasks: peer_with_calico_rr.yml
|
2022-08-18 15:52:37 +08:00
|
|
|
when:
|
2023-07-05 11:36:54 +08:00
|
|
|
- peer_with_calico_rr | default(false)
|
2022-08-18 15:52:37 +08:00
|
|
|
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Calico | Peer with the router
|
|
|
|
include_tasks: peer_with_router.yml
|
2022-08-18 15:52:37 +08:00
|
|
|
when:
|
2023-07-05 11:36:54 +08:00
|
|
|
- peer_with_router | default(false)
|