From ba7e233c2709c3337354c8309005bddf154e95bc Mon Sep 17 00:00:00 2001 From: Danny Bessems Date: Thu, 12 Oct 2023 11:24:56 +0200 Subject: [PATCH] feat: Store cluster API provider manifests --- .../workloadcluster/tasks/clusterapi.yml | 54 +++++++++++++------ 1 file changed, 39 insertions(+), 15 deletions(-) diff --git a/ansible/roles/firstboot/files/ansible_payload/bootstrap/roles/workloadcluster/tasks/clusterapi.yml b/ansible/roles/firstboot/files/ansible_payload/bootstrap/roles/workloadcluster/tasks/clusterapi.yml index ea982b5..b4a885d 100644 --- a/ansible/roles/firstboot/files/ansible_payload/bootstrap/roles/workloadcluster/tasks/clusterapi.yml +++ b/ansible/roles/firstboot/files/ansible_payload/bootstrap/roles/workloadcluster/tasks/clusterapi.yml @@ -85,6 +85,40 @@ --kubeconfig {{ kubeconfig.path }} chdir: /opt/metacluster/cluster-api +- name: Initialize tempfolder + ansible.builtin.tempfile: + state: directory + register: capi_clustermanifest + +- name: Pull existing repository + ansible.builtin.git: + repo: https://git.{{ vapp['metacluster.fqdn'] }}/mc/GitOps.ClusterAPI.git + dest: "{{ capi_clustermanifest.path }}" + version: main + +- name: Generate Cluster API provider manifests + ansible.builtin.shell: + cmd: >- + clusterctl generate provider \ + -v5 \ + --{{ item.type }} {{ item.name }}:{{ item.version }} \ + --config ./clusterctl.yaml > {{ capi_clustermanifest.path }}/provider-{{ item.name }}.yaml + chdir: /opt/metacluster/cluster-api + loop: + - type: infrastructure + name: vsphere + version: "{{ components.clusterapi.management.version.infrastructure_vsphere }}" + - type: ipam + name: in-cluster + version: "{{ components.clusterapi.management.version.ipam_incluster }}" + +- name: Split cluster API provider manifests into separate files + ansible.builtin.shell: + cmd: >- + awk 'BEGINFILE {print "---"}{print}' provider-*.yaml | \ + kubectl slice \ + -o {{ capi_clustermanifest.path }}/providers + - name: Ensure controller availability kubernetes.core.k8s_info: kind: Deployment @@ -124,17 +158,6 @@ chdir: /opt/metacluster/cluster-api register: clusterctl_newcluster -- name: Initialize tempfolder - ansible.builtin.tempfile: - state: directory - register: capi_clustermanifest - -- name: Pull existing repository - ansible.builtin.git: - repo: https://git.{{ vapp['metacluster.fqdn'] }}/mc/GitOps.ClusterAPI.git - dest: "{{ capi_clustermanifest.path }}" - version: main - - name: Save workload cluster manifest ansible.builtin.copy: dest: "{{ capi_clustermanifest.path }}/new-cluster.yaml" @@ -145,7 +168,7 @@ cmd: >- kubectl slice \ -f {{ capi_clustermanifest.path }}/new-cluster.yaml \ - -o {{ capi_clustermanifest.path }}/manifests + -o {{ capi_clustermanifest.path }}/downstream-cluster - name: Generate nodepool kustomization manifest ansible.builtin.template: @@ -169,12 +192,12 @@ cmd: >- kubectl slice \ -f {{ capi_clustermanifest.path }}/nodepool-worker-storage.yaml \ - -o {{ capi_clustermanifest.path }}/manifests + -o {{ capi_clustermanifest.path }}/downstream-cluster - name: Create in-cluster IpPool ansible.builtin.template: src: ippool.j2 - dest: "{{ capi_clustermanifest.path }}/manifests/inclusterippool-{{ _template.cluster.name }}.yml" + dest: "{{ capi_clustermanifest.path }}/downstream-cluster/inclusterippool-{{ _template.cluster.name }}.yml" vars: _template: cluster: @@ -192,7 +215,8 @@ branch: main comment: "Upload manifests" add: - - ./manifests + - ./downstream-cluster + - ./providers clean: untracked url: https://administrator:{{ vapp['metacluster.password'] | urlencode }}@git.{{ vapp['metacluster.fqdn'] }}/mc/GitOps.ClusterAPI.git environment: