Skip to content

Commit 3fff0da

Browse files
committed
api: add skipBackgroundRequests support for MutatingPolicy and GeneratingPolicy
1 parent 50ace33 commit 3fff0da

14 files changed

Lines changed: 258 additions & 0 deletions

api/policies.kyverno.io/v1beta1/generating_policy.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,16 @@ func (s GeneratingPolicySpec) AdmissionEnabled() bool {
261261
return *s.EvaluationConfiguration.Admission.Enabled
262262
}
263263

264+
// SkipBackgroundRequestsEnabled returns whether background requests should be skipped.
265+
// Returns true by default.
266+
func (s GeneratingPolicySpec) SkipBackgroundRequestsEnabled() bool {
267+
const defaultValue = true
268+
if s.EvaluationConfiguration == nil || s.EvaluationConfiguration.SkipBackgroundRequests == nil {
269+
return defaultValue
270+
}
271+
return *s.EvaluationConfiguration.SkipBackgroundRequests
272+
}
273+
264274
type GeneratingPolicyEvaluationConfiguration struct {
265275
// Admission controls policy evaluation during admission.
266276
// +optional
@@ -276,6 +286,13 @@ type GeneratingPolicyEvaluationConfiguration struct {
276286

277287
// OrphanDownstreamOnPolicyDelete defines the configuration for orphaning downstream resources on policy delete.
278288
OrphanDownstreamOnPolicyDelete *OrphanDownstreamOnPolicyDeleteConfiguration `json:"orphanDownstreamOnPolicyDelete,omitempty"`
289+
290+
// SkipBackgroundRequests bypasses admission requests that are sent by the background controller.
291+
// The default value is set to "true", it must be set to "false" to apply
292+
// generate rules to those requests.
293+
// +kubebuilder:default=true
294+
// +kubebuilder:validation:Optional
295+
SkipBackgroundRequests *bool `json:"skipBackgroundRequests,omitempty"`
279296
}
280297

281298
// GenerateExistingConfiguration defines the configuration for generating resources for existing triggers.

api/policies.kyverno.io/v1beta1/mutating_policy.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,16 @@ func (s MutatingPolicySpec) MutateExistingEnabled() bool {
404404
return *s.EvaluationConfiguration.MutateExistingConfiguration.Enabled
405405
}
406406

407+
// SkipBackgroundRequestsEnabled returns whether background requests should be skipped.
408+
// Returns true by default.
409+
func (s MutatingPolicySpec) SkipBackgroundRequestsEnabled() bool {
410+
const defaultValue = true
411+
if s.EvaluationConfiguration == nil || s.EvaluationConfiguration.SkipBackgroundRequests == nil {
412+
return defaultValue
413+
}
414+
return *s.EvaluationConfiguration.SkipBackgroundRequests
415+
}
416+
407417
type MutatingPolicyEvaluationConfiguration struct {
408418
// Mode is the mode of policy evaluation.
409419
// Allowed values are "Kubernetes" or "JSON".
@@ -422,6 +432,13 @@ type MutatingPolicyEvaluationConfiguration struct {
422432
// MutateExisting controls whether existing resources are mutated.
423433
// +optional
424434
MutateExistingConfiguration *MutateExistingConfiguration `json:"mutateExisting,omitempty"`
435+
436+
// SkipBackgroundRequests bypasses admission requests that are sent by the background controller.
437+
// The default value is set to "true", it must be set to "false" to apply
438+
// mutateExisting rules to those requests.
439+
// +kubebuilder:default=true
440+
// +kubebuilder:validation:Optional
441+
SkipBackgroundRequests *bool `json:"skipBackgroundRequests,omitempty"`
425442
}
426443

427444
type MutatingPolicyAutogenConfiguration struct {

api/policies.kyverno.io/v1beta1/zz_generated.deepcopy.go

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

charts/kyverno-api/templates/crds/policies.kyverno.io_generatingpolicies.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1318,6 +1318,13 @@ spec:
13181318
Optional. Defaults to "false" if not specified.
13191319
type: boolean
13201320
type: object
1321+
skipBackgroundRequests:
1322+
default: true
1323+
description: |-
1324+
SkipBackgroundRequests bypasses admission requests that are sent by the background controller.
1325+
The default value is set to "true", it must be set to "false" to apply
1326+
generate rules to those requests.
1327+
type: boolean
13211328
synchronize:
13221329
description: Synchronization defines the configuration for the
13231330
synchronization of generated resources.

charts/kyverno-api/templates/crds/policies.kyverno.io_mutatingpolicies.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4453,6 +4453,13 @@ spec:
44534453
When spec.targetMatchConstraints is not defined, Kyverno mutates existing resources matched in spec.matchConstraints.
44544454
type: boolean
44554455
type: object
4456+
skipBackgroundRequests:
4457+
default: true
4458+
description: |-
4459+
SkipBackgroundRequests bypasses admission requests that are sent by the background controller.
4460+
The default value is set to "true", it must be set to "false" to apply
4461+
mutateExisting rules to those requests.
4462+
type: boolean
44564463
type: object
44574464
failurePolicy:
44584465
description: |-
@@ -5465,6 +5472,13 @@ spec:
54655472
When spec.targetMatchConstraints is not defined, Kyverno mutates existing resources matched in spec.matchConstraints.
54665473
type: boolean
54675474
type: object
5475+
skipBackgroundRequests:
5476+
default: true
5477+
description: |-
5478+
SkipBackgroundRequests bypasses admission requests that are sent by the background controller.
5479+
The default value is set to "true", it must be set to "false" to apply
5480+
mutateExisting rules to those requests.
5481+
type: boolean
54685482
type: object
54695483
failurePolicy:
54705484
description: |-

charts/kyverno-api/templates/crds/policies.kyverno.io_namespacedgeneratingpolicies.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,13 @@ spec:
706706
Optional. Defaults to "false" if not specified.
707707
type: boolean
708708
type: object
709+
skipBackgroundRequests:
710+
default: true
711+
description: |-
712+
SkipBackgroundRequests bypasses admission requests that are sent by the background controller.
713+
The default value is set to "true", it must be set to "false" to apply
714+
generate rules to those requests.
715+
type: boolean
709716
synchronize:
710717
description: Synchronization defines the configuration for the
711718
synchronization of generated resources.

charts/kyverno-api/templates/crds/policies.kyverno.io_namespacedmutatingpolicies.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2305,6 +2305,13 @@ spec:
23052305
When spec.targetMatchConstraints is not defined, Kyverno mutates existing resources matched in spec.matchConstraints.
23062306
type: boolean
23072307
type: object
2308+
skipBackgroundRequests:
2309+
default: true
2310+
description: |-
2311+
SkipBackgroundRequests bypasses admission requests that are sent by the background controller.
2312+
The default value is set to "true", it must be set to "false" to apply
2313+
mutateExisting rules to those requests.
2314+
type: boolean
23082315
type: object
23092316
failurePolicy:
23102317
description: |-
@@ -3317,6 +3324,13 @@ spec:
33173324
When spec.targetMatchConstraints is not defined, Kyverno mutates existing resources matched in spec.matchConstraints.
33183325
type: boolean
33193326
type: object
3327+
skipBackgroundRequests:
3328+
default: true
3329+
description: |-
3330+
SkipBackgroundRequests bypasses admission requests that are sent by the background controller.
3331+
The default value is set to "true", it must be set to "false" to apply
3332+
mutateExisting rules to those requests.
3333+
type: boolean
33203334
type: object
33213335
failurePolicy:
33223336
description: |-

config/crds.yaml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2993,6 +2993,13 @@ spec:
29932993
Optional. Defaults to "false" if not specified.
29942994
type: boolean
29952995
type: object
2996+
skipBackgroundRequests:
2997+
default: true
2998+
description: |-
2999+
SkipBackgroundRequests bypasses admission requests that are sent by the background controller.
3000+
The default value is set to "true", it must be set to "false" to apply
3001+
generate rules to those requests.
3002+
type: boolean
29963003
synchronize:
29973004
description: Synchronization defines the configuration for the
29983005
synchronization of generated resources.
@@ -14897,6 +14904,13 @@ spec:
1489714904
When spec.targetMatchConstraints is not defined, Kyverno mutates existing resources matched in spec.matchConstraints.
1489814905
type: boolean
1489914906
type: object
14907+
skipBackgroundRequests:
14908+
default: true
14909+
description: |-
14910+
SkipBackgroundRequests bypasses admission requests that are sent by the background controller.
14911+
The default value is set to "true", it must be set to "false" to apply
14912+
mutateExisting rules to those requests.
14913+
type: boolean
1490014914
type: object
1490114915
failurePolicy:
1490214916
description: |-
@@ -15909,6 +15923,13 @@ spec:
1590915923
When spec.targetMatchConstraints is not defined, Kyverno mutates existing resources matched in spec.matchConstraints.
1591015924
type: boolean
1591115925
type: object
15926+
skipBackgroundRequests:
15927+
default: true
15928+
description: |-
15929+
SkipBackgroundRequests bypasses admission requests that are sent by the background controller.
15930+
The default value is set to "true", it must be set to "false" to apply
15931+
mutateExisting rules to those requests.
15932+
type: boolean
1591215933
type: object
1591315934
failurePolicy:
1591415935
description: |-
@@ -18814,6 +18835,13 @@ spec:
1881418835
Optional. Defaults to "false" if not specified.
1881518836
type: boolean
1881618837
type: object
18838+
skipBackgroundRequests:
18839+
default: true
18840+
description: |-
18841+
SkipBackgroundRequests bypasses admission requests that are sent by the background controller.
18842+
The default value is set to "true", it must be set to "false" to apply
18843+
generate rules to those requests.
18844+
type: boolean
1881718845
synchronize:
1881818846
description: Synchronization defines the configuration for the
1881918847
synchronization of generated resources.
@@ -26275,6 +26303,13 @@ spec:
2627526303
When spec.targetMatchConstraints is not defined, Kyverno mutates existing resources matched in spec.matchConstraints.
2627626304
type: boolean
2627726305
type: object
26306+
skipBackgroundRequests:
26307+
default: true
26308+
description: |-
26309+
SkipBackgroundRequests bypasses admission requests that are sent by the background controller.
26310+
The default value is set to "true", it must be set to "false" to apply
26311+
mutateExisting rules to those requests.
26312+
type: boolean
2627826313
type: object
2627926314
failurePolicy:
2628026315
description: |-
@@ -27287,6 +27322,13 @@ spec:
2728727322
When spec.targetMatchConstraints is not defined, Kyverno mutates existing resources matched in spec.matchConstraints.
2728827323
type: boolean
2728927324
type: object
27325+
skipBackgroundRequests:
27326+
default: true
27327+
description: |-
27328+
SkipBackgroundRequests bypasses admission requests that are sent by the background controller.
27329+
The default value is set to "true", it must be set to "false" to apply
27330+
mutateExisting rules to those requests.
27331+
type: boolean
2729027332
type: object
2729127333
failurePolicy:
2729227334
description: |-

config/crds/policies.kyverno.io_generatingpolicies.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,6 +1316,13 @@ spec:
13161316
Optional. Defaults to "false" if not specified.
13171317
type: boolean
13181318
type: object
1319+
skipBackgroundRequests:
1320+
default: true
1321+
description: |-
1322+
SkipBackgroundRequests bypasses admission requests that are sent by the background controller.
1323+
The default value is set to "true", it must be set to "false" to apply
1324+
generate rules to those requests.
1325+
type: boolean
13191326
synchronize:
13201327
description: Synchronization defines the configuration for the
13211328
synchronization of generated resources.

config/crds/policies.kyverno.io_mutatingpolicies.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4451,6 +4451,13 @@ spec:
44514451
When spec.targetMatchConstraints is not defined, Kyverno mutates existing resources matched in spec.matchConstraints.
44524452
type: boolean
44534453
type: object
4454+
skipBackgroundRequests:
4455+
default: true
4456+
description: |-
4457+
SkipBackgroundRequests bypasses admission requests that are sent by the background controller.
4458+
The default value is set to "true", it must be set to "false" to apply
4459+
mutateExisting rules to those requests.
4460+
type: boolean
44544461
type: object
44554462
failurePolicy:
44564463
description: |-
@@ -5463,6 +5470,13 @@ spec:
54635470
When spec.targetMatchConstraints is not defined, Kyverno mutates existing resources matched in spec.matchConstraints.
54645471
type: boolean
54655472
type: object
5473+
skipBackgroundRequests:
5474+
default: true
5475+
description: |-
5476+
SkipBackgroundRequests bypasses admission requests that are sent by the background controller.
5477+
The default value is set to "true", it must be set to "false" to apply
5478+
mutateExisting rules to those requests.
5479+
type: boolean
54665480
type: object
54675481
failurePolicy:
54685482
description: |-

0 commit comments

Comments
 (0)