Fix kubeconfig source;(WIP)Register workloadcluster in argocd
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Danny Bessems 2023-01-06 16:27:33 +01:00
parent 36e3a2b99f
commit 2a5a154df0
2 changed files with 42 additions and 16 deletions

View File

@ -103,14 +103,18 @@
{{ clusterctl_newcluster.stdout }} {{ clusterctl_newcluster.stdout }}
wait: yes wait: yes
kubeconfig: "{{ kubeconfig.path }}" kubeconfig: "{{ kubeconfig.path }}"
# TODO: move to git repo
- name: Initialize tempfile - name: Initialize tempfile
ansible.builtin.tempfile: ansible.builtin.tempfile:
state: file state: file
register: capi_kubeconfig register: capi_kubeconfig
- name: Retrieve kubeconfig - name: Retrieve kubeconfig
ansible.builtin.command: ansible.builtin.command:
cmd: kubectl config view --raw cmd: clusterctl get kubeconfig {{ vapp['workloadcluster.name'] | lower }}
register: capi_kubectl_config register: capi_kubectl_config
- name: Store kubeconfig in tempfile - name: Store kubeconfig in tempfile
ansible.builtin.copy: ansible.builtin.copy:
dest: "{{ capi_kubeconfig.path }}" dest: "{{ capi_kubeconfig.path }}"
@ -129,23 +133,11 @@
retries: "{{ playbook.retries }}" retries: "{{ playbook.retries }}"
delay: "{{ playbook.delays.long }}" delay: "{{ playbook.delays.long }}"
- name: Generate serviceaccount # TODO: move to git repo
# TODO: move to GitOps
kubernetes.core.k8s:
template: serviceaccount.j2
state: present
kubeconfig: "{{ capi_kubeconfig.path }}"
vars:
_template:
account:
name: argocd-sa
namespace: default
clusterrolebinding:
name: argocd-crb
- name: Apply cni plugin manifest - name: Apply cni plugin manifest
# TODO: move to GitOps
kubernetes.core.k8s: kubernetes.core.k8s:
src: /opt/metacluster/cluster-api/cni-calico/{{ components.clusterapi.workload.version.calico }}/calico.yaml src: /opt/metacluster/cluster-api/cni-calico/{{ components.clusterapi.workload.version.calico }}/calico.yaml
state: present state: present
wait: yes wait: yes
kubeconfig: "{{ capi_kubeconfig.path }}" kubeconfig: "{{ capi_kubeconfig.path }}"
# TODO: move to git repo

View File

@ -1 +1,35 @@
# - name: Register workload cluster in argo-cd - block:
- name: Generate service account in workload cluster
kubernetes.core.k8s:
template: serviceaccount.j2
state: present
kubeconfig: "{{ capi_kubeconfig.path }}"
- name: Retrieve service account bearer token
kubernetes.core.k8s_info:
kind: ServiceAccount
name: "{{ _template.account.name }}"
namespace: "{{ _template.account.namespace }}"
register: workloadcluster_serviceaccount
- name: Retrieve service account bearer token
kubernetes.core.k8s_info:
kind: Secret
name: "{{ workloadcluster_serviceaccount.resources | json_query('[].secrets[].name') | first }}"
namespace: "{{ _template.account.namespace }}"
register: workloadcluster_bearertoken
- debug:
msg: "{{ workloadcluster_bearertoken.resources | json_query('[].data.token') }}"
vars:
_template:
account:
name: argocd-sa
namespace: default
clusterrolebinding:
name: argocd-crb
module_defaults:
group/k8s:
kubeconfig: "{{ capi_kubeconfig.path }}"