Skip to content

Commit

Permalink
Replace kustomize with lineinfile and use ansible assemble module
Browse files Browse the repository at this point in the history
  • Loading branch information
mirwan committed Mar 13, 2021
1 parent 595ec60 commit 76ae38d
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 98 deletions.
1 change: 0 additions & 1 deletion docs/offline-environment.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ crictl_download_url: "{{ files_repo }}/kubernetes/cri-tools/crictl-{{ crictl_ver
calicoctl_download_url: "{{ files_repo }}/kubernetes/calico/{{ calico_ctl_version }}/calicoctl-linux-{{ image_arch }}"
# If using Calico with kdd
calico_crds_download_url: "{{ files_repo }}/kubernetes/calico/{{ calico_version }}.tar.gz"
kustomize_download_url: "{{ files_repo }}/kubernetes/kustomize/{{ kustomize_version }}/kustomize_{{ kustomize_version }}_linux_{{ image_arch }}.tar.gz"

# CentOS/Redhat
## Docker / Containerd
Expand Down
1 change: 0 additions & 1 deletion inventory/sample/group_vars/k8s-cluster/offline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
# calicoctl_download_url: "{{ files_repo }}/kubernetes/calico/{{ calico_ctl_version }}/calicoctl-linux-{{ image_arch }}"
# [Optional] Calico with kdd: If using Calico network plugin with kdd datastore
# calico_crds_download_url: "{{ files_repo }}/kubernetes/calico/{{ calico_version }}.tar.gz"
# kustomize_download_url: "{{ files_repo }}/kubernetes/kustomize/{{ kustomize_version }}/kustomize_{{ kustomize_version }}_linux_{{ image_arch }}.tar.gz"

## CentOS/Redhat
### For EL7, base and extras repo must be available, for EL8, baseos and appstream
Expand Down
22 changes: 0 additions & 22 deletions roles/download/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ calico_policy_version: "{{ calico_version }}"
calico_typha_version: "{{ calico_version }}"
typha_enabled: false

kustomize_version: "v4.0.5"

flannel_version: "v0.13.0"
cni_version: "v0.9.0"
weave_version: 2.8.1
Expand Down Expand Up @@ -101,7 +99,6 @@ etcd_download_url: "https://github.com/coreos/etcd/releases/download/{{ etcd_ver
cni_download_url: "https://github.com/containernetworking/plugins/releases/download/{{ cni_version }}/cni-plugins-linux-{{ image_arch }}-{{ cni_version }}.tgz"
calicoctl_download_url: "https://github.com/projectcalico/calicoctl/releases/download/{{ calico_ctl_version }}/calicoctl-linux-{{ image_arch }}"
calico_crds_download_url: "https://github.com/projectcalico/calico/archive/{{ calico_version }}.tar.gz"
kustomize_download_url: "https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize%2F{{ kustomize_version }}/kustomize_{{ kustomize_version }}_linux_{{ image_arch }}.tar.gz"
crictl_download_url: "https://github.com/kubernetes-sigs/cri-tools/releases/download/{{ crictl_version }}/crictl-{{ crictl_version }}-{{ ansible_system | lower }}-{{ image_arch }}.tar.gz"
helm_download_url: "https://get.helm.sh/helm-{{ helm_version }}-linux-{{ image_arch }}.tar.gz"

Expand Down Expand Up @@ -427,10 +424,6 @@ calicoctl_binary_checksums:
calico_crds_archive_checksums:
v3.16.8: f3c2b87c560fc0114d07ef21214429c2c228431c75ea3ad28a23b12722531771
v3.15.2: 82e7122ec04a89c89861b8377c39ae357c7cdbbf60b5f0f1b8fc18ba6bda7dc2
kustomize_binary_checksums:
arm: 0
arm64: 6481a12eb63c42e267ec7806a478eb745cae2f7c4b7b8a8cc437e7dc054a5795
amd64: 3ef93195ede4b7664b7ec65284461dd8eeb9f5404e7db5eb5bf59003085a0c98

helm_archive_checksums:
arm:
Expand All @@ -453,7 +446,6 @@ kubectl_binary_checksum: "{{ kubectl_checksums[image_arch][kube_version] }}"
kubeadm_binary_checksum: "{{ kubeadm_checksums[image_arch][kubeadm_version] }}"
calicoctl_binary_checksum: "{{ calicoctl_binary_checksums[image_arch][calico_ctl_version] }}"
calico_crds_archive_checksum: "{{ calico_crds_archive_checksums[calico_version] }}"
kustomize_binary_checksum: "{{ kustomize_binary_checksums[image_arch] }}"
crictl_binary_checksum: "{{ crictl_checksums[image_arch][crictl_version] }}"
helm_archive_checksum: "{{ helm_archive_checksums[image_arch][helm_version] }}"

Expand Down Expand Up @@ -804,20 +796,6 @@ downloads:
groups:
- k8s-cluster

kustomize:
file: true
# kustomize standalone binary won't be required when updated in kubectl (https://github.com/kubernetes/kubernetes/pull/98946)
enabled: "{{ kube_network_plugin == 'calico' and calico_datastore == 'kdd' and kube_version is version('v1.21', '<') }}"
version: "{{ kustomize_version }}"
dest: "{{ local_release_dir }}/kustomize_{{ kustomize_version }}_linux_{{ image_arch }}.tar.gz"
sha256: "{{ kustomize_binary_checksum }}"
url: "{{ kustomize_download_url }}"
unarchive: true
owner: "root"
mode: "0755"
groups:
- kube-master

calico_crds:
file: true
enabled: "{{ kube_network_plugin == 'calico' and calico_datastore == 'kdd' }}"
Expand Down
74 changes: 19 additions & 55 deletions roles/network_plugin/calico/tasks/install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,76 +110,40 @@
- calico_pool_cidr_ipv6 is defined
- enable_dual_stack_networks

- name: Calico | Copy kustomize binary from download dir
copy:
src: "{{ local_release_dir }}/kustomize"
dest: "{{ bin_dir }}/kubectl"
mode: 0755
remote_src: true
when:
- inventory_hostname in groups['kube-master']
- calico_datastore == 'kdd'
- kube_version is version('v1.21', '<')

- name: Calico | Get the list of CRDs manifests
find:
paths: "{{ local_release_dir }}/calico-{{ calico_version }}-kdd-crds"
patterns: "^crd\\.projectcalico\\.org_.*?\\.ya?ml$"
use_regex: yes
register: calico_kdd_crds_manifests
when:
- inventory_hostname == groups['kube-master'][0]
- inventory_hostname in groups['kube-master']
- calico_datastore == 'kdd'

- name: Calico | Set manifests list to put kustomization.yml
set_fact:
calico_kdd_crds_manifests_list: "{{ calico_kdd_crds_manifests|map(attribute='path')|map('basename')|list }}"
delegate_to: "{{ host }}"
delegate_facts: true
loop: "{{ groups['kube-master'] }}"
no_log: true

- name: Calico | Replace unwanted annotations and creationTimestamp keys from metadata in Calico manifests
lineinfile:
path: "{{ item.0.path }}"
state: absent
regexp: "{{ item.1 }}"
loop: "{{ calico_kdd_crds_manifests.files|product(lines_to_remove)|list }}"
loop_control:
loop_var: host
when:
- inventory_hostname == groups['kube-master'][0]
- calico_datastore == 'kdd'

- name: Calico | Render kustomization.yml
template:
src: "kustomization.yml.j2"
dest: "{{ local_release_dir }}/calico-{{ calico_version }}-kdd-crds/kustomization.yml"
label: "{{ item.0.path|basename }}"
vars:
lines_to_remove:
- "^\\s{2,4}annotations:$"
- "^\\s{2,4}controller-gen\\.kubebuilder\\.io/version: \\(devel\\)$"
- "^\\s{2,4}creationTimestamp: null$"
when:
- inventory_hostname in groups['kube-master']
- calico_datastore == "kdd"

- name: Calico | Run kustomize
command: >-
{% if kube_version is version('v1.21', '<') %}
{{ bin_dir }}/kustomize build
{% else %}
{{ bin_dir }}/kubectl kustomize
{% endif %}
{{ local_release_dir }}/calico-{{ calico_version }}-kdd-crds
register: kdd_crds_whole_manifest
when:
- inventory_hostname == groups['kube-master'][0]
- calico_datastore == "kdd"

- name: Calico | Set kdd_crds_content
set_fact:
kdd_crds_content: "{{ kdd_crds_whole_manifest.stdout }}"
delegate_to: "{{ host }}"
delegate_facts: true
loop: "{{ groups['kube-master'] }}"
loop_control:
loop_var: host
when:
- inventory_hostname == groups['kube-master'][0]
- calico_datastore == 'kdd'

- name: Calico | Create calico manifests for kdd
copy:
content: "{{ kdd_crds_content }}"
assemble:
src: "{{ local_release_dir }}/calico-{{ calico_version }}-kdd-crds"
dest: "{{ kube_config_dir }}/{{ item.file }}"
regexp: ".*\\.yaml"
remote_src: true
with_items:
- {name: calico, file: kdd-crds.yml, type: kdd}
register: calico_node_kdd_manifest
Expand Down
19 changes: 0 additions & 19 deletions roles/network_plugin/calico/templates/kustomization.yml.j2

This file was deleted.

0 comments on commit 76ae38d

Please sign in to comment.