Skip to content

feat: add default-failure-policy flag to fix #4567#4581

Closed
Mallikarjunadevops wants to merge 1 commit into
open-policy-agent:masterfrom
Mallikarjunadevops:fix/issue-4567-default-failure-policy
Closed

feat: add default-failure-policy flag to fix #4567#4581
Mallikarjunadevops wants to merge 1 commit into
open-policy-agent:masterfrom
Mallikarjunadevops:fix/issue-4567-default-failure-policy

Conversation

@Mallikarjunadevops

@Mallikarjunadevops Mallikarjunadevops commented May 19, 2026

Copy link
Copy Markdown
Contributor

Fixes #4567 This pull request introduces a global --default-failure-policy flag to configure the default failure policy for admission requests and VAPs when a ConstraintTemplate does not explicitly define one.

Changes:

  • Added DefaultFailurePolicy to pkg/drivers/k8scel/schema/schema.go.
  • Updated GetV1Beta1FailurePolicy() and GetFailurePolicy() to use the new flag as a fallback instead of the hardcoded Fail.
  • Added the --default-failure-policy flag to the controller manager and audit deployments in values.yaml and raw manifests.
  • Added comprehensive unit tests in schema_test.go to ensure correct fallback logic.

Testing Performed

  • Implemented explicit unit tests to guarantee that the new global flag (--default-failure-policy) behaves perfectly as a fallback, while respecting any explicitly defined template failure policies.
  • Added test suites TestGetFailurePolicy and TestGetV1Beta1FailurePolicy to pkg/drivers/k8scel/schema/schema_test.go checking all four edge cases (fallback when default is Fail/Ignore, explicit overrides).
  • Ran standard Go test suite with passing results:
$ go test ./pkg/drivers/k8scel/schema
ok      github.com/open-policy-agent/gatekeeper/v3/pkg/drivers/k8scel/schema    4.239s

Copilot AI review requested due to automatic review settings May 19, 2026 03:08
@Mallikarjunadevops Mallikarjunadevops requested a review from a team as a code owner May 19, 2026 03:08
@linux-foundation-easycla

Copy link
Copy Markdown

CLA Missing ID

  • ❌ The email address for the commit (4106cce) is not linked to the GitHub account, preventing the EasyCLA check. Consult this Help Article and GitHub Help to resolve. (To view the commit's email address, add .patch at the end of this PR page's URL.) For further assistance with EasyCLA, please visit our EasyCLA portal and chat with our support bot.

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

Note

Copilot was unable to run its full agentic suite in this review.

Adds a configurable “default failure policy” for CEL-based schema generation and plumbs it through Gatekeeper’s manifests/Helm chart so installs can choose between Fail and Ignore.

Changes:

  • Introduces a global --default-failure-policy flag and uses it when Source.FailurePolicy is unset.
  • Adds unit tests covering defaulting behavior for both v1 and v1beta1 failure policy types.
  • Exposes the setting via Helm values and wires it into controller-manager/audit deployments and manager manifests.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
pkg/drivers/k8scel/schema/schema.go Adds default failure policy flag and defaulting logic in failure policy getters.
pkg/drivers/k8scel/schema/schema_test.go Adds tests validating defaulting behavior for v1 and v1beta1 failure policies.
manifest_staging/charts/gatekeeper/values.yaml Adds defaultFailurePolicy chart value.
manifest_staging/charts/gatekeeper/templates/gatekeeper-controller-manager-deployment.yaml Passes --default-failure-policy arg from values into controller-manager deployment.
manifest_staging/charts/gatekeeper/templates/gatekeeper-audit-deployment.yaml Passes --default-failure-policy arg from values into audit deployment.
config/manager/manager.yaml Adds --default-failure-policy=Fail to manager containers.

{{- if not .Values.controllerManager.disableGenerateOperation }}
- --operation=generate
{{- end }}
{{ if hasKey .Values "defaultFailurePolicy" }}- --default-failure-policy={{ .Values.defaultFailurePolicy }}{{- end }}
{{- if not .Values.audit.disableStatusOperation }}
- --operation=status
{{- end }}
{{ if hasKey .Values "defaultFailurePolicy" }}- --default-failure-policy={{ .Values.defaultFailurePolicy }}{{- end }}
package schema

import (
"flag"
ObjectName = "anyObject"
)

var DefaultFailurePolicy = flag.String("default-failure-policy", "Fail", "Default failure policy for ConstraintTemplate and ValidatingAdmissionPolicy. Can be set to 'Fail' or 'Ignore'.")
Comment on lines 202 to 211
func (in *Source) GetFailurePolicy() (*admissionv1.FailurePolicyType, error) {
if in.FailurePolicy == nil {
return nil, nil
var out admissionv1.FailurePolicyType
if DefaultFailurePolicy != nil && *DefaultFailurePolicy == string(admissionv1.Ignore) {
out = admissionv1.Ignore
} else {
out = admissionv1.Fail
}
return &out, nil
}
Comment on lines 227 to 236
func (in *Source) GetV1Beta1FailurePolicy() (*admissionv1beta1.FailurePolicyType, error) {
var out admissionv1beta1.FailurePolicyType
if in.FailurePolicy == nil {
out = admissionv1beta1.Fail
if DefaultFailurePolicy != nil && *DefaultFailurePolicy == string(admissionv1beta1.Ignore) {
out = admissionv1beta1.Ignore
} else {
out = admissionv1beta1.Fail
}
return &out, nil
}
Comment on lines +285 to +289
func TestGetFailurePolicy(t *testing.T) {
originalDefault := *DefaultFailurePolicy
defer func() {
*DefaultFailurePolicy = originalDefault
}()
Comment on lines +323 to +326
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
*DefaultFailurePolicy = tt.defaultFailurePolicy
got, err := tt.source.GetFailurePolicy()
@JaydipGabani

Copy link
Copy Markdown
Contributor

closing this in favor of #4568, thanks for raising the pr.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add 'default-failure-policy` flag to control failure policy on constraint template if the field is missing

3 participants