From 7e9564de927cc71f28b81a60e59b1541dcfabed4 Mon Sep 17 00:00:00 2001 From: Judd Maltin Date: Tue, 17 Mar 2026 10:02:35 -0400 Subject: [PATCH] Revert "ocp4_workload_gitops_bootstrap: Simplify multi-tenancy config (#90)" This reverts commit 0d6595a491241152864cb242fd519a49f72a2051. --- .../defaults/main.yml | 28 +++++++++----- .../tasks/remove_workload.yml | 6 ++- .../tasks/set_application_paths.yml | 31 +++++++++++++++ .../tasks/workload.yml | 38 ++----------------- .../templates/application.yaml.j2 | 4 +- .../templates/appproject.yaml.j2 | 19 ---------- 6 files changed, 59 insertions(+), 67 deletions(-) create mode 100644 roles/ocp4_workload_gitops_bootstrap/tasks/set_application_paths.yml delete mode 100644 roles/ocp4_workload_gitops_bootstrap/templates/appproject.yaml.j2 diff --git a/roles/ocp4_workload_gitops_bootstrap/defaults/main.yml b/roles/ocp4_workload_gitops_bootstrap/defaults/main.yml index b5a3791..e9e661d 100644 --- a/roles/ocp4_workload_gitops_bootstrap/defaults/main.yml +++ b/roles/ocp4_workload_gitops_bootstrap/defaults/main.yml @@ -2,18 +2,26 @@ ocp4_workload_gitops_bootstrap_repo_url: http://gitea:3000/user/bootstrap ocp4_workload_gitops_bootstrap_repo_revision: main -# The name of the ArgoCD application to create for bootstrapping. -# If you are deploying a tenant application, this should be unique across all tenants. -# You should use "bootstrap-{{ guid }}" -ocp4_workload_gitops_bootstrap_application_name: bootstrap +# Examples to support multi-tenancy: +# +# Example 1: Backwards compatibility. Deploys INFRA and N number of tenants +# ocp4_workload_gitops_bootstrap_application_name: 'bootstrap' +# ocp4_workload_gitops_bootstrap_repo_path: "" +# ocp4_workload_gitops_bootstrap_helm_values: +# user: +# count: 3 +# +# Example 2: Deploy ONLY the infra: +# ocp4_workload_gitops_bootstrap_application_name: 'bootstrap-infra' +# ocp4_workload_gitops_bootstrap_repo_path: infra +# +# Example 3: Deploy ONE tenant +# ocp4_workload_gitops_bootstrap_application_name: 'bootstrap-tenant-{{ guid }}' +# ocp4_workload_gitops_bootstrap_repo_path: tenant -# The path within the git repository where the ArgoCD application manifests are located. +ocp4_workload_gitops_bootstrap_application_name: bootstrap ocp4_workload_gitops_bootstrap_repo_path: "" - -# The ArgoCD project to deploy the bootstrap application into. -# This is not the same as the git repo path. -# You should use "tenants" if deploying a tenant application. -ocp4_workload_gitops_bootstrap_application_project: default +#'bootstrap-tenant-{{ guid }}' or 'bootstrap-infra' or 'bootstrap' # We cannot do k8s_info on annotations, # so when deploying openshift_gitops, diff --git a/roles/ocp4_workload_gitops_bootstrap/tasks/remove_workload.yml b/roles/ocp4_workload_gitops_bootstrap/tasks/remove_workload.yml index b65c81c..573d4e4 100644 --- a/roles/ocp4_workload_gitops_bootstrap/tasks/remove_workload.yml +++ b/roles/ocp4_workload_gitops_bootstrap/tasks/remove_workload.yml @@ -1,9 +1,11 @@ --- +- name: Set application paths and final application name + ansible.builtin.include_tasks: set_application_paths.yml - name: Remove bootstrap ArgoCD application kubernetes.core.k8s: api_version: argoproj.io/v1alpha1 kind: Application - name: "{{ ocp4_workload_gitops_bootstrap_application_name }}" + name: "{{ ocp4_workload_gitops_bootstrap_final_application_name }}" namespace: "{{ ocp4_workload_gitops_bootstrap_namespace }}" - state: absent + state: absent \ No newline at end of file diff --git a/roles/ocp4_workload_gitops_bootstrap/tasks/set_application_paths.yml b/roles/ocp4_workload_gitops_bootstrap/tasks/set_application_paths.yml new file mode 100644 index 0000000..8249e3f --- /dev/null +++ b/roles/ocp4_workload_gitops_bootstrap/tasks/set_application_paths.yml @@ -0,0 +1,31 @@ +--- +- name: Set App paths for 'bootstrap', infra + tenants deployment scenario + when: ocp4_workload_gitops_bootstrap_application_name == 'bootstrap' + ansible.builtin.set_fact: + ocp4_workload_gitops_bootstrap_repo_path: "bootstrap" + +- name: Set App path for 'bootstrap-platform', platform only deployment scenario + when: ocp4_workload_gitops_bootstrap_application_name == 'bootstrap-platform' + ansible.builtin.set_fact: + ocp4_workload_gitops_bootstrap_repo_path: "platform/bootstrap" + +- name: Set App path for 'bootstrap-infra', infra only deployment scenario + when: ocp4_workload_gitops_bootstrap_application_name == 'bootstrap-infra' + ansible.builtin.set_fact: + ocp4_workload_gitops_bootstrap_repo_path: "infra/bootstrap" + +- name: "Set App path and name for 'bootstrap-tenant', infra only deployment scenario" + when: ocp4_workload_gitops_bootstrap_application_name == 'bootstrap-tenant' + ansible.builtin.set_fact: + ocp4_workload_gitops_bootstrap_repo_path: "tenant/bootstrap" + ocp4_workload_gitops_bootstrap_final_application_name: "bootstrap-tenant-{{ guid }}" + ocp4_workload_gitops_bootstrap_application_project_name: "tenants" + +- name: Set final_application_name to application_name if final_application_name is not set + when: ocp4_workload_gitops_bootstrap_final_application_name is not defined + ansible.builtin.set_fact: + ocp4_workload_gitops_bootstrap_final_application_name: "{{ ocp4_workload_gitops_bootstrap_application_name }}" + +- name: Report bootstrap final application name + ansible.builtin.debug: + msg: "Bootstrap final application name: {{ ocp4_workload_gitops_bootstrap_final_application_name }}" \ No newline at end of file diff --git a/roles/ocp4_workload_gitops_bootstrap/tasks/workload.yml b/roles/ocp4_workload_gitops_bootstrap/tasks/workload.yml index d340ab8..3fd6963 100644 --- a/roles/ocp4_workload_gitops_bootstrap/tasks/workload.yml +++ b/roles/ocp4_workload_gitops_bootstrap/tasks/workload.yml @@ -13,38 +13,8 @@ ansible.builtin.debug: msg: "{{ _ocp4_workload_gitops_bootstrap_deployer_values | to_yaml }}" -- name: Check if ArgoCD application already exists - kubernetes.core.k8s_info: - api_version: argoproj.io/v1alpha1 - kind: Application - name: "{{ ocp4_workload_gitops_bootstrap_application_name }}" - namespace: "{{ ocp4_workload_gitops_bootstrap_namespace }}" - register: _existing_application - -- name: Fail if ArgoCD application already exists - ansible.builtin.fail: - msg: >- - ArgoCD Application '{{ ocp4_workload_gitops_bootstrap_application_name }}' - already exists in namespace '{{ ocp4_workload_gitops_bootstrap_namespace }}'). - If you are running a tenant application, set a unique name. - when: _existing_application.resources | length > 0 - -- name: Ensure ArgoCD AppProject exists - when: ocp4_workload_gitops_bootstrap_application_project != 'default' - block: - - name: Check if ArgoCD AppProject exists - kubernetes.core.k8s_info: - api_version: argoproj.io/v1alpha1 - kind: AppProject - name: "{{ ocp4_workload_gitops_bootstrap_application_project }}" - namespace: openshift-gitops - register: _existing_appproject - - - name: Create ArgoCD AppProject - when: _existing_appproject.resources | length == 0 - kubernetes.core.k8s: - state: present - template: appproject.yaml.j2 +- name: Set application paths and final application name + ansible.builtin.include_tasks: set_application_paths.yml - name: Create bootstrap ArgoCD application kubernetes.core.k8s: @@ -66,7 +36,7 @@ kubernetes.core.k8s_info: api_version: argoproj.io/v1alpha1 kind: Application - name: "{{ ocp4_workload_gitops_bootstrap_application_name }}" + name: "{{ ocp4_workload_gitops_bootstrap_final_application_name }}" namespace: openshift-gitops register: argocd_bootstrap retries: "{{ ocp4_workload_gitops_bootstrap_health_retries }}" @@ -92,7 +62,7 @@ api_version: argoproj.io/v1alpha1 kind: Application label_selectors: - - "app.kubernetes.io/instance={{ ocp4_workload_gitops_bootstrap_application_name }}" + - "app.kubernetes.io/instance={{ ocp4_workload_gitops_bootstrap_final_application_name }}" register: _all_apps delay: 10 retries: "{{ ocp4_workload_gitops_bootstrap_application_health_retries }}" diff --git a/roles/ocp4_workload_gitops_bootstrap/templates/application.yaml.j2 b/roles/ocp4_workload_gitops_bootstrap/templates/application.yaml.j2 index 81a1360..d2602d4 100644 --- a/roles/ocp4_workload_gitops_bootstrap/templates/application.yaml.j2 +++ b/roles/ocp4_workload_gitops_bootstrap/templates/application.yaml.j2 @@ -2,12 +2,12 @@ apiVersion: argoproj.io/v1alpha1 kind: Application metadata: - name: "{{ ocp4_workload_gitops_bootstrap_application_name }}" + name: "{{ ocp4_workload_gitops_bootstrap_final_application_name }}" namespace: {{ ocp4_workload_gitops_bootstrap_namespace }} finalizers: - resources-finalizer.argocd.argoproj.io spec: - project: "{{ ocp4_workload_gitops_bootstrap_application_project }}" + project: "{{ ocp4_workload_gitops_bootstrap_application_project_name | default('default') }}" source: repoURL: {{ ocp4_workload_gitops_bootstrap_repo_url }} targetRevision: {{ ocp4_workload_gitops_bootstrap_repo_revision }} diff --git a/roles/ocp4_workload_gitops_bootstrap/templates/appproject.yaml.j2 b/roles/ocp4_workload_gitops_bootstrap/templates/appproject.yaml.j2 deleted file mode 100644 index f72d163..0000000 --- a/roles/ocp4_workload_gitops_bootstrap/templates/appproject.yaml.j2 +++ /dev/null @@ -1,19 +0,0 @@ ---- -apiVersion: argoproj.io/v1alpha1 -kind: AppProject -metadata: - name: "{{ ocp4_workload_gitops_bootstrap_application_project }}" - namespace: openshift-gitops -spec: - description: "Auto-created project for {{ ocp4_workload_gitops_bootstrap_application_project }}" - sourceRepos: - - '*' - destinations: - - namespace: '*' - server: '*' - clusterResourceWhitelist: - - group: '*' - kind: '*' - namespaceResourceWhitelist: - - group: '*' - kind: '*'