From 7a294113890263c32b1c60c3cc535f51ba33b3ce Mon Sep 17 00:00:00 2001 From: Ted Cook Date: Thu, 30 May 2024 21:56:29 -0600 Subject: [PATCH] Add ArgoCD resource tracking method parameter Enable application deployment on all namespaces --- defaults/main/argocd.yml | 4 ++++ tasks/deploy.yml | 2 +- tasks/deploy/argocd.yml | 13 ++++++++++++- tasks/verify.yml | 2 +- tasks/verify/argocd.yml | 20 ++++++++++---------- 5 files changed, 28 insertions(+), 13 deletions(-) diff --git a/defaults/main/argocd.yml b/defaults/main/argocd.yml index 512f787..6927db9 100644 --- a/defaults/main/argocd.yml +++ b/defaults/main/argocd.yml @@ -21,6 +21,10 @@ k8s_argocd_chart_values: replicas: 2 applicationSet: replicas: 2 + configs: + params: + application.namespaces: "*" +k8s_argocd_resourceTrackingMethod: label k8s_argocd_apps_namespace: "argocd" k8s_argocd_apps_wait_timeout: "{{ k8s_wait_timeout }}" k8s_argocd_apps_chart: diff --git a/tasks/deploy.yml b/tasks/deploy.yml index 50ab957..9addd2b 100644 --- a/tasks/deploy.yml +++ b/tasks/deploy.yml @@ -23,7 +23,7 @@ ansible.builtin.include_tasks: "deploy/longhorn.yml" when: k8s_longhorn_deploy | bool -- name: Include argocd deployment tasks +- name: Include ArgoCD deployment tasks ansible.builtin.include_tasks: "deploy/argocd.yml" when: k8s_argocd_deploy | bool diff --git a/tasks/deploy/argocd.yml b/tasks/deploy/argocd.yml index f85d9b3..5c615a9 100644 --- a/tasks/deploy/argocd.yml +++ b/tasks/deploy/argocd.yml @@ -6,7 +6,7 @@ _config: "{{ k8s_kubeconfig }}" _resource: 'argocd-repo-server' -- name: Install argocd chart +- name: Install ArgoCD chart kubernetes.core.helm: name: argocd chart_ref: "{{ k8s_argocd_chart.name }}" @@ -50,6 +50,17 @@ _reposerver_query: "{{ query(_query, kind='Deployment', namespace=_ns, resource_name=_resource, kubeconfig=_config) }}" changed_when: false +- name: Configure ArgoCD resource tracking method + kubernetes.core.k8s: + api_version: v1 + kind: ConfigMap + namespace: "{{ k8s_argocd_namespace }}" + name: argocd-cm + kubeconfig: "{{ k8s_kubeconfig | default(omit) }}" + definition: + data: + application.resourceTrackingMethod: "{{ k8s_argocd_resourceTrackingMethod }}" + - name: Deploy argocd ingress kubernetes.core.k8s: namespace: "{{ k8s_argocd_namespace }}" diff --git a/tasks/verify.yml b/tasks/verify.yml index 30efdcc..1e4221f 100644 --- a/tasks/verify.yml +++ b/tasks/verify.yml @@ -27,7 +27,7 @@ - name: Include Helm checks ansible.builtin.include_tasks: verify/helm.yml - - name: Include argocd checks + - name: Include ArgoCD checks ansible.builtin.include_tasks: verify/argocd.yml when: k8s_argocd_verify | bool diff --git a/tasks/verify/argocd.yml b/tasks/verify/argocd.yml index 7260dcc..d8256ba 100644 --- a/tasks/verify/argocd.yml +++ b/tasks/verify/argocd.yml @@ -11,7 +11,7 @@ vars: _reposerver_query: "{{ query(_query, kind='Deployment', namespace=_ns, resource_name='argocd-repo-server', kubeconfig=_config) }}" -- name: Query argocd ingress metadata +- name: Query ArgoCD ingress metadata ansible.builtin.set_fact: ingress_argocd_ip: "{{ ingress_query[0][_status][_lb][_ingress][0][_ip] }}" vars: @@ -32,26 +32,26 @@ - ingress_query[0][_status][_lb][_ingress] | length > 0 - _ip in ingress_query[0][_status][_lb][_ingress][0] -- name: Record argocd deployment env vars +- name: Record ArgoCD deployment env vars ansible.builtin.set_fact: argocd_env: "{{ _argocd_env }}" argocd_env_exec_item: "{{ _argocd_env | selectattr('name', 'equalto', 'ARGOCD_EXEC_TIMEOUT') }}" vars: _argocd_env: "{{ _reposerver_def.spec.template.spec.containers[0].env }}" -- name: Check argocd exec timeout parameter +- name: Check ArgoCD exec timeout parameter ansible.builtin.assert: that: argocd_env_exec_item | length > 0 fail_msg: "env var ARGOCD_EXEC_TIMEOUT is not set" -- name: Check argocd exec timeout value +- name: Check ArgoCD exec timeout value ansible.builtin.assert: that: argocd_env_exec_value == k8s_argocd_exec_timeout fail_msg: "env var ARGOCD_EXEC_TIMEOUT is not set correctly ({{ argocd_env_exec_value }})" vars: argocd_env_exec_value: "{{ argocd_env_exec_item[0].value }}" -- name: Query argocd access info +- name: Query ArgoCD access info ansible.builtin.set_fact: _argocd_secret_query: "{{ _secrets }}" vars: @@ -61,14 +61,14 @@ delay: "{{ k8s_retry_delay }}" until: _secrets | length > 0 -- name: Record argocd auth credentials +- name: Record ArgoCD auth credentials ansible.builtin.set_fact: argocd_admin_username: "admin" argocd_admin_password: "{{ _argocd_secret_data.data.password | b64decode }}" vars: _argocd_secret_data: "{{ _argocd_secret_query | first }}" -- name: Auth against argocd api +- name: Auth against ArgoCD API ansible.builtin.uri: url: "https://{{ ingress_argocd_ip }}/api/v1/session" method: POST @@ -81,13 +81,13 @@ validate_certs: false register: argocd_auth_data -- name: Record argocd auth token +- name: Record ArgoCD auth token ansible.builtin.set_fact: argocd_admin_token: "{{ argocd_auth_data.json.token }}" -- name: Verify argocd application status +- name: Verify ArgoCD application status block: - - name: Query argocd application status + - name: Query ArgoCD application status ansible.builtin.uri: url: "https://{{ ingress_argocd_ip }}/api/v1/applications?refresh=true" headers: