diff --git a/inventory/sample/group_vars/k8s_cluster/k8s-net-custom-cni.yml b/inventory/sample/group_vars/k8s_cluster/k8s-net-custom-cni.yml index 67b048103..2287cf288 100644 --- a/inventory/sample/group_vars/k8s_cluster/k8s-net-custom-cni.yml +++ b/inventory/sample/group_vars/k8s_cluster/k8s-net-custom-cni.yml @@ -49,3 +49,15 @@ # custom_cni_chart_values: # cluster: # name: "cilium-demo" + +## Preflight - Deploy network files prior to CNI +## It can be used when preparatory work such as deploying CRDs is required +## prior to CNI distribution, as if the `kubectl create -f` method (present) +## or `kubectl apply -f` (latest) was used with it. +# +## List of Kubernetes network resource files +## Example: +# custom_cni_preflight_templates: +# - path: https://raw.githubusercontent.com/prometheus-operator/prometheus-operator/main/example/prometheus-operator-crd/monitoring.coreos.com_servicemonitors.yaml +# namespace: "kube-system" # default: "kube-system" +# state: present # options: [latest, present, absent] diff --git a/roles/kubernetes-apps/network_plugin/custom_cni/tasks/main.yml b/roles/kubernetes-apps/network_plugin/custom_cni/tasks/main.yml new file mode 100644 index 000000000..3ecee2e11 --- /dev/null +++ b/roles/kubernetes-apps/network_plugin/custom_cni/tasks/main.yml @@ -0,0 +1,11 @@ +--- +- name: Custom CNI | Preflight | Start Resources + kube: + namespace: "{{ item.namespace | default('kube-system') }}" + kubectl: "{{ bin_dir }}/kubectl" + filename: "{{ item.path }}" + state: "{{ item.state }}" + wait: true + loop: "{{ custom_cni_preflight_templates }}" + delegate_to: "{{ groups['kube_control_plane'] | first }}" + run_once: true diff --git a/roles/network_plugin/custom_cni/defaults/main.yml b/roles/network_plugin/custom_cni/defaults/main.yml index 0eab14374..12e3d7b4d 100644 --- a/roles/network_plugin/custom_cni/defaults/main.yml +++ b/roles/network_plugin/custom_cni/defaults/main.yml @@ -1,5 +1,7 @@ --- +custom_cni_preflight_templates: [] + custom_cni_manifests: [] custom_cni_chart_namespace: kube-system diff --git a/roles/network_plugin/custom_cni/meta/main.yml b/roles/network_plugin/custom_cni/meta/main.yml index 361c406de..088ab8bc2 100644 --- a/roles/network_plugin/custom_cni/meta/main.yml +++ b/roles/network_plugin/custom_cni/meta/main.yml @@ -1,5 +1,13 @@ --- dependencies: + - role: kubernetes-apps/network_plugin/custom_cni + when: + - inventory_hostname == groups['kube_control_plane'][0] + - custom_cni_chart_release_name | length > 0 + environment: + http_proxy: "{{ http_proxy | default('') }}" + https_proxy: "{{ https_proxy | default('') }}" + - role: helm-apps when: - inventory_hostname == groups['kube_control_plane'][0]