From 02e27ec3d417e203b7fb339f4de0d13d677deea0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Charles-Edouard=20Br=C3=A9t=C3=A9ch=C3=A9?= Date: Thu, 5 Sep 2024 16:48:47 +0200 Subject: [PATCH] fix: unsupported defaults in api (#11021) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Charles-Edouard Brétéché --- api/kyverno/v1/rule_types.go | 2 +- api/kyverno/v1/zz_generated.deepcopy.go | 5 +++++ api/kyverno/v2beta1/rule_types.go | 2 +- api/kyverno/v2beta1/zz_generated.deepcopy.go | 5 +++++ pkg/webhooks/resource/utils.go | 6 +++++- 5 files changed, 17 insertions(+), 3 deletions(-) diff --git a/api/kyverno/v1/rule_types.go b/api/kyverno/v1/rule_types.go index 33f9f2c2cc..f848815b8f 100644 --- a/api/kyverno/v1/rule_types.go +++ b/api/kyverno/v1/rule_types.go @@ -108,7 +108,7 @@ type Rule struct { // generate and mutateExisting rules to those requests. // +kubebuilder:default=true // +kubebuilder:validation:Optional - SkipBackgroundRequests bool `json:"skipBackgroundRequests,omitempty"` + SkipBackgroundRequests *bool `json:"skipBackgroundRequests,omitempty"` } // HasMutate checks for mutate rule diff --git a/api/kyverno/v1/zz_generated.deepcopy.go b/api/kyverno/v1/zz_generated.deepcopy.go index 9b50a27ad3..b2b945610f 100755 --- a/api/kyverno/v1/zz_generated.deepcopy.go +++ b/api/kyverno/v1/zz_generated.deepcopy.go @@ -1415,6 +1415,11 @@ func (in *Rule) DeepCopyInto(out *Rule) { (*in)[i].DeepCopyInto(&(*out)[i]) } } + if in.SkipBackgroundRequests != nil { + in, out := &in.SkipBackgroundRequests, &out.SkipBackgroundRequests + *out = new(bool) + **out = **in + } return } diff --git a/api/kyverno/v2beta1/rule_types.go b/api/kyverno/v2beta1/rule_types.go index 8a92c5dc3e..6ca8783803 100644 --- a/api/kyverno/v2beta1/rule_types.go +++ b/api/kyverno/v2beta1/rule_types.go @@ -71,7 +71,7 @@ type Rule struct { // generate and mutateExisting rules to those requests. // +kubebuilder:default=true // +kubebuilder:validation:Optional - SkipBackgroundRequests bool `json:"skipBackgroundRequests,omitempty"` + SkipBackgroundRequests *bool `json:"skipBackgroundRequests,omitempty"` } // HasMutate checks for mutate rule diff --git a/api/kyverno/v2beta1/zz_generated.deepcopy.go b/api/kyverno/v2beta1/zz_generated.deepcopy.go index 7a282816ff..c23558c1f4 100755 --- a/api/kyverno/v2beta1/zz_generated.deepcopy.go +++ b/api/kyverno/v2beta1/zz_generated.deepcopy.go @@ -748,6 +748,11 @@ func (in *Rule) DeepCopyInto(out *Rule) { (*in)[i].DeepCopyInto(&(*out)[i]) } } + if in.SkipBackgroundRequests != nil { + in, out := &in.SkipBackgroundRequests, &out.SkipBackgroundRequests + *out = new(bool) + **out = **in + } return } diff --git a/pkg/webhooks/resource/utils.go b/pkg/webhooks/resource/utils.go index e65a8a34f6..909aae97db 100644 --- a/pkg/webhooks/resource/utils.go +++ b/pkg/webhooks/resource/utils.go @@ -105,7 +105,11 @@ func skipBackgroundRequests(policy kyvernov1.PolicyInterface, logger logr.Logger policyNew := policy.CreateDeepCopy() policyNew.GetSpec().Rules = nil for _, rule := range policy.GetSpec().Rules { - if rule.SkipBackgroundRequests && (bgsaDesired == bgsaActual) { + skipBackgroundRequests := true + if rule.SkipBackgroundRequests != nil { + skipBackgroundRequests = *rule.SkipBackgroundRequests + } + if skipBackgroundRequests && (bgsaDesired == bgsaActual) { continue } logger.V(4).Info("applying background rule", "rule", rule.Name, "skipBackgroundRequests", rule.SkipBackgroundRequests, "backgroundSaDesired", bgsaDesired, "backgroundSaActual", bgsaActual)