fix(e2e): stop the PSA sidecar guard passing when otel-collector is absent - #452
Open
AshrafAhmed9 wants to merge 1 commit into
Open
fix(e2e): stop the PSA sidecar guard passing when otel-collector is absent#452AshrafAhmed9 wants to merge 1 commit into
AshrafAhmed9 wants to merge 1 commit into
Conversation
AshrafAhmed9
requested review from
WentingWu666666,
alaye-ms,
hossain-rayhan and
xgerman
as code owners
August 30, 2026 17:52
2 tasks
…bsent documentdb-gateway is injected unconditionally, so the matched == 0 guard in AssertInjectedSidecarsPSARestricted is always satisfied and a monitoring-on cluster whose otel-collector failed to inject still reports its pods as hardened. Add an optional requireSidecars parameter naming sidecars that must be present on every instance pod. Presence is scoped by cnpg.io/podRole=instance so CNPG's bootstrap and join Job pods, which also carry cnpg.io/cluster, are not mistaken for instances that lost a sidecar. Requiring a sidecar when no instance pod matches is an error, so a change to CNPG's labels cannot silently reinstate the vacuous pass. Call it with otel-collector from the monitoring-on spec in tests/resources, which already deploys the suite's only monitoring-on cluster in a PSA-restricted namespace, so this adds no cluster deploy to CI. Adds unit tests for the helper; it was the only assertion in the package without any. Refs documentdb#412, documentdb#387 Signed-off-by: Ashrafahmed9 <ashrafahmed1232@gmail.com>
AshrafAhmed9
force-pushed
the
developer/e2e-otel-psa-assertion
branch
from
August 30, 2026 17:53
ba19916 to
0e7e2c6
Compare
|
🤖 Auto-triaged by documentdb-triage-tool. Applied: Reasoningcomponent from path globs (test); effort from diff stats (262+7 LOC, 4 files); LLM: Fixes a false-passing PSA sidecar assertion in e2e tests that masked missing otel-collector injection, with unit tests and scoped instance-pod filtering added. If a label is wrong, remove it manually and ping |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
AssertInjectedSidecarsPSARestrictedcan't fail when the otel-collector is missing.documentdb-gatewayis injected unconditionally, somatched == 0never trips, and a monitoring-on cluster whose collector never injected still comes back hardened.That's the gap behind #412. While chasing it I think most of the monitoring-on coverage the issue asks for already landed in #409:
tests/resources/sidecar_resources_test.godeploys a cluster withmonitoring.enabled: trueand waits for healthy, andfixtures.CreateLabeledNamespaceapplies the restricted PSA labels. The assertion is the part that's missing. All three callers of the helper deploy monitoring-off, so nothing ever checks the collector'ssecurityContext.Changes
requireSidecars ...stringnames sidecars that must be present on every instance pod. Variadic, so the existing monitoring-off callers are untouched.cnpg.io/podRole=instance. CNPG putscnpg.io/clusteron bootstrap and join Job pods too and the injector skips those, so without the scope a leftover initdb pod looks like an instance that lost its collector.tests/resourcesnow passesotel-collector. It already deploys the suite's only monitoring-on cluster, so CI doesn't gain one.On the observability area
#412 suggests a new area for this. I used the existing monitoring-on cluster instead, since a second area buys another cluster deploy for the same signal. The scrape check listed as a follow-on there would justify its own area, but that needs a real exporter round-trip and reads better as a separate PR. Happy to move this if you'd rather areas stay single-purpose.
Testing
go vet ./...andgofmtclean,go test ./pkg/...green,tests/{resources,lifecycle,backup}all compile.Dropping the required-sidecar check reproduces the vacuous pass. Dropping the instance-pod scope reproduces the Job-pod false positive:
Both pass with the change.
I haven't run the e2e suite itself, since I don't have a kind cluster with the operator on it. The spec change is one
Eventuallyagainst an existing fixture and the helper is unit-tested, but the end-to-end path wants a CI run.Out of scope
gofmtdrift under Go 1.26 in ~39 files intest/e2ethat I didn't touch.