fix(e2e): stop the PSA sidecar guard passing when otel-collector is absent - #452
fix(e2e): stop the PSA sidecar guard passing when otel-collector is absent#452AshrafAhmed9 wants to merge 2 commits into
Conversation
…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>
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 |
|
@AshrafAhmed9 Nice catch on the vacuous pass! One idea: I think the presence check should be its own helper, not a variadic on Also, the variadic is optional. Two of the three callers pass nothing, so they skip the presence check without any warning. It is easy to forget on the next caller too. So maybe: keep this function as it was on main (PSA only), add a new |
AssertInjectedSidecarsPSARestricted cannot fail when the otel-collector is missing. documentdb-gateway is injected unconditionally, so the matched == 0 guard is always satisfied and a monitoring-on cluster whose collector never injected still reports its pods as hardened. Split the two questions rather than widening that checker. Presence and hardening fail for different reasons: a missing collector is a plumbing problem, a bad securityContext is the documentdb#387 problem, and one error should not have to be read to work out which happened. AssertInjectedSidecarsPSARestricted is left exactly as it was on main. AssertSidecarsInjected takes the sidecars a caller expects and requires them on every instance pod. Presence is scoped by cnpg.io/podRole=instance, since CNPG stamps cnpg.io/cluster on its bootstrap and join Job pods too and the injector never touches those. Naming no sidecars, or naming something that is not an injected sidecar, is a spec bug and fails immediately instead of spinning until the Eventually timeout. The monitoring-on spec in tests/resources now runs both. It already deploys the suite's only monitoring-on cluster, so this adds no cluster deploy to CI. Adds unit tests for both helpers; the PSA one had none, and it was the only assertion in the package without any.
|
You're right that the optional variadic was the weak part, and two callers were already demonstrating it. A check that silently does nothing when you forget an argument isn't much of a check. Done in 835a9f8.
The monitoring-on spec runs both, and the failure messages now say which thing broke: The new helper only counts pods labelled Both helpers now have unit tests; the PSA one had none before. On it being easy to forget on the next caller: splitting doesn't fully solve that, since a new spec can just as easily not call |
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
Presence and hardening are separate checks, because they fail for different reasons: a missing collector is a plumbing problem, a bad
securityContextis the #387 problem, and one error shouldn't have to be read to work out which happened.AssertInjectedSidecarsPSARestrictedis unchanged from main, byte for byte.AssertSidecarsInjected(ctx, c, ns, cluster, names...)requires the named sidecars on every instance pod. Naming none is an error rather than a pass, so it can't be called into a no-op.cnpg.io/podRole=instance. CNPG stampscnpg.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/resourcesruns both. 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. Full CI is green, including the E2E matrix on amd64 and arm64.Dropping the instance-pod scope reproduces the Job-pod false positive:
The tests also pin the case that motivated the split: on a gateway-only cluster the PSA checker passes, as it should, while
AssertSidecarsInjectedwithotel-collectorfails.Out of scope
AssertSidecarsInjected; the fix for that belongs in the shared cluster fixture, not in either assertion.gofmtdrift under Go 1.26 in ~39 files intest/e2ethat I didn't touch.