# ApplicationSets

> The ApplicationSets in `argocd/appsets/` generate every Argo CD Application after bootstrap. The files carry a pointer here and a few short reasons, so this page is the reasoning behind them. Sync waves are in [DFE on Kubernetes on-premises](/v/2.2.2-fix.1/dfe-infra/deployment/on-prem.md#what-you-see).

## Layer 1 addons

`layer1-addons.yaml` deploys KEDA, metrics-server, Reloader and the DocumentDB operator. Chart versions must match `versions.yaml`. A `chartDigest` switches an element to Argo's OCI source at that digest, as `layer2-apps.yaml` does for thin charts. Envoy Gateway deploys from `bootstrap/`.

- cert-manager and external-secrets are bootstrap's. They have to exist before Argo does, because ESO backs the `ClusterSecretStore` and the repo credentials, and cert-manager backs the gateway certificates and the AWS Load Balancer Controller's webhook certificate. Listing them here would install a second copy beside bootstrap's (dfe-infra#4).
- KEDA pushes its scaler value, active flag and error counters to the collector gateway over OTLP instead of being scraped. The port is 4318 because KEDA's exporter speaks OTLP/HTTP and posts to `/v1/metrics`. The gRPC port answers with a frame it can't parse, and the URI needs its scheme. `OTEL_SERVICE_NAME` is set because KEDA sets none, so the Go SDK would group every KEDA series under `unknown_service:keda`.
- The DocumentDB operator serves HyperDX's document store, the `documentdb` chart in `layer2-data.yaml`. Its chart bundles CloudNativePG, installs it into `cnpg-system` and needs cert-manager. It is OCI only and the chart composes `repository:tag`, so each tag carries its image digest.
- The CloudNativePG image is held a patch above the chart's own, for GHSA-x8c2-3p4r-v9r6, GHSA-w3gf-xc94-wvmj and CVE-2026-84304. `helm/charts/documentdb` grants the EndpointSlice read the bundled chart lacks.

## DNS and AWS controllers

Three more elements sit behind cluster-label gates in `layer1-addons.yaml`.

- external-dns deploys only where the cluster secret declares a DNS provider. The chart's default provider is `aws`, so an unconfigured install fails every minute against Route 53 and publishes nothing (#223). The gate is `Exists` AND `NotIn`, because `NotIn` alone matches a secret with no `dfe.hyperi.io/dns-provider` label.
- The AWS Load Balancer Controller owns every Service annotated `aws-load-balancer-type: external`. Without it that Service sits at "Ensuring load balancer" forever, because the annotation also keeps the in-tree cloud provider off it.
- Karpenter provisions every node pool outside the managed group, which is sized for the cluster's own controllers.
- Both sync at wave 1 and are gated on the cloud label with `Exists` AND `In`. Karpenter publishes only over OCI, and its chart's `crds/` apply with the release, so a new CRD field arrives with the controller that reads it.
- `imageTag` and `imageDigest` for the load balancer controller are `services.aws-load-balancer-controller-image` in `versions.yaml`. Until a stack pins them the chart's own tag runs.

## Layer 2 apps

`layer2-apps.yaml` creates one Application per deploy-repo `values/<service>-<instance>-values.yaml`, whose `deploy: {service, instance}` block names it. Adding an instance is an engine git write and never an appset edit.

Each Application has four sources, in this order:

1. The component's thin chart, pulled over OCI from the registry its images come from, pinned by digest.
2. `helm/charts/dfe-extras`, the DFE-only objects beside it, at the target revision.
3. This repo as ref `infra`, at the same revision, for the value files.
4. The deploy repo as ref `values`, whose instance file is layered last.

Both helm sources read the same value files, parameters and inline values, so the engine overlay wins over every default in either. `ignoreMissingValueFiles` lets a chart run on its defaults until the engine publishes its overlay. Argo reads one revision per repo URL, so source 3 shares dfe-extras' revision, and a deploy repo naming the same repo at another revision fails the render.

- The chart digests are a literal map because an appset can't read `versions.yaml`. `scripts/check_versions_drift.py --fix` writes them. A service with no entry, or one whose chart isn't published, fails the render and its Application keeps its current spec.
- Helm refuses a release name past 53 characters, so both helm sources set `releaseName` only for a longer Application name: its first 44 characters plus 8 of its sha256.
- dfe-engine syncs at wave 5 and everything else at 7. The engine applies every ClickHouse object and bootstrap topic at startup and reports converged on `/readyz`, so its Application reaching Healthy is the schema being there. Wave 6, the collector, then has its otel tables.
- culvert is generated by `layer2-edge.yaml` where the edge module reaches the cluster, and excluded here so one generator owns it. A second generator covers clusters with no `dfe.hyperi.io/edge` key until dfe-infra#342. It uses `DoesNotExist` and not `NotIn`, because a deployer who set the key to `false` turned the edge off on purpose.
- `ignoreDifferences` leaves replica counts to KEDA's HPA, and `/data` on `dfe-ingest-bearer-tokens` and `dfe-alert-destinations` to dfe-engine, which writes into them. The names are `common.yaml`'s `ingestBearer.secretName` and `alertDestinations.secretName`, held equal by `test_ingest_bearer_secret.py`.

## Layer 2 app parameters

The chart pulls under the registry annotation `global.registry` reads, so a mirrored deployment moves its charts with its images. A missing annotation fails the render, because an empty parameter beats every values file and would send each image to Docker Hub.

- `gitops.repoUrl` and `gitops.branch` come from the annotations Argo reads, so the engine's write target can't drift from them.
- `env` comes from the cluster annotation. At the chart's `local` default every deployment would report as dev, which the engine's commit policy and default-admin-password check gate on (#233).
- `publicService.loadBalancerIP` is the ingest door's address. Only dfe-receiver's contract marks a port public.
- `clickhouse.tls.internalCA.present` says whether `dfe-internal-ca` exists, from the edge label. `layer2-data.yaml` passes it too, so every client dials the scheme the server serves.

## Layer 2 data

`layer2-data.yaml` deploys ClickHouse, Kafka and the DocumentDB store at wave 4, and the OTel collector, Kafbat and the links page at wave 6. The collector needs the otel tables dfe-engine creates at wave 5. HyperDX is an app, deployed by `layer2-apps.yaml`.

Each Application has two sources: the base chart, then the deploy repo as ref `values`, layered last. A deployer's `clickhouse.mode`, `kafka.mode` and storage model therefore beat the tier defaults without editing dfe-infra. The exception is a cluster secret naming a ClickHouse bucket: the inline values then lock the bucket, its region and the resolver's storage model and cache placement. On a bundled deploy these report `ComparisonError` until `layer2-deploy-repo.yaml`'s Forgejo is up.

The resolver's sizing comes from the deploy repo's `sizing/`, under the `infra/` files, so a deployer's or the engine's edit to a sized key wins.

`appNamespace` is the annotation `layer2-apps.yaml` places the apps with, so the two can't disagree. kafka and documentdb project a credential into it. The KEDA `ignoreDifferences` is in [Kafka autoscaling](/v/2.2.2-fix.1/dfe-infra/deployment/kafka/autoscaling.md).

## Scale operators

`layer-scale.yaml` holds three ApplicationSets.

- `dfe-scale-operators` installs Strimzi and the ClickHouse operator on the `scale` profile.
- `dfe-mesh-operators` installs the ClickHouse operator alone on `mesh`, which runs a cluster and no broker. It is separate because moving an element between ApplicationSets orphans the Applications a running scale cluster owns by name.
- `dfe-redpanda-operator` installs where a `scale` cluster also sets `dfe.hyperi.io/kafka-provider: redpanda`. Redpanda is BSL, so it is an explicit opt-in, the choice the kafka chart's `acceptLicense` gate enforces. Strimzi is the Apache-2.0 default.

Slim and single match none: slim has no Kafka and single runs a non-operator broker. All three sync at wave 3, so the CRDs exist before `layer2-data.yaml` at wave 4.

- The ClickHouse operator is the official one, with `clickhouse.com` CRDs. The HyperI private cloud may swap it for an internal cached operator and ClickHouse fork (see [ClickHouse](/v/2.2.2-fix.1/dfe-infra/deployment/clickhouse.md)). The Altinity operator isn't tested with this stack.
- Its namespace is upstream's own and must match `common.yaml` `operatorNamespaces.clickhouse`, which opens the NetworkPolicy the operator needs to probe Keeper and run DDL. The scale and mesh entries carry the same pin and values, and move together.
- The operator's logger is zap development mode, which is debug level. `manager.args` replaces the chart's default flag list, so `--leader-elect` is restated.

## Edge and platform

`layer2-platform.yaml` generates the cluster platform charts at wave 2: network policy, the toolbox pod and, on AWS, the node pools. `layer2-edge.yaml` generates the gateway and the culvert tunnel ([the edge module](/v/2.2.2-fix.1/dfe-infra/deployment/edge.md)).

- The edge gate reads the secret's `dfe.hyperi.io/edge` label, because a cluster selector matches labels only. `Exists` AND `In` excludes a secret written before the module, which `NotIn` would match.
- Until dfe-infra#342, `layer2-platform.yaml` still generates `envoy-gateway-config` for those older secrets and `layer2-apps.yaml` the tunnel. The names are unchanged so Argo adopts the live objects. Nothing sets `preserveResourcesOnDeletion`, so a rename would take the Gateway, routes and certificates with it.
- The gateway syncs at wave 2 so the routes exist before their workloads, and reports `SyncFailed` until the envoy-gateway operator lands.
- The node pools chart syncs at wave 3, after the Karpenter controller, because a NodePool applied before it sits unclaimed.
- `network-policies` reads `dfeNamespaces`, not `appNamespace`. A NetworkPolicy aimed at an absent namespace is rejected, which fails the whole sync and leaves the cluster with no policies.
- `app` is the Application name and `chart` only its directory, so a chart can move without a rename. The lookup uses `index`, because `missingkey=error` fails a field lookup on an element with no chart.
- The tunnel's `culvert` namespace is labelled `privileged`: the pod holds `NET_ADMIN`, a hostPath tun device and a privileged init container, none of which `baseline` admits.
- `values` is a string because the template is parsed as YAML before Go templating, so a conditional can't live in a structured field.
