refactor(k3s): enhance cluster setup and enable ArgoCD apps

Signed-off-by: Tuan-Dat Tran <tuan-dat.tran@tudattr.dev>
This commit is contained in:
Tuan-Dat Tran
2025-07-22 07:23:09 +02:00
parent e1a2248154
commit 976cad51e2
38 changed files with 401 additions and 234 deletions

View File

@@ -0,0 +1,2 @@
argocd_apps_repo_url: ssh://git@git.tudattr.dev/tudattr/argocd.git
argocd_apps_target_revision: main

View File

@@ -0,0 +1,10 @@
- name: Render Argo CD Application YAML to a variable
ansible.builtin.set_fact:
argo_app_manifest: "{{ lookup('ansible.builtin.template', '../templates/argo_app.yaml.j2') }}"
- name: Apply Argo CD Application to Kubernetes using k8s module
kubernetes.core.k8s:
state: present
definition: "{{ argo_app_manifest }}"
register: k8s_apply_result
delegate_to: localhost

View File

@@ -0,0 +1,5 @@
- name: Install Argo Application
ansible.builtin.include_tasks: ./install_argo_app.yml
loop: argo_apps
loop_control:
loop_var: app

View File

@@ -0,0 +1,24 @@
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: {{ app.name }}
namespace: argocd
finalizers:
- resources-finalizer.argocd.argoproj.io
spec:
project: default
source:
repoURL: {{ argocd_apps_repo_url }}
targetRevision: {{ argocd_apps_target_revision | default("HEAD") }}
path: argocd/{{ app.name }}
directory:
recurse: true
destination:
server: https://kubernetes.default.svc
namespace: {{ argocd_apps_target_namespace | default(app.name) }}
syncPolicy:
automated:
prune: true
selfHeal: true
syncOptions:
- CreateNamespace=true

View File

@@ -0,0 +1,11 @@
apiVersion: argoproj.io/v1alpha1
kind: Repository
metadata:
name: {{ argocd_apps_repo_name }}
namespace: argocd
spec:
url: {{ argocd_apps_repo_url }}
type: git
sshPrivateKeySecret:
name: {{ argocd_apps_ssh_private_key_secret_name }}
key: {{ argocd_apps_ssh_private_key_secret_key }}