Skip to content

Fix flake caused by invalid detection of active policies in VAP integration tests #132502

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

benluddy
Copy link
Contributor

@benluddy benluddy commented Jun 24, 2025

What type of PR is this?

/kind flake
/sig api-machinery

What this PR does / why we need it:

Writes to policy resources don't instantaneously take effect in admission. ValidatingAdmissionPolicy
integration tests determine that the policies under test have taken effect by adding a sentinel
policy rule and polling until that rule is applied to a request.

If the marker resource names are the same for each test case in a series of test cases, then
observing a policy's effect on a marker request only indicates that any test policy is in effect,
but it's not necessarily the policy the current test case is waiting for. For example:

  1. Test 1 creates a policy and binding.

  2. The policy and binding are observed by the admission plugin and take effect.

  3. Test 1 observes that a policy is in effect via marker requests.

  4. Test 1 exercises the behavior under test and successfully deletes the policy and binding it
    created.

  5. Test 2 creates a policy and binding.

  6. Test 2 observes that a policy is in effect via marker requests, but the policy in effect is still
    the one created by Test 1.

  7. Test 2 exercises the behavior under test, which fails because it was evaluated against Test 1's
    policy.

Generating a per-policy name for the marker resource in each test resolves the timing issue. In the
example, step (6) will not proceed until the admission plugin has observed the policy and binding
created in (5).

Which issue(s) this PR is related to:

N/A

Special notes for your reviewer:

@bertinatto first reported this in https://kubernetes.slack.com/archives/C02TTBG6LF4/p1746818599391839 after seeing this flake in OpenShift CI.

Does this PR introduce a user-facing change?

NONE

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


@k8s-ci-robot
Copy link
Contributor

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

@k8s-ci-robot k8s-ci-robot added size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. kind/flake Categorizes issue or PR as related to a flaky test. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Jun 24, 2025
@k8s-ci-robot k8s-ci-robot requested review from SataQiu and thockin June 24, 2025 14:20
@k8s-ci-robot k8s-ci-robot added area/test sig/testing Categorizes an issue or PR as relevant to SIG Testing. labels Jun 24, 2025
@benluddy
Copy link
Contributor Author

/test pull-kubernetes-integration

@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Jun 24, 2025
@benluddy
Copy link
Contributor Author

Increasing the policy refresh interval is enough to consistently reproduce this failure. Because the "test-marker" check is identical across test cases, it can proceed even when the policy from the previous test case is still in effect. Generating a random marker name for each test policy seems to resolve it, even with a very wide policy refresh interval.

/test pull-kubernetes-integration

Writes to policy resources don't instantaneously take effect in admission. ValidatingAdmissionPolicy
integration tests determine that the policies under test have taken effect by adding a sentinel
policy rule and polling until that rule is applied to a request.

If the marker resource names are the same for each test case in a series of test cases, then
observing a policy's effect on a marker request only indicates that _any_ test policy is in effect,
but it's not necessarily the policy the current test case is waiting for. For example:

1. Test 1 creates a policy and binding.

2. The policy and binding are observed by the admission plugin and take effect.

3. Test 1 observes that a policy is in effect via marker requests.

4. Test 1 exercises the behavior under test and successfully deletes the policy and binding it
created.

5. Test 2 creates a policy and binding.

6. Test 2 observes that a policy is in effect via marker requests, but the policy in effect is still
the one created by Test 1.

7. Test 2 exercises the behavior under test, which fails because it was evaluated against Test 1's
policy.

Generating a per-policy name for the marker resource in each test resolves the timing issue. In the
example, step (6) will not proceed until the admission plugin has observed the policy and binding
created in (5).
@benluddy benluddy force-pushed the validatingadmissionpolicy-integration-marker-flake branch from 8dae9ea to 190c8c7 Compare June 25, 2025 15:43
@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. and removed do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Jun 25, 2025
@benluddy benluddy changed the title wip: demonstrate flake in vap integration tests Fix flake caused by invalid detection of active policies in VAP integration tests Jun 25, 2025
@benluddy benluddy marked this pull request as ready for review June 25, 2025 15:49
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jun 25, 2025
@benluddy
Copy link
Contributor Author

/cc @jpbetz

@k8s-ci-robot k8s-ci-robot requested a review from jpbetz June 25, 2025 15:51
@benluddy
Copy link
Contributor Author

The PR job history includes a run where I had changed nothing except increased policyRefreshInterval from 10ms to 10s: https://prow.k8s.io/view/gs/kubernetes-ci-logs/pr-logs/pull/132502/pull-kubernetes-integration/1937516402059513856. Then with generated marker names (but still 10s refresh interval): https://prow.k8s.io/view/gs/kubernetes-ci-logs/pr-logs/pull/132502/pull-kubernetes-integration/1937561265681469440.

@k8s-ci-robot
Copy link
Contributor

@benluddy: 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
pull-kubernetes-linter-hints 190c8c7 link false /test pull-kubernetes-linter-hints

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

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.

@liggitt
Copy link
Member

liggitt commented Jun 25, 2025

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 25, 2025
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: 57efaf9f65dafdccca53e39771c5e7d288ceda4f

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: benluddy, liggitt

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

The pull request process is described here

Needs approval from an approver in each of these files:

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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 25, 2025
@benluddy
Copy link
Contributor Author

/triage accepted

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Jun 25, 2025
@k8s-ci-robot k8s-ci-robot merged commit befc91a into kubernetes:master Jun 25, 2025
12 of 13 checks passed
@k8s-ci-robot k8s-ci-robot added this to the v1.34 milestone Jun 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/test cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/flake Categorizes issue or PR as related to a flaky test. lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. release-note-none Denotes a PR that doesn't merit a release note. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/testing Categorizes an issue or PR as relevant to SIG Testing. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants