Skip to content

fix: allow mutation-webhook only operation without constraint client …#4469

Open
adiazny wants to merge 1 commit into
open-policy-agent:release-3.21from
adiazny:backport-fix-PR4423-release-3.21
Open

fix: allow mutation-webhook only operation without constraint client …#4469
adiazny wants to merge 1 commit into
open-policy-agent:release-3.21from
adiazny:backport-fix-PR4423-release-3.21

Conversation

@adiazny

@adiazny adiazny commented Mar 25, 2026

Copy link
Copy Markdown
Contributor

What this PR does / why we need it: cherry-pick #4423 fix: allow mutation-webhook only operation without constraint client for release-3.21

Which issue(s) this PR fixes:
Fixes #3928

@adiazny adiazny requested a review from a team as a code owner March 25, 2026 15:21
Copilot AI review requested due to automatic review settings March 25, 2026 15:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR cherry-picks the upstream fix to let Gatekeeper run with --operation=mutation-webhook only by avoiding unnecessary constraint/OPA client initialization and making the cache manager tolerant of having no constraint client.

Changes:

  • Only initialize the constraint/OPA client in main.go when validation operations are enabled.
  • Default CacheManager’s CfClient to a no-op implementation when none is provided.
  • Extend cache manager tests to cover behavior with a no-op CfClient and adjust assertions accordingly.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
main.go Skips constraint client creation when validation operations aren’t enabled; passes no client to cache manager in mutation-only mode.
pkg/cachemanager/cachemanager.go Introduces noopCFDataClient and defaults CfClient to it when unset.
pkg/cachemanager/cachemanager_test.go Adds tests for no-op client cases and makes assertions conditional on fake client presence.

Comment on lines +108 to +111
cfClient := config.CfClient
if cfClient == nil {
cfClient = &noopCFDataClient{}
}

Copilot AI Mar 25, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

config.CfClient is an interface, so a typed-nil (e.g. (*constraintclient.Client)(nil) assigned to CFDataClient) will make cfClient != nil here, and the no-op fallback won’t apply. That can still lead to panics later when c.cfClient.AddData/RemoveData is invoked. Consider normalizing the interface value (e.g., via reflect.ValueOf(cfClient).IsNil() for nilable kinds, or a small helper) before deciding whether to use noopCFDataClient.

Copilot uses AI. Check for mistakes.
…pen-policy-agent#4423)

Signed-off-by: Alan Diaz <alan.diaz@jpmchase.com>
(cherry picked from commit 70d79e4)
Signed-off-by: Alan Diaz <alan.diaz@jpmchase.com>
@adiazny adiazny force-pushed the backport-fix-PR4423-release-3.21 branch from 5c437e5 to 33dcbec Compare March 25, 2026 15:28
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.00000% with 2 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (release-3.21@ee60035). Learn more about missing BASE report.

Files with missing lines Patch % Lines
pkg/cachemanager/cachemanager.go 75.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@               Coverage Diff               @@
##             release-3.21    #4469   +/-   ##
===============================================
  Coverage                ?   40.71%           
===============================================
  Files                   ?      251           
  Lines                   ?    17734           
  Branches                ?        0           
===============================================
  Hits                    ?     7220           
  Misses                  ?     9889           
  Partials                ?      625           
Flag Coverage Δ
unittests 40.71% <75.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ogulcanaydogan ogulcanaydogan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean cherry-pick. The key change is guarding the constraint client initialization behind HasValidationOperations(), so mutation-only deployments don't need it.

Wrapping the rego driver and K8s CEL setup in the validation check makes sense since those are only needed for constraint evaluation.

LGTM

@github-actions

Copy link
Copy Markdown
Contributor

This PR has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.

@github-actions github-actions Bot added the stale label Jun 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants