Skip to content

Commit

Permalink
Add ArgoCD resource tracking method parameter
Browse files Browse the repository at this point in the history
Enable application deployment on all namespaces
  • Loading branch information
teddyphreak committed May 31, 2024
1 parent abc8176 commit 7a29411
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 13 deletions.
4 changes: 4 additions & 0 deletions defaults/main/argocd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ k8s_argocd_chart_values:
replicas: 2
applicationSet:
replicas: 2
configs:
params:
application.namespaces: "*"
k8s_argocd_resourceTrackingMethod: label

Check failure on line 27 in defaults/main/argocd.yml

View workflow job for this annotation

GitHub Actions / lint

var-naming[pattern]

Variables names should match ^\[a-z_]\[a-z0-9_]*$ regex. (k8s_argocd_resourceTrackingMethod) (vars: k8s_argocd_resourceTrackingMethod)
k8s_argocd_apps_namespace: "argocd"
k8s_argocd_apps_wait_timeout: "{{ k8s_wait_timeout }}"
k8s_argocd_apps_chart:
Expand Down
2 changes: 1 addition & 1 deletion tasks/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 12 additions & 1 deletion tasks/deploy/argocd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}"
Expand Down Expand Up @@ -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 }}"
Expand Down
2 changes: 1 addition & 1 deletion tasks/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
20 changes: 10 additions & 10 deletions tasks/verify/argocd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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
Expand All @@ -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:
Expand Down

0 comments on commit 7a29411

Please sign in to comment.