ArgoCD e ApplicationSet¶
O ArgoCD gerencia o deploy de todas as aplicações nos clusters HML e NOX. A estratégia central é o padrão App of Apps via ApplicationSet.
Arquitetura¶
flowchart TB
subgraph tools["Cluster TOOLS"]
ARGO[ArgoCD v9.1.0]
APPSET[ApplicationSet<br/>apps-of-apps]
end
subgraph git["GitHub"]
TC[ads-tenants-config<br/>tenants/oci/*/*/*/app-config.yaml]
HELM[ads-helm-charts<br/>ghcr.io/ads-saude/*]
end
subgraph hml["Cluster HML"]
H1[tre/auth-api]
H2[tre/is-core-ui]
H3[afpes/auth-api]
H4[...]
end
subgraph nox["Cluster NOX"]
N1[cmd-prd/auth-api]
N2[cmd-tre/auth-api]
N3[...]
end
APPSET -->|"Git Generator<br/>scan app-config.yaml"| TC
APPSET -->|"Cluster Generator<br/>match env label"| hml
APPSET -->|"Cluster Generator<br/>match env label"| nox
TC -->|values.yaml| hml
TC -->|values.yaml| nox
HELM -->|chart OCI| hml
HELM -->|chart OCI| nox
ApplicationSet: apps-of-apps¶
O recurso ApplicationSet usa um Matrix Generator que combina duas fontes:
Git Generator¶
Escaneia o repositório ads-tenants-config buscando arquivos no padrão:
tenants/oci/*/*/*/app-config.yaml
Cada match gera variáveis baseadas nos segmentos do path:
| Path | Segmento | Índice | Exemplo |
|---|---|---|---|
tenants |
— | 0 | — |
oci |
— | 1 | — |
hml |
Ambiente | 2 | hml |
tre |
Tenant | 3 | tre |
auth-api |
Aplicação | 4 | auth-api |
Do app-config.yaml, extrai o campo chartVersion para determinar a versão do chart Helm.
Cluster Generator¶
Seleciona o cluster destino filtrando pela label env que corresponde ao segmento de ambiente do path.
Resultado: Uma Application por Combinação¶
Para cada app-config.yaml encontrado × cluster correspondente, o ApplicationSet gera uma Application com:
| Campo | Valor | Exemplo |
|---|---|---|
| Nome | {env}-{app}-{tenant} |
hml-auth-api-tre |
| Projeto ArgoCD | {tenant}-{env} |
tre-hml |
| Namespace destino | {tenant} |
tre |
| Chart source | oci://ghcr.io/ads-saude/{app} |
Chart OCI do registry |
| Chart version | chartVersion do app-config.yaml |
1.0.0 |
| Values source | tenants/oci/{env}/{tenant}/{app}/values.yaml |
Git repo |
Dual Source¶
Cada Application usa duas fontes (multi-source):
- Helm Chart via OCI — o chart com templates e defaults
- Values via Git — os overrides específicos do tenant vindos do
ads-tenants-config
SyncPolicy¶
yaml
syncPolicy:
automated:
prune: true # Remove recursos órfãos
selfHeal: true # Restaura drift automaticamente
syncOptions:
- CreateNamespace=true
- ServerSideApply=true
- PruneLast=true
- ApplyOutOfSyncOnly=true
Auto-sync sempre ativo
Com selfHeal: true, qualquer alteração manual no cluster é revertida automaticamente. Todas as mudanças devem ser feitas via Git.
Projetos ArgoCD¶
Os projetos são criados automaticamente via Terraform (infrastructure/modules/argocd/tenants.tf):
- Nome:
{namespace}-{env}(ex:tre-hml) - Destino: cluster
OKE-{ENV}→ namespace{tenant} - Source repos: lista compartilhada de repositórios permitidos
Cada tenant tem seu próprio projeto, garantindo isolamento de permissões.
Fluxo de Deploy¶
sequenceDiagram
participant DEV as Desenvolvedor
participant GH as GitHub Actions
participant OCIR as Container Registry
participant TC as ads-tenants-config
participant ARGO as ArgoCD
participant K8S as Cluster K8s
DEV->>GH: Merge PR (development)
GH->>GH: Build + Tag (8.0.0-DEV)
GH->>OCIR: Push imagem
GH->>TC: Update values.yaml<br/>(image.tag + digest)
TC->>ARGO: Git webhook / poll
ARGO->>ARGO: Detecta diff no ApplicationSet
ARGO->>K8S: Sync (helm upgrade)
K8S-->>ARGO: Status: Synced + Healthy
Manutenção do Auto-Sync¶
Para manutenções que exigem desabilitar o auto-sync temporariamente:
Desabilitar¶
O workflow tenant-disable-auto-sync.yml (dispatch manual):
- Faz backup do ApplicationSet
- Patcha removendo
automatede reduzindosyncOptions - Deleta deployments do tenant no cluster alvo
Reabilitar¶
O workflow tenant-enable-auto-sync.yml (dispatch manual):
- Faz backup do ApplicationSet
- Restaura
syncPolicy.automatedcomprune: trueeselfHeal: true
Sempre reabilitar após manutenção
Não esquecer de executar o workflow de reabilitar. Sem auto-sync, novas versões deployadas não serão aplicadas automaticamente.