# ArgoCD Manifests — URL Shortener

This directory contains all ArgoCD manifests for the URL shortener stack.
Used in Lesson 14 of the Cloud Infrastructure & DevOps course.

---

## 1. Install ArgoCD on `kind`

```bash
kubectl create namespace argocd
kubectl apply -n argocd \
  -f https://raw.githubusercontent.com/argoproj/argo-cd/v2.11.0/manifests/install.yaml
kubectl -n argocd rollout status deploy/argocd-server --timeout=5m
```

Pinned version: **v2.11.0**. The `install.yaml` in this directory documents the pin; apply the upstream URL above.

---

## 2. Port-forward to the UI

```bash
kubectl -n argocd port-forward svc/argocd-server 8080:443 &
```

Open <https://localhost:8080>. Accept the self-signed cert.

---

## 3. Initial admin password

```bash
kubectl -n argocd get secret argocd-initial-admin-secret \
  -o jsonpath='{.data.password}' | base64 -d ; echo
```

Log in as `admin` with the password printed above. Change the password immediately in production (`argocd account update-password`).

---

## 4. Bootstrap — App-of-Apps OR ApplicationSet (not both)

**Option A — App-of-Apps** (recommended for learning the sync-wave order):

```bash
# Edit repoURL in app-of-apps.yaml and children/*.yaml to point at your fork first.
kubectl apply -n argocd -f app-of-apps.yaml
```

A single root Application appears. ArgoCD discovers each YAML in `children/` and creates child Applications: `cert-manager`, `ingress-nginx`, `kube-prometheus-stack`, `url-shortener`. Sync waves ensure dependencies install before the app.

**Option B — ApplicationSet** (demonstrates multi-environment fan-out):

```bash
# Edit repoURL in appset-environments.yaml to point at your fork first.
kubectl apply -n argocd -f appset-environments.yaml
```

Three Applications are created: `url-shortener-dev`, `url-shortener-stage`, `url-shortener-prod`. Each uses a different values file and a different namespace.

**Do not apply both at the same time** — both manage an Application named `url-shortener` (or `url-shortener-prod`) and will conflict.

---

## 5. Sync-wave ordering recap

| Wave | Resources |
|------|-----------|
| −1   | cert-manager, ingress-nginx, kube-prometheus-stack |
| 0    | url-shortener (default; no annotation needed) |

Wave −1 resources reach `Healthy` before ArgoCD starts wave 0. This ensures CRDs and controllers are ready before the app tries to create `Ingress` and `Certificate` resources.

---

## 6. How to drive a deploy (git push workflow)

1. Edit `cloud-devops/sample-app/helm/values-prod.yaml` (e.g., bump `api.maxReplicas`).
2. Commit and push to `main`.
3. Within ~3 minutes ArgoCD detects the change, sets the Application `OutOfSync`, and syncs.
4. Watch in the UI or with `argocd app get url-shortener`.

No `kubectl`, no `helm upgrade`, no SSH.

---

## 7. HPA + selfHeal interaction

`automated.selfHeal: true` reverts any live edit back to what git says. The HPA is an exception: it writes `spec.replicas` to scale the Deployment, but that field is not in git (git might say `replicas: 3` while HPA has scaled to 8).

The `ignoreDifferences` block in `app-url-shortener.yaml` and `children/url-shortener.yaml` excludes `/spec/replicas` from ArgoCD's diff calculation. Result: HPA can freely adjust replicas; ArgoCD never reverts them. Every other field is still owned by git.

See [L14 theory](../../lesson14-gitops-argocd/theory.html) for the full explanation.
