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: 10 additions & 18 deletions roles/ocp4_workload_gitops_bootstrap/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,18 @@
ocp4_workload_gitops_bootstrap_repo_url: http://gitea:3000/user/bootstrap
ocp4_workload_gitops_bootstrap_repo_revision: main

# 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 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

# The path within the git repository where the ArgoCD application manifests are located.
ocp4_workload_gitops_bootstrap_repo_path: ""
#'bootstrap-tenant-{{ guid }}' or 'bootstrap-infra' or 'bootstrap'

# 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

# 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,11 +1,9 @@
---
- 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_final_application_name }}"
name: "{{ ocp4_workload_gitops_bootstrap_application_name }}"
namespace: "{{ ocp4_workload_gitops_bootstrap_namespace }}"
state: absent
state: absent

This file was deleted.

38 changes: 34 additions & 4 deletions roles/ocp4_workload_gitops_bootstrap/tasks/workload.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,38 @@
ansible.builtin.debug:
msg: "{{ _ocp4_workload_gitops_bootstrap_deployer_values | to_yaml }}"

- name: Set application paths and final application name
ansible.builtin.include_tasks: set_application_paths.yml
- 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: Create bootstrap ArgoCD application
kubernetes.core.k8s:
Expand All @@ -36,7 +66,7 @@
kubernetes.core.k8s_info:
api_version: argoproj.io/v1alpha1
kind: Application
name: "{{ ocp4_workload_gitops_bootstrap_final_application_name }}"
name: "{{ ocp4_workload_gitops_bootstrap_application_name }}"
namespace: openshift-gitops
register: argocd_bootstrap
retries: "{{ ocp4_workload_gitops_bootstrap_health_retries }}"
Expand All @@ -62,7 +92,7 @@
api_version: argoproj.io/v1alpha1
kind: Application
label_selectors:
- "app.kubernetes.io/instance={{ ocp4_workload_gitops_bootstrap_final_application_name }}"
- "app.kubernetes.io/instance={{ ocp4_workload_gitops_bootstrap_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_final_application_name }}"
name: "{{ ocp4_workload_gitops_bootstrap_application_name }}"
namespace: {{ ocp4_workload_gitops_bootstrap_namespace }}
finalizers:
- resources-finalizer.argocd.argoproj.io
spec:
project: "{{ ocp4_workload_gitops_bootstrap_application_project_name | default('default') }}"
project: "{{ ocp4_workload_gitops_bootstrap_application_project }}"
source:
repoURL: {{ ocp4_workload_gitops_bootstrap_repo_url }}
targetRevision: {{ ocp4_workload_gitops_bootstrap_repo_revision }}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
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: '*'
Loading