E2E Metrics Test
Every resource gets a second e2e test next to its reconcile test:
test/e2e/e2e_metrics_<version>_<kind>_test.go. It checks that the resource’s
metrics are actually reachable through the metrics Service, which is what
Prometheus scrapes — not through the Pod.
What it checks
Creates the resource and waits for
Status.IsReady().Scrapes
/metricsthrough the API server’s service proxy:kubectl get --raw /api/v1/namespaces/<operator-namespace>/services/<project>-<controller>-metrics:metrics/proxy/metricsThe proxy resolves the Service to its endpoints, so the test fails if the Service selector, the
metricsport name or the endpoints are wrong.Asserts the two gauges every resource records, for this resource’s
name:Metric Expected <group>_<kind>_ready1<group>_<kind>_phasepresent <group>is the API group with dots replaced by underscores, and both parts are lowercased —infrastructure.acme.io/VPCgivesinfrastructure_acme_io_vpc_ready.
The gauges are recorded by the leader after the reconcile, so the assertions are retried for up to two minutes.
The gauges only exist while the resource’s metrics switch is on. The test reads
<PLURAL>_METRICS_ENABLED from the <project>-operator-controller-default-env
ConfigMap and, when it is false (metrics: false in .genop.yaml), only
checks that the Service is reachable. The generated Go code does not depend on
the topology, so flipping the switch never rewrites the file.
Adding your own checks
The file is generated once and never overwritten — genop apply skips it
when it exists, so it is yours to edit. Custom metrics registered in the
resource’s metrics.go (see Metrics) are
asserted at the // Add your custom metric checks here marker, against the
scraped out:
g.Expect(out).To(ContainSubstring("infrastructure_acme_io_vpc_my_metric"))Deleting the kind (genop apply --prune) removes this file together with the
rest of the resource’s e2e test.
Limits
- The test targets the defaults: plain HTTP metrics (
METRICS_SECURE=false) and one replica. With secure metrics on, the proxy path needs anhttps:prefix and RBAC on the caller. - The Service is looked up by its two conventional names,
<project>-<controller>-metrics(kustomize) and<project>-operator-<controller>-controller-metrics(Helm, default release name). A chart installed under another release name orfullnameOverrideneeds themetricsServiceslist adjusted. - The switch is read from the default ConfigMap: a value overridden in your own
<project>-operator-controller-envConfigMap is not seen.