Skip to content

CMP-4601: metrics: wait for the serving cert before serving TLS - #1350

Open
Vincent056 wants to merge 1 commit into
ComplianceAsCode:masterfrom
Vincent056:cmp-4601-metrics-cert-wait
Open

CMP-4601: metrics: wait for the serving cert before serving TLS#1350
Vincent056 wants to merge 1 commit into
ComplianceAsCode:masterfrom
Vincent056:cmp-4601-metrics-cert-wait

Conversation

@Vincent056

@Vincent056 Vincent056 commented Aug 18, 2026

Copy link
Copy Markdown

Status: under test — please hold review of correctness claims until validation completes. We are actively validating this against live clusters and e2e (tracking in CMP-4601); I'll drop the draft state and comment here once we have a validated run.

Problem

Metrics.Start calls ListenAndServeTLS exactly once and deliberately swallows the error (a metrics failure must never take down the operator). The serving cert is minted asynchronously by the service-ca operator after the metrics Service is created — so on a fresh deployment the operator can start before the secret volume is populated. Losing that race leaves metrics.<ns>.svc:8585/metrics-co connection-refused for the life of the pod: no retry, no restart (liveness only checks healthz), no self-heal.

Caught live in #1255's e2e-aws-parallel run: operator logged Metrics service failed: open /var/run/secrets/serving-cert/tls.crt: no such file or directory at pod start, and TestResultServerHTTPVersion, TestServiceMonitoringMetricsTarget, TestSingleScanSucceeds all failed with curl exit 7 against :8585 while Prometheus scraped :8383 fine.

Fix

Wait (bounded 5 min, 5 s poll, context-aware) for the cert and key files to exist before starting the TLS listener. On final failure the behavior is unchanged: log and keep the operator alive. Unit-tested (late-minted cert recovery, timeout, context cancellation); package coverage 60.7 → 62.2 (baseline updated).

Out of scope, noted in CMP-4601

  • Whether a permanently-missing cert should fail the pod instead (kubelet restart = self-heal)
  • Cert rotation (the cert is loaded once; a service-ca rotation today likely needs a pod restart — GetCertificate-based reload would fix that)
  • e2e metrics helpers tolerating a not-yet-ready endpoint

🤖 Generated with Claude Code

The HTTPS metrics server calls ListenAndServeTLS once and deliberately
swallows the error so a metrics failure never takes down the operator.
But the serving cert is minted asynchronously by the service-ca operator
after the metrics Service is created, so on a fresh deployment the
operator can start before the secret volume is populated - and when it
loses that race the :8585 endpoint stays connection-refused for the
life of the pod, with nothing to self-heal (no retry, no restart).

Seen in the wild in the e2e-aws-parallel run for ComplianceAsCode#1255 (2026-08-18):
'Metrics service failed: open /var/run/secrets/serving-cert/tls.crt:
no such file or directory' at pod start, and every metrics assertion
(TestResultServerHTTPVersion, TestServiceMonitoringMetricsTarget,
TestSingleScanSucceeds) failing with curl exit 7.

Wait for the cert and key files to appear (bounded, context-aware)
before starting the TLS listener, keeping the existing behavior of
never exiting the operator on metrics failure.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@openshift-ci-robot

openshift-ci-robot commented Aug 18, 2026

Copy link
Copy Markdown
Collaborator

@Vincent056: This pull request references CMP-4601 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the bug to target either version "5.1.0." or "openshift-5.1.0.", but it targets "compliance-operator-1.10.0" instead.

Details

In response to this:

Status: under test — please hold review of correctness claims until validation completes. We are actively validating this against live clusters and e2e (tracking in CMP-4601); I'll drop the draft state and comment here once we have a validated run.

Problem

Metrics.Start calls ListenAndServeTLS exactly once and deliberately swallows the error (a metrics failure must never take down the operator). The serving cert is minted asynchronously by the service-ca operator after the metrics Service is created — so on a fresh deployment the operator can start before the secret volume is populated. Losing that race leaves metrics.<ns>.svc:8585/metrics-co connection-refused for the life of the pod: no retry, no restart (liveness only checks healthz), no self-heal.

Caught live in #1255's e2e-aws-parallel run: operator logged Metrics service failed: open /var/run/secrets/serving-cert/tls.crt: no such file or directory at pod start, and TestResultServerHTTPVersion, TestServiceMonitoringMetricsTarget, TestSingleScanSucceeds all failed with curl exit 7 against :8585 while Prometheus scraped :8383 fine.

Fix

Wait (bounded 5 min, 5 s poll, context-aware) for the cert and key files to exist before starting the TLS listener. On final failure the behavior is unchanged: log and keep the operator alive. Unit-tested (late-minted cert recovery, timeout, context cancellation); package coverage 60.7 → 62.2 (baseline updated).

Out of scope, noted in CMP-4601

  • Whether a permanently-missing cert should fail the pod instead (kubelet restart = self-heal)
  • Cert rotation (the cert is loaded once; a service-ca rotation today likely needs a pod restart — GetCertificate-based reload would fix that)
  • e2e metrics helpers tolerating a not-yet-ready endpoint

🤖 Generated with Claude Code

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@openshift-ci

openshift-ci Bot commented Aug 18, 2026

Copy link
Copy Markdown

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@github-actions

Copy link
Copy Markdown

🤖 To deploy this PR, run the following command:

make catalog-deploy CATALOG_IMG=ghcr.io/complianceascode/compliance-operator-catalog:1350-f4afbd4a9a8dec9e9dce90d92e0e1e45605656ff

@Vincent056
Vincent056 marked this pull request as ready for review August 19, 2026 02:44
@taimurhafeez

Copy link
Copy Markdown
Collaborator

/retest-required

@openshift-ci

openshift-ci Bot commented Aug 19, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: taimurhafeez, Vincent056

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:
  • OWNERS [Vincent056,taimurhafeez]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@taimurhafeez

Copy link
Copy Markdown
Collaborator

/lgtm

@taimurhafeez

Copy link
Copy Markdown
Collaborator

Pre-Merge verification passed on 4.22.

@openshift-ci

openshift-ci Bot commented Aug 19, 2026

Copy link
Copy Markdown

@Vincent056: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/e2e-aws-parallel f4afbd4 link true /test e2e-aws-parallel

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@yuumasato

Copy link
Copy Markdown
Member

CI failure on e2e-aws-parallel is the same noticed here: #1365 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants