Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 18 additions & 10 deletions roles/ocp4_workload_gitops_bootstrap/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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 }}"
38 changes: 4 additions & 34 deletions roles/ocp4_workload_gitops_bootstrap/tasks/workload.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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 }}"
Expand All @@ -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 }}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down

This file was deleted.

Loading