From cbedc9679f714c26076fa18218b43bafac6c44d7 Mon Sep 17 00:00:00 2001 From: Danny Bessems Date: Fri, 7 Jul 2023 16:48:32 +0200 Subject: [PATCH] feat: Add version/metadata API endpoint --- ansible/roles/assets/tasks/manifests.yml | 6 ++-- .../roles/metacluster/tasks/json-server.yml | 27 +++++++++++++++++ .../roles/metacluster/tasks/main.yml | 1 + ansible/vars/metacluster.yml | 30 +++++++++++++++++++ 4 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 ansible/roles/firstboot/files/ansible_payload/bootstrap/roles/metacluster/tasks/json-server.yml diff --git a/ansible/roles/assets/tasks/manifests.yml b/ansible/roles/assets/tasks/manifests.yml index 52068fb..ef537f3 100644 --- a/ansible/roles/assets/tasks/manifests.yml +++ b/ansible/roles/assets/tasks/manifests.yml @@ -16,14 +16,16 @@ { 'components': ( metacluster_chartvalues | combine({ 'clusterapi': components.clusterapi }) | - combine({ 'kubevip' : components.kubevip }) ) + combine({ 'kubevip' : components.kubevip }) ), + 'appliance': { + 'version': (applianceversion) + } } | to_nice_yaml(indent=2, width=4096) }} - name: Aggregate chart_values into dict ansible.builtin.set_fact: workloadcluster_chartvalues: "{{ workloadcluster_chartvalues | default({}) | combine({ item.key: { 'chart_values': (item.value.chart_values | default('') | from_yaml) } }) }}" - # when: item.value.chart_values is defined loop: "{{ query('ansible.builtin.dict', downstream.helm_charts) }}" loop_control: label: "{{ item.key }}" diff --git a/ansible/roles/firstboot/files/ansible_payload/bootstrap/roles/metacluster/tasks/json-server.yml b/ansible/roles/firstboot/files/ansible_payload/bootstrap/roles/metacluster/tasks/json-server.yml new file mode 100644 index 0000000..ab0ca72 --- /dev/null +++ b/ansible/roles/firstboot/files/ansible_payload/bootstrap/roles/metacluster/tasks/json-server.yml @@ -0,0 +1,27 @@ +- block: + - name: Install json-server chart + kubernetes.core.helm: + name: json-server + chart_ref: /opt/metacluster/helm-charts/json-server + release_namespace: json-server + create_namespace: true + wait: false + kubeconfig: "{{ kubeconfig.path }}" + values: "{{ components['json-server'].chart_values }}" + + - name: Ensure json-server API availability + ansible.builtin.uri: + url: https://version.{{ vapp['metacluster.fqdn'] }}/healthz + method: GET + register: api_readycheck + until: + - api_readycheck.json.status is defined + - api_readycheck.json.status == 'running' + retries: "{{ playbook.retries }}" + delay: "{{ (storage_benchmark | int) * (playbook.delay.long | int) }}" + + module_defaults: + ansible.builtin.uri: + validate_certs: no + status_code: [200, 201] + body_format: json diff --git a/ansible/roles/firstboot/files/ansible_payload/bootstrap/roles/metacluster/tasks/main.yml b/ansible/roles/firstboot/files/ansible_payload/bootstrap/roles/metacluster/tasks/main.yml index b08f420..d8054e1 100644 --- a/ansible/roles/firstboot/files/ansible_payload/bootstrap/roles/metacluster/tasks/main.yml +++ b/ansible/roles/firstboot/files/ansible_payload/bootstrap/roles/metacluster/tasks/main.yml @@ -1,5 +1,6 @@ - import_tasks: init.yml - import_tasks: k3s.yml +- import_tasks: json-server.yml - import_tasks: assets.yml - import_tasks: kube-vip.yml - import_tasks: storage.yml diff --git a/ansible/vars/metacluster.yml b/ansible/vars/metacluster.yml index 2d0ca1b..2a39245 100644 --- a/ansible/vars/metacluster.yml +++ b/ansible/vars/metacluster.yml @@ -51,6 +51,8 @@ platform: url: https://prometheus-community.github.io/helm-charts - name: smallstep url: https://smallstep.github.io/helm-charts/ + - name: spamasaurus + url: https://code.spamasaurus.com/api/packages/djpbessems/helm components: @@ -225,6 +227,34 @@ components: registry: size: 25Gi + json-server: + helm: + version: v0.5.1 + chart: spamasaurus/json-server + parse_logic: helm template . | yq --no-doc eval '.. | .image? | select(.)' | sort -u | awk '!/ /' + chart_values: !unsafe | + ingress: + enabled: true + hosts: + - host: version.{{ vapp['metacluster.fqdn'] }} + paths: + - path: / + pathType: Prefix + seedData: + configInline: | + { + "appliance": { "version": "{{ appliance.version }}" }, + "components": [ + { "app": "argo-cd", "version": "{{ components[argo-cd].helm.version }}" }, + { "app": "cert-manager", "version": "{{ components[cert-manager].helm.version }}" }, + { "app": "cluster-api", + "management": { "foo": "bar" }, + "workload": { "foo": "bar" } + } + ], + "healthz": { "status": "running" } + } + # keycloakx: # helm: # version: 2.1.1 # (= Keycloak 20.0.3)