Repository navigation
fix(e2e): resolve bestpractice-install failures after Kyverno 3.8.1 migration - #9041
Conversation
|
/test pull-cert-manager-master-e2e-v1-36-bestpractice-install |
|
Triggered The retry does close the webhook race:
That's the only policy denial in the whole run (grepped the full log — 110 denial events, all The cause looks like a scope change introduced by this PR rather than an equivalent CEL rewrite. Before this PR, resourceRules:
- apiGroups: [""]
apiVersions: [v1]
operations: [CREATE, UPDATE]
resources: [serviceaccounts]
validations:
- expression: object.?automountServiceAccountToken.orValue(true) == false
message: ServiceAccounts must set automountServiceAccountToken to false.That's a different resource kind and field than the original policy enforced, and it now denies creation of any A few ways to resolve this, in case it affects how you'd like to proceed with the underlying policy migration:
I've held off picking one of these myself since it affects the policy-migration PR rather than the retry fix in this PR — happy to implement whichever direction you'd prefer, or split it into a follow-up PR against #8886's changes. cc @hjoshi123 as the author of the original migration (#8886), in case there's context on whether the ServiceAccount-level enforcement was intentional. Update (2026-07-22): implemented option 3 above (comply with the ServiceAccount-scoped policy in cert-manager's own e2e helpers) and pushed it as a second commit folded into this PR, rather than waiting further or splitting into a follow-up. Rationale: grepping No rush on your input if you still have thoughts on the policy-migration side, @hjoshi123 — this doesn't change anything about #8886 itself, just brings cert-manager's e2e scaffolding into line with the policy as migrated. |
|
Following up after five days without further movement — required CI is green ( To be clear about scope: this PR only closes the Kyverno webhook startup race in @maelvls — requesting review/approval as OWNERS approver for Update (2026-07-22): change of plan — both root causes are now fixed in this PR. Rather than merging the race fix alone and leaving the ServiceAccount automount regression (161 specs) for later, I've folded the fix for that into the same commit and force-pushed (see the updated PR description above for both root causes and the full rationale). This PR now resolves the whole |
6846ceb to
b2e4910
Compare
There was a problem hiding this comment.
Pull request overview
This PR hardens the e2e environment setup against a Kyverno admission webhook startup race by retrying the Kyverno policy kubectl apply step, preventing make e2e-setup from failing before any tests run.
Changes:
- Wrap Kyverno policy
kubectl apply --server-sidein a bounded retry loop (10 attempts, 3s backoff). - Capture apply failures to a log file and print the log on final failure.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@wallrj-cyberark apologies for the delayed response.. I prefer option 1 too for the policy.. we can just patch the policy to add pods instead of serviceaccounts and change the expression too.. instead of migrating back to the old one I prefer patching it for our usecase |
|
/test pull-cert-manager-master-e2e-v1-36-bestpractice-install |
|
Oh I guess that works too 😛 |
b2e4910 to
b983528
Compare
|
Thanks for weighing in, no worries on the timing — appreciate it. I'd actually already gone with option 3 (comply in the e2e test helpers) just before your message landed, so let me explain the reasoning and you can tell me if you still feel strongly about patching the policy instead: Grepping That said, your patch-to-pods approach is a legitimate call too and would keep the original pre-migration semantics intact rather than adopting kyverno's newer ServiceAccount-scoped check — if you'd prefer that direction for the migrated bundle regardless of this PR, I'm happy to help or defer to whatever you land on for #8886. For unblocking this specific CI failure though, I'd like to go with what's already implemented and passing, if that's alright with you — keen to get |
|
/test pull-cert-manager-master-e2e-v1-36-bestpractice-install |
|
Yup @wallrj-cyberark since you have already made the change I don't want that to be reverted.. I do agree option 3 is cleaner.. the reason I was aiming for option 1 is its much simpler to do but since you have already started the changes we should continue with that.. I like the direction of the PR and as long as the tests pass I am happy to merge it |
b983528 to
71b4b6e
Compare
|
The last run (428 passed, 51 failed — down from 161) confirmed the ServiceAccount automount fix worked: zero Kyverno policy denials anywhere in the log. The remaining 51 failures (all ACME HTTP01) were a third, unrelated cause:
Correction: that reasoning was wrong — Kyverno's For context: this exact hazard is long-established prior art in Kubernetes' own e2e framework — |
|
/test pull-cert-manager-master-e2e-v1-36-bestpractice-install |
|
/retest |
…igration ci-cert-manager-master-e2e-v1-36-bestpractice-install has failed every periodic run since 2026-07-09, immediately after the Kyverno ClusterPolicy to ValidatingPolicy migration in cert-manager#8886 bumped the chart to 3.8.1. Two distinct problems, fixed below. 1. Webhook startup race: Kyverno registers its own admission webhooks from inside the running pod, after `helm upgrade --wait` already considers the Deployment ready. The very next step, `kubectl apply` of policy.yaml, lands in that startup window and fails with a webhook connection-refused error, aborting e2e-setup-kyverno before a single test runs: Error from server (InternalError): Internal error occurred: failed calling webhook "validate-policy.kyverno.svc": failed to call webhook: Post "https://kyverno-svc.kyverno.svc:443/policyvalidate ?timeout=10s": dial tcp 10.0.255.124:443: connect: connection refused Fixed by retrying the apply with a short backoff, mirroring the retry already used for tool downloads via curl's --retry-connrefused in make/_shared/tools/00_mod.mk. The retry loop also captures combined stdout+stderr and prints it on every failed attempt rather than only the last, so the real error is visible immediately instead of after the full retry budget. 2. ServiceAccount-targeting policy is a different policy, not a CEL rewrite of the original: fixing (1) let the suite actually run, surfacing that cert-manager#8886 also changed the effective automount policy from validating Pods (spec.automountServiceAccountToken) to validating ServiceAccounts themselves (object.automountServiceAccountToken). This is because the pre-migration policy, other/restrict-automount-sa-token, has no like-for-like CEL/ValidatingPolicy equivalent upstream - the only automount-related entry in kyverno's other-vpol catalog is restrict-sa-automount-sa-token, a differently-scoped policy that happens to have a similar name. Enforcing that policy as published denies Kubernetes' own creation of the "default" ServiceAccount for every namespace, since nothing sets automountServiceAccountToken on it. kube-controller-manager's serviceaccounts_controller retries forever and is denied every time (confirmed via its own logs: 4576 denials across 852 e2e namespaces in one run), so this is a permanent failure, not a race - any Pod anywhere that doesn't specify a custom ServiceAccount is unable to run. It reached 161 failing e2e specs here (RBAC-boundary, ACME HTTP01, Vault issuer suites - i.e. every suite that creates a Pod or ServiceAccount without setting the field), traced via 110 direct denial events in the apply log plus the default-ServiceAccount denials above: error creating ServiceAccount for Kubernetes auth: admission webhook "vpol.validate.kyverno.svc-fail" denied the request: Policy restrict-sa-automount-sa-token failed: ServiceAccounts must set automountServiceAccountToken to false. Fixed by patching the migrated ValidatingPolicy in kustomization.yaml to restore the original Pod-targeting semantics (resourceRules on pods, CEL expression on spec.automountServiceAccountToken) instead of the ServiceAccount-targeting resource kyverno currently publishes. This matches the policy already in effect on 2026-07-08 before the migration, under which the entire e2e suite already passed cleanly (479/479, 0 failures) - cert-manager's own ACME HTTP01 solver pod already sets automountServiceAccountToken: false (pkg/issuer/acme/http/pod.go), so no further e2e or product code changes are needed. Also fixes a related, unrelated-looking symptom this surfaced: CreateKubeNamespace in the e2e framework created the test Namespace and returned immediately, without waiting for its "default" ServiceAccount to be provisioned - a latent race any Pod created immediately afterwards (e.g. an ACME HTTP01 solver pod) could hit. Kept as defence in depth, mirroring the equivalent, long-standing wait in Kubernetes' own e2e framework (WaitForDefaultServiceAccountInNamespace, called from CreateTestingNS), even though it no longer fires in practice once the ServiceAccount-targeting denial above is fixed. Fixes: https://testgrid.k8s.io/cert-manager-periodics-master#ci-cert-manager-master-e2e-v1-36-bestpractice-install Signed-off-by: Richard Wall <[email protected]>
1ac2eb4 to
8562d2a
Compare
|
@hjoshi123 — update: the "default SA not found" failures from the earlier run turned out to be a much bigger issue than a timing race, and it vindicates your option 1. Checked Since the controller resends the same request every retry, this is permanent, not transient — no wait/retry logic in our e2e code can fix it. Any Pod anywhere that doesn't specify a custom ServiceAccount is unable to run under this policy, cluster-wide, not just in cert-manager's tests. Also traced why: the pre-migration policy ( Implemented your suggested approach: patched the migrated |
|
/test pull-cert-manager-master-e2e-v1-36-bestpractice-install |
1 similar comment
|
/test pull-cert-manager-master-e2e-v1-36-bestpractice-install |
Signed-off-by: Hemant Joshi <[email protected]>
|
@wallrj-cyberark based on the comments regarding description and other metadata on the policy, I added some changes and pushed it back.. the PR largely looks similar and LGTM.. I am adding my LGTM but holding it for your final decision. Feel free to add an approve and remove the hold in the morning when you see this :).. Thank you for working on this :) |
|
/label tide/merge-method-squash |
|
/lgtm |
|
/test pull-cert-manager-master-e2e-v1-36-bestpractice-install |
|
/unhold |
|
/approve |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: wallrj The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
ci-cert-manager-release-1.21-e2e-v1-36-bestpractice-install has failed every periodic run since 2026-09-04. The kyverno admission webhook registers itself from inside the running pod, after `helm upgrade --wait` has already returned. The next step, applying policy.yaml, lands in that window and fails: Error from server (InternalError): Internal error occurred: failed calling webhook "mutate-policy.kyverno.svc": failed to call webhook: Post "https://kyverno-svc.kyverno.svc:443/policymutate?timeout=10s": dial tcp 10.0.17.91:443: connect: connection refused Retry the apply with a short backoff, as master already does since #9041. Only that hunk is backported. The rest of #9041 belongs to the Kyverno 3.8.1 / ValidatingPolicy migration, which this branch never took, and it conflicts on cherry-pick. Signed-off-by: Richard Wall <[email protected]> Co-Authored-By: Claude Fable 5 <[email protected]>
ci-cert-manager-release-1.20-e2e-v1-35-bestpractice-install has failed on 3 of its last 10 periodic runs. The kyverno admission webhook registers itself from inside the running pod, after `helm upgrade --wait` has already returned. The next step, applying policy.yaml, lands in that window and fails: Error from server (InternalError): Internal error occurred: failed calling webhook "mutate-policy.kyverno.svc": failed to call webhook: Post "https://kyverno-svc.kyverno.svc:443/policymutate?timeout=10s": dial tcp 10.0.17.91:443: connect: connection refused Retry the apply with a short backoff, as master already does since #9041. Only that hunk is backported. The rest of #9041 belongs to the Kyverno 3.8.1 / ValidatingPolicy migration, which this branch never took, and it conflicts on cherry-pick. Signed-off-by: Richard Wall <[email protected]> Co-Authored-By: Claude Fable 5 <[email protected]>
Pull Request Motivation
ci-cert-manager-master-e2e-v1-36-bestpractice-installhas failed on every periodic run since 2026-07-09: https://testgrid.k8s.io/cert-manager-periodics-master#ci-cert-manager-master-e2e-v1-36-bestpractice-install (last green run was 83e2659 on 2026-07-07).Bisecting
git log 83e2659e8..mastershows the very first commit after the last green run is #8886, which bumped the Kyverno Helm chart to 3.8.1 and replaced the legacyClusterPolicyresources inmake/config/kyverno/policy.yamlwith the new CEL-basedValidatingPolicyresources. That migration surfaced two distinct problems, fixed below.1. Webhook startup race
The build log for the earliest failing run shows the failure happens during
make e2e-setup, before any test runs:Kyverno's admission-controller registers/updates its own webhook configuration from inside the running process, after the pod has already passed its readiness probe.
helm upgrade --install --waitonly waits for the Deployment to becomeAvailable, so applyingpolicy.yamlimmediately afterwards can land in that startup window.Fixed with a bounded retry loop (10 attempts, 3s backoff) around the
kubectl apply, mirroring the retry idiom already used for tool downloads viacurl --retry-connrefusedinmake/_shared/tools/00_mod.mk. The loop captures combined stdout+stderr and prints it on every failed attempt, not just the last.Verification (2026-07-17): confirmed the retry closes the race —
e2e-setup-kyvernonow succeeds and the suite runs 479 of 994 specs, versus dying before a single test ran onmaster.2. The migrated policy isn't a CEL rewrite of the original — it's a different policy
Fixing (1) let the suite actually run, which surfaced that #8886 also changed the effective automount policy semantics. The pre-migration policy was
other/restrict-automount-sa-token, which validates Pods (spec.automountServiceAccountToken). Kyverno's CEL/ValidatingPolicycatalog has no like-for-like replacement for it: the only automount-related entry underother-vpolisrestrict-sa-automount-sa-token, a different, similarly-named policy that validates ServiceAccounts themselves (object.automountServiceAccountToken).Enforcing that policy as published is not just an e2e-test problem — it denies Kubernetes' own creation of the
defaultServiceAccount for every namespace in the cluster, since nothing ever setsautomountServiceAccountTokenon it. Confirmed directly fromkube-controller-manager's own log (itsserviceaccounts_controller, which is what creates every namespace'sdefaultSA):4,576 denials across 852 distinct e2e namespaces in one run — every single one the suite created. Since the controller resends the identical request on every retry, this is a permanent denial, not a transient race: no amount of waiting fixes it. Any Pod anywhere that doesn't specify a custom ServiceAccount (the overwhelming majority of real-world workloads) is unable to run at all under this policy. It reached 161 failing e2e specs here — every RBAC-boundary, ACME HTTP01, and Vault issuer suite, i.e. every suite that creates a Pod or ServiceAccount without explicitly setting the field.
I checked kyverno's own chainsaw test suite for this policy — it only applies hand-crafted
good-sa.yaml/bad-sa.yamlfixtures directly, and never exercises the Namespace-creation path that triggers this. This looks like a genuine, previously unnoticed gap in the upstream policy as published, not a cert-manager misconfiguration; I'll file an issue againstkyverno/policiesseparately.Fix: patch the migrated
ValidatingPolicyinkustomization.yamlto restore the original Pod-targeting semantics (resourceRulesonpods, CEL expression onspec.automountServiceAccountToken) instead of the ServiceAccount-targeting resource kyverno currently publishes under a similar name. This matches the policy already in effect on 2026-07-08, before the migration, under which the entire suite already passed cleanly (479/479, 0 failures) — cert-manager's own ACME HTTP01 solver pod already setsautomountServiceAccountToken: false(pkg/issuer/acme/http/pod.go), so no other e2e or product code changes are needed for this.This also incidentally surfaced a small, genuinely separate latent race in the e2e framework:
CreateKubeNamespacecreates the testNamespaceand returns immediately without waiting for itsdefaultServiceAccount to be provisioned, which any Pod created immediately afterwards could hit. I've kept the fix for that (waiting for thedefaultServiceAccount, mirroring Kubernetes' ownWaitForDefaultServiceAccountInNamespace/CreateTestingNS) as defence in depth, even though it no longer fires in practice once the denial above is fixed.Test plan
I can't reproduce this locally (no
docker/kindin my environment), so I'm relying on CI. Verified incrementally by re-triggering/test pull-cert-manager-master-e2e-v1-36-bestpractice-installafter each push and reading the failure log — 161 failures traced to the ServiceAccount-targeting policy denial, now fixed by restoring Pod-targeting semantics. Will report the final result here.Kind
/kind flake