1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-04-08 18:15:48 +00:00

allowing users to skip policy validation when mutating resources (#2365)

* allowing users to skip policy validation when mutating resources

* fix unit test issue

* fix comment
This commit is contained in:
Vyankatesh Kudtarkar 2021-09-08 10:42:44 +05:30 committed by GitHub
parent 511db4372b
commit 12530619ce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 37 additions and 3 deletions

View file

@ -1518,6 +1518,11 @@ spec:
type: array
type: object
type: array
schemaValidation:
description: SchemaValidation skips policy validation checks. Optional.
The default value is set to "true", it must be set to "false" to
disable the validation checks.
type: boolean
validationFailureAction:
description: ValidationFailureAction controls if a validation policy
rule failure should disallow the admission review request (enforce),

View file

@ -1519,6 +1519,11 @@ spec:
type: array
type: object
type: array
schemaValidation:
description: SchemaValidation skips policy validation checks. Optional.
The default value is set to "true", it must be set to "false" to
disable the validation checks.
type: boolean
validationFailureAction:
description: ValidationFailureAction controls if a validation policy
rule failure should disallow the admission review request (enforce),

View file

@ -956,6 +956,11 @@ spec:
type: array
type: object
type: array
schemaValidation:
description: SchemaValidation skips policy validation checks. Optional.
The default value is set to "true", it must be set to "false" to
disable the validation checks.
type: boolean
validationFailureAction:
description: ValidationFailureAction controls if a validation policy rule failure should disallow the admission review request (enforce), or allow (audit) the admission review request and report an error in a policy report. Optional. The default value is "audit".
type: string
@ -2705,6 +2710,11 @@ spec:
type: array
type: object
type: array
schemaValidation:
description: SchemaValidation skips policy validation checks. Optional.
The default value is set to "true", it must be set to "false" to
disable the validation checks.
type: boolean
validationFailureAction:
description: ValidationFailureAction controls if a validation policy rule failure should disallow the admission review request (enforce), or allow (audit) the admission review request and report an error in a policy report. Optional. The default value is "audit".
type: string

View file

@ -943,6 +943,9 @@ spec:
type: array
type: object
type: array
schemaValidation:
description: SchemaValidation skips policy validation checks. Optional.The default value is set to "true", it must be set to "false" to disable the validation checks.
type: boolean
validationFailureAction:
description: ValidationFailureAction controls if a validation policy rule failure should disallow the admission review request (enforce), or allow (audit) the admission review request and report an error in a policy report. Optional. The default value is "audit".
type: string
@ -2664,6 +2667,9 @@ spec:
type: array
type: object
type: array
schemaValidation:
description: SchemaValidation skips policy validation checks. Optional.The default value is set to "true", it must be set to "false" to disable the validation checks.
type: boolean
validationFailureAction:
description: ValidationFailureAction controls if a validation policy rule failure should disallow the admission review request (enforce), or allow (audit) the admission review request and report an error in a policy report. Optional. The default value is "audit".
type: string

View file

@ -54,6 +54,11 @@ type Spec struct {
// uses variables that are only available in the admission review request (e.g. user name).
// +optional
Background *bool `json:"background,omitempty" yaml:"background,omitempty"`
// SchemaValidation skips policy validation checks.
// Optional. The default value is set to "true", it must be set to "false" to disable the validation checks.
// +optional
SchemaValidation *bool `json:"schemaValidation,omitempty" yaml:"schemaValidation,omitempty"`
}
// Rule defines a validation, mutation, or generation control for matching resources.

View file

@ -167,10 +167,13 @@ func (o *Controller) ValidatePolicyMutation(policy v1.ClusterPolicy) error {
return err
}
err = o.ValidateResource(*patchedResource.DeepCopy(), "", kind)
if err != nil {
return err
if policy.Spec.SchemaValidation == nil || *policy.Spec.SchemaValidation {
err = o.ValidateResource(*patchedResource.DeepCopy(), "", kind)
if err != nil {
return err
}
}
}
return nil