From cbfdc92f2d969ab24580f00f5c615eaeafaf7489 Mon Sep 17 00:00:00 2001 From: prakhar Date: Sun, 8 Feb 2026 00:00:32 +1100 Subject: [PATCH 1/3] Enable userinfo ConfigMap discovery in gitops_bootstrap Uncomment the demo.redhat.com/userinfo ConfigMap discovery block so GitOps deployments can report user-facing data (URLs, credentials) back to Babylon via agnosticd_user_info. Supports both global data and per-user data via users_json. --- .../tasks/workload.yml | 96 +++++++++---------- 1 file changed, 48 insertions(+), 48 deletions(-) diff --git a/roles/ocp4_workload_gitops_bootstrap/tasks/workload.yml b/roles/ocp4_workload_gitops_bootstrap/tasks/workload.yml index fc06f6a..23f385c 100644 --- a/roles/ocp4_workload_gitops_bootstrap/tasks/workload.yml +++ b/roles/ocp4_workload_gitops_bootstrap/tasks/workload.yml @@ -73,51 +73,51 @@ ####### ####### Begin processing GitOps output ####### -# -# - name: Retrieve ConfigMaps with the demo.redhat.com/userinfo label -# kubernetes.core.k8s_info: -# api_version: v1 -# kind: ConfigMap -# label_selectors: -# - "demo.redhat.com/userdata" -# register: cm_userdata -# -# - name: If ConfigMaps were found, process them -# when: -# - cm_userdata.resources is defined -# - cm_userdata.resources | length | int > 0 -# block: -# - name: Add to agnosticd_user_info all data from ConfigMaps except configmap.data.users_json data -# agnosticd.core.agnosticd_user_info: -# data: >- -# {{ item | dict2items | selectattr('key', 'ne', 'users_json') | items2dict }} -# loop: "{{ cm_userdata.resources | map(attribute='data') }}" -# -# - name: Prepare data_user_json to add to agnosticd_user_info -# ansible.builtin.debug: -# msg: "Prepare data_user_json to add to agnosticd_user_info" -# -# - name: Merge list of all users_json data from all ConfigMaps that have data.users_json -# ansible.builtin.set_fact: -# data_users_json: "{{ data_users_json | default([]) | combine(item.data.users_json | from_json, recursive=True) }}" -# loop: "{{ cm_userdata.resources }}" -# when: item.data.users_json is defined -# -# - name: Handle data_users_json data -# when: data_users_json is defined -# block: -# - name: Debug merged data_users_json data -# ansible.builtin.debug: -# msg: "{{ data_users_json }}" -# -# - name: Add to agnosticd_user_info all configmap.data.users_json ConfigMap data -# agnosticd.core.agnosticd_user_info: -# user: "{{ item.key }}" -# data: -# "{{ item.value }}" -# loop: "{{ data_users_json.users | dict2items }}" -# when: data_users_json is defined -# -# - name: Debug user_data -# ansible.builtin.debug: -# msg: "{{ lookup('agnosticd_user_data', '*') }}" + +- name: Retrieve ConfigMaps with the demo.redhat.com/userinfo label + kubernetes.core.k8s_info: + api_version: v1 + kind: ConfigMap + label_selectors: + - "demo.redhat.com/userinfo" + register: cm_userinfo + +- name: If ConfigMaps were found, process them + when: + - cm_userinfo.resources is defined + - cm_userinfo.resources | length | int > 0 + block: + - name: Add to agnosticd_user_info all data from ConfigMaps except configmap.data.users_json data + agnosticd.core.agnosticd_user_info: + data: >- + {{ item | dict2items | selectattr('key', 'ne', 'users_json') | items2dict }} + loop: "{{ cm_userinfo.resources | map(attribute='data') }}" + + - name: Prepare data_user_json to add to agnosticd_user_info + ansible.builtin.debug: + msg: "Prepare data_user_json to add to agnosticd_user_info" + + - name: Merge list of all users_json data from all ConfigMaps that have data.users_json + ansible.builtin.set_fact: + data_users_json: "{{ data_users_json | default([]) | combine(item.data.users_json | from_json, recursive=True) }}" + loop: "{{ cm_userinfo.resources }}" + when: item.data.users_json is defined + + - name: Handle data_users_json data + when: data_users_json is defined + block: + - name: Debug merged data_users_json data + ansible.builtin.debug: + msg: "{{ data_users_json }}" + + - name: Add to agnosticd_user_info all configmap.data.users_json ConfigMap data + agnosticd.core.agnosticd_user_info: + user: "{{ item.key }}" + data: + "{{ item.value }}" + loop: "{{ data_users_json.users | dict2items }}" + when: data_users_json is defined + +- name: Debug user_data + ansible.builtin.debug: + msg: "{{ lookup('agnosticd_user_data', '*') }}" From be90b6020e50e9034677ff84197caf838821af7e Mon Sep 17 00:00:00 2001 From: prakhar Date: Tue, 3 Mar 2026 19:14:20 +1100 Subject: [PATCH 2/3] feat: add resources-finalizer to bootstrap Application and implement remove_workload --- .../tasks/remove_workload.yml | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/roles/ocp4_workload_gitops_bootstrap/tasks/remove_workload.yml b/roles/ocp4_workload_gitops_bootstrap/tasks/remove_workload.yml index 573d4e4..32cd9bd 100644 --- a/roles/ocp4_workload_gitops_bootstrap/tasks/remove_workload.yml +++ b/roles/ocp4_workload_gitops_bootstrap/tasks/remove_workload.yml @@ -1,11 +1,16 @@ --- -- name: Set application paths and final application name - ansible.builtin.include_tasks: set_application_paths.yml - -- name: Remove bootstrap ArgoCD application +# Delete the bootstrap Application. +# Because the Application has resources-finalizer.argocd.argoproj.io, +# ArgoCD will cascade-delete all child Applications and their managed +# Kubernetes resources before the Application is fully removed. +- name: Delete bootstrap ArgoCD Application kubernetes.core.k8s: + state: absent api_version: argoproj.io/v1alpha1 kind: Application - name: "{{ ocp4_workload_gitops_bootstrap_final_application_name }}" + name: "{{ ocp4_workload_gitops_bootstrap_final_application_name + | default(ocp4_workload_gitops_bootstrap_application_name) }}" namespace: "{{ ocp4_workload_gitops_bootstrap_namespace }}" - state: absent \ No newline at end of file + wait: true + wait_timeout: 300 + ignore_errors: true From 3f169b81c673a52e062a3f848b690210292e9338 Mon Sep 17 00:00:00 2001 From: prakhar Date: Tue, 3 Mar 2026 21:09:47 +1100 Subject: [PATCH 3/3] feat: add multi-application support via ocp4_workload_gitops_bootstrap_applications list --- .../defaults/main.yml | 17 +++++++ .../tasks/remove_workload.yml | 27 +++++++++-- .../tasks/workload.yml | 48 +++++++++++++++++++ 3 files changed, 87 insertions(+), 5 deletions(-) diff --git a/roles/ocp4_workload_gitops_bootstrap/defaults/main.yml b/roles/ocp4_workload_gitops_bootstrap/defaults/main.yml index e9e661d..16f0403 100644 --- a/roles/ocp4_workload_gitops_bootstrap/defaults/main.yml +++ b/roles/ocp4_workload_gitops_bootstrap/defaults/main.yml @@ -2,6 +2,23 @@ ocp4_workload_gitops_bootstrap_repo_url: http://gitea:3000/user/bootstrap ocp4_workload_gitops_bootstrap_repo_revision: main +# Multi-application mode: create multiple bootstrap Applications in one role call. +# When set, all other ocp4_workload_gitops_bootstrap_* vars are ignored. +# Each entry supports: name, path, project (optional), repo_url (optional), +# repo_revision (optional), helm_values (optional) +# +# Example: +# ocp4_workload_gitops_bootstrap_applications: +# - name: bootstrap-infra +# path: infra/bootstrap +# - name: bootstrap-platform +# path: platform/bootstrap +# project: platform +# helm_values: +# deployer: +# domain: "{{ openshift_cluster_ingress_domain }}" +ocp4_workload_gitops_bootstrap_applications: [] + # Examples to support multi-tenancy: # # Example 1: Backwards compatibility. Deploys INFRA and N number of tenants diff --git a/roles/ocp4_workload_gitops_bootstrap/tasks/remove_workload.yml b/roles/ocp4_workload_gitops_bootstrap/tasks/remove_workload.yml index 32cd9bd..3481792 100644 --- a/roles/ocp4_workload_gitops_bootstrap/tasks/remove_workload.yml +++ b/roles/ocp4_workload_gitops_bootstrap/tasks/remove_workload.yml @@ -1,9 +1,26 @@ --- -# Delete the bootstrap Application. -# Because the Application has resources-finalizer.argocd.argoproj.io, -# ArgoCD will cascade-delete all child Applications and their managed -# Kubernetes resources before the Application is fully removed. -- name: Delete bootstrap ArgoCD Application +# Delete bootstrap Applications. +# resources-finalizer.argocd.argoproj.io causes ArgoCD to cascade-delete +# all child Applications and their managed resources before removal. + +- name: Delete multiple bootstrap Applications (multi-app mode) + when: ocp4_workload_gitops_bootstrap_applications | length > 0 + kubernetes.core.k8s: + state: absent + api_version: argoproj.io/v1alpha1 + kind: Application + name: "{{ app_item.name }}" + namespace: "{{ ocp4_workload_gitops_bootstrap_namespace }}" + wait: true + wait_timeout: 300 + loop: "{{ ocp4_workload_gitops_bootstrap_applications }}" + loop_control: + loop_var: app_item + label: "{{ app_item.name }}" + ignore_errors: true + +- name: Delete single bootstrap Application (single-app mode) + when: ocp4_workload_gitops_bootstrap_applications | length == 0 kubernetes.core.k8s: state: absent api_version: argoproj.io/v1alpha1 diff --git a/roles/ocp4_workload_gitops_bootstrap/tasks/workload.yml b/roles/ocp4_workload_gitops_bootstrap/tasks/workload.yml index 23f385c..ac8108a 100644 --- a/roles/ocp4_workload_gitops_bootstrap/tasks/workload.yml +++ b/roles/ocp4_workload_gitops_bootstrap/tasks/workload.yml @@ -11,6 +11,54 @@ ansible.builtin.debug: msg: "{{ _ocp4_workload_gitops_bootstrap_deployer_values | to_yaml }}" + +# ================================================================== +# Multi-application mode: create multiple Applications in one call. +# Runs when ocp4_workload_gitops_bootstrap_applications list is set. +# ================================================================== +- name: Create multiple bootstrap ArgoCD applications + when: ocp4_workload_gitops_bootstrap_applications | length > 0 + kubernetes.core.k8s: + state: present + definition: + apiVersion: argoproj.io/v1alpha1 + kind: Application + metadata: + name: "{{ app_item.name }}" + namespace: "{{ ocp4_workload_gitops_bootstrap_namespace }}" + finalizers: + - resources-finalizer.argocd.argoproj.io + spec: + project: "{{ app_item.project | default('default') }}" + source: + repoURL: "{{ app_item.repo_url | default(ocp4_workload_gitops_bootstrap_repo_url) }}" + targetRevision: "{{ app_item.repo_revision | default(ocp4_workload_gitops_bootstrap_repo_revision) }}" + path: "{{ app_item.path }}" + helm: + values: | + {{ (app_item.helm_values | default({})) + | combine(_ocp4_workload_gitops_bootstrap_deployer_values) + | to_nice_yaml + | indent(width=14, first=False) }} + destination: + namespace: "{{ ocp4_workload_gitops_bootstrap_namespace }}" + server: https://kubernetes.default.svc + syncPolicy: + automated: + prune: false + selfHeal: false + loop: "{{ ocp4_workload_gitops_bootstrap_applications }}" + loop_control: + loop_var: app_item + label: "{{ app_item.name }}" + +- name: End play when multi-application mode used (no single-app logic needed) + when: ocp4_workload_gitops_bootstrap_applications | length > 0 + ansible.builtin.meta: end_play + +# ================================================================== +# Single-application mode (default) +# ================================================================== - name: Set application paths and final application name ansible.builtin.include_tasks: set_application_paths.yml