1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2024-12-14 11:57:48 +00:00

fix: unsupported defaults in api (#11021)

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
This commit is contained in:
Charles-Edouard Brétéché 2024-09-05 16:48:47 +02:00 committed by GitHub
parent 209fd8d90a
commit 02e27ec3d4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 17 additions and 3 deletions

View file

@ -108,7 +108,7 @@ type Rule struct {
// generate and mutateExisting rules to those requests. // generate and mutateExisting rules to those requests.
// +kubebuilder:default=true // +kubebuilder:default=true
// +kubebuilder:validation:Optional // +kubebuilder:validation:Optional
SkipBackgroundRequests bool `json:"skipBackgroundRequests,omitempty"` SkipBackgroundRequests *bool `json:"skipBackgroundRequests,omitempty"`
} }
// HasMutate checks for mutate rule // HasMutate checks for mutate rule

View file

@ -1415,6 +1415,11 @@ func (in *Rule) DeepCopyInto(out *Rule) {
(*in)[i].DeepCopyInto(&(*out)[i]) (*in)[i].DeepCopyInto(&(*out)[i])
} }
} }
if in.SkipBackgroundRequests != nil {
in, out := &in.SkipBackgroundRequests, &out.SkipBackgroundRequests
*out = new(bool)
**out = **in
}
return return
} }

View file

@ -71,7 +71,7 @@ type Rule struct {
// generate and mutateExisting rules to those requests. // generate and mutateExisting rules to those requests.
// +kubebuilder:default=true // +kubebuilder:default=true
// +kubebuilder:validation:Optional // +kubebuilder:validation:Optional
SkipBackgroundRequests bool `json:"skipBackgroundRequests,omitempty"` SkipBackgroundRequests *bool `json:"skipBackgroundRequests,omitempty"`
} }
// HasMutate checks for mutate rule // HasMutate checks for mutate rule

View file

@ -748,6 +748,11 @@ func (in *Rule) DeepCopyInto(out *Rule) {
(*in)[i].DeepCopyInto(&(*out)[i]) (*in)[i].DeepCopyInto(&(*out)[i])
} }
} }
if in.SkipBackgroundRequests != nil {
in, out := &in.SkipBackgroundRequests, &out.SkipBackgroundRequests
*out = new(bool)
**out = **in
}
return return
} }

View file

@ -105,7 +105,11 @@ func skipBackgroundRequests(policy kyvernov1.PolicyInterface, logger logr.Logger
policyNew := policy.CreateDeepCopy() policyNew := policy.CreateDeepCopy()
policyNew.GetSpec().Rules = nil policyNew.GetSpec().Rules = nil
for _, rule := range policy.GetSpec().Rules { 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 continue
} }
logger.V(4).Info("applying background rule", "rule", rule.Name, "skipBackgroundRequests", rule.SkipBackgroundRequests, "backgroundSaDesired", bgsaDesired, "backgroundSaActual", bgsaActual) logger.V(4).Info("applying background rule", "rule", rule.Name, "skipBackgroundRequests", rule.SkipBackgroundRequests, "backgroundSaDesired", bgsaDesired, "backgroundSaActual", bgsaActual)