@@ -26,6 +26,7 @@ import (
2626 "github.com/istio-ecosystem/sail-operator/pkg/constants"
2727 "github.com/istio-ecosystem/sail-operator/pkg/enqueuelogger"
2828 "github.com/istio-ecosystem/sail-operator/pkg/errlist"
29+ "github.com/istio-ecosystem/sail-operator/pkg/fieldignore"
2930 "github.com/istio-ecosystem/sail-operator/pkg/helm"
3031 predicate2 "github.com/istio-ecosystem/sail-operator/pkg/predicate"
3132 sharedreconcile "github.com/istio-ecosystem/sail-operator/pkg/reconcile"
@@ -274,29 +275,41 @@ func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error {
274275 Named ("istiorevision" ).
275276
276277 // namespaced resources
277- Watches (& corev1.ConfigMap {}, ownedResourceHandler , builder .WithPredicates (predicate2 .IgnoreUpdateWhenAnnotation ())).
278+ Watches (& corev1.ConfigMap {}, ownedResourceHandler ,
279+ builder .WithPredicates (fieldignore .RulesFor (fieldignore .DefaultRules , & corev1.ConfigMap {}).NewPredicate (), predicate2 .IgnoreUpdateWhenAnnotation ())).
278280 // We don't ignore the status for Deployments because we use it to calculate the IstioRevision status
279- Watches (& appsv1.Deployment {}, ownedResourceHandler , builder .WithPredicates (predicate2 .IgnoreUpdateWhenAnnotation ())).
281+ Watches (& appsv1.Deployment {}, ownedResourceHandler ,
282+ builder .WithPredicates (fieldignore .RulesFor (fieldignore .DefaultRules , & appsv1.Deployment {}).NewPredicate (), predicate2 .IgnoreUpdateWhenAnnotation ())).
280283 // +lint-watches:ignore: Endpoints (older versions of istiod chart create Endpoints for remote installs, but this controller watches EndpointSlices)
281284 // +lint-watches:ignore: EndpointSlice (istiod chart creates Endpoints for remote installs, but this controller watches EndpointSlices)
282- Watches (& discoveryv1.EndpointSlice {}, endpointSliceHandler , builder .WithPredicates (predicate2 .IgnoreUpdateWhenAnnotation ())).
285+ Watches (& discoveryv1.EndpointSlice {}, endpointSliceHandler ,
286+ builder .WithPredicates (
287+ fieldignore .RulesFor (fieldignore .DefaultRules , & discoveryv1.EndpointSlice {}).NewPredicate (),
288+ predicate2 .IgnoreUpdateWhenAnnotation ())).
283289 Watches (& corev1.Service {}, ownedResourceHandler ,
284- builder .WithPredicates (ignoreStatusChange (), predicate2 .IgnoreUpdateWhenAnnotation ())).
290+ builder .WithPredicates (
291+ fieldignore .RulesFor (fieldignore .DefaultRules , & corev1.Service {}).NewPredicate (),
292+ ignoreStatusChange (), predicate2 .IgnoreUpdateWhenAnnotation ())).
285293
286294 // +lint-watches:ignore: NetworkPolicy (FIXME: NetworkPolicy has not yet been added upstream, but is WIP)
287295 Watches (& networkingv1.NetworkPolicy {}, ownedResourceHandler ,
288- builder .WithPredicates (ignoreStatusChange (), predicate2 .IgnoreUpdateWhenAnnotation ())).
289-
290- // We use predicate.IgnoreUpdate() so that we skip the reconciliation when a pull secret is added to the ServiceAccount.
291- // This is necessary so that we don't remove the newly-added secret.
292- // TODO: this is a temporary hack until we implement the correct solution on the Helm-render side
293- Watches (& corev1.ServiceAccount {}, ownedResourceHandler , builder .WithPredicates (predicate2 .IgnoreUpdate ())).
294- Watches (& rbacv1.Role {}, ownedResourceHandler , builder .WithPredicates (predicate2 .IgnoreUpdateWhenAnnotation ())).
295- Watches (& rbacv1.RoleBinding {}, ownedResourceHandler , builder .WithPredicates (predicate2 .IgnoreUpdateWhenAnnotation ())).
296+ builder .WithPredicates (
297+ fieldignore .RulesFor (fieldignore .DefaultRules , & networkingv1.NetworkPolicy {}).NewPredicate (),
298+ ignoreStatusChange (), predicate2 .IgnoreUpdateWhenAnnotation ())).
299+ Watches (& corev1.ServiceAccount {}, ownedResourceHandler ,
300+ builder .WithPredicates (fieldignore .RulesFor (fieldignore .DefaultRules , & corev1.ServiceAccount {}).NewPredicate (), predicate2 .IgnoreUpdateWhenAnnotation ())).
301+ Watches (& rbacv1.Role {}, ownedResourceHandler ,
302+ builder .WithPredicates (fieldignore .RulesFor (fieldignore .DefaultRules , & rbacv1.Role {}).NewPredicate (), predicate2 .IgnoreUpdateWhenAnnotation ())).
303+ Watches (& rbacv1.RoleBinding {}, ownedResourceHandler ,
304+ builder .WithPredicates (fieldignore .RulesFor (fieldignore .DefaultRules , & rbacv1.RoleBinding {}).NewPredicate (), predicate2 .IgnoreUpdateWhenAnnotation ())).
296305 Watches (& policyv1.PodDisruptionBudget {}, ownedResourceHandler ,
297- builder .WithPredicates (ignoreStatusChange (), predicate2 .IgnoreUpdateWhenAnnotation ())).
306+ builder .WithPredicates (
307+ fieldignore .RulesFor (fieldignore .DefaultRules , & policyv1.PodDisruptionBudget {}).NewPredicate (),
308+ ignoreStatusChange (), predicate2 .IgnoreUpdateWhenAnnotation ())).
298309 Watches (& autoscalingv2.HorizontalPodAutoscaler {}, ownedResourceHandler ,
299- builder .WithPredicates (ignoreStatusChange (), predicate2 .IgnoreUpdateWhenAnnotation ())).
310+ builder .WithPredicates (
311+ fieldignore .RulesFor (fieldignore .DefaultRules , & autoscalingv2.HorizontalPodAutoscaler {}).NewPredicate (),
312+ ignoreStatusChange (), predicate2 .IgnoreUpdateWhenAnnotation ())).
300313
301314 // +lint-watches:ignore: Namespace (not found in charts, but must be watched to reconcile IstioRevision when its namespace is created)
302315 Watches (& corev1.Namespace {}, nsHandler , builder .WithPredicates (ignoreStatusChange ()), builder .WithPredicates (predicate2 .IgnoreUpdateWhenAnnotation ())).
@@ -308,12 +321,20 @@ func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error {
308321 Watches (& v1.IstioRevisionTag {}, revisionTagHandler ).
309322
310323 // cluster-scoped resources
311- Watches (& rbacv1.ClusterRole {}, ownedResourceHandler , builder .WithPredicates (predicate2 .IgnoreUpdateWhenAnnotation ())).
312- Watches (& rbacv1.ClusterRoleBinding {}, ownedResourceHandler , builder .WithPredicates (predicate2 .IgnoreUpdateWhenAnnotation ())).
324+ Watches (& rbacv1.ClusterRole {}, ownedResourceHandler ,
325+ builder .WithPredicates (fieldignore .RulesFor (fieldignore .DefaultRules , & rbacv1.ClusterRole {}).NewPredicate (), predicate2 .IgnoreUpdateWhenAnnotation ())).
326+ Watches (& rbacv1.ClusterRoleBinding {}, ownedResourceHandler ,
327+ builder .WithPredicates (
328+ fieldignore .RulesFor (fieldignore .DefaultRules , & rbacv1.ClusterRoleBinding {}).NewPredicate (),
329+ predicate2 .IgnoreUpdateWhenAnnotation ())).
313330 Watches (& admissionv1.MutatingWebhookConfiguration {}, ownedResourceHandler ,
314- builder .WithPredicates (webhookConfigPredicate (), predicate2 .IgnoreUpdateWhenAnnotation ())).
331+ builder .WithPredicates (
332+ fieldignore .RulesFor (fieldignore .DefaultRules , & admissionv1.MutatingWebhookConfiguration {}).NewPredicate (),
333+ predicate2 .IgnoreUpdateWhenAnnotation ())).
315334 Watches (& admissionv1.ValidatingWebhookConfiguration {}, ownedResourceHandler ,
316- builder .WithPredicates (webhookConfigPredicate (), predicate2 .IgnoreUpdateWhenAnnotation ())).
335+ builder .WithPredicates (
336+ fieldignore .RulesFor (fieldignore .DefaultRules , & admissionv1.ValidatingWebhookConfiguration {}).NewPredicate (),
337+ predicate2 .IgnoreUpdateWhenAnnotation ())).
317338
318339 // +lint-watches:ignore: IstioCNI (not found in charts, but this controller needs to watch it to update the IstioRevision status)
319340 Watches (& v1.IstioCNI {}, istioCniHandler ).
@@ -725,42 +746,6 @@ func specWasUpdated(oldObject client.Object, newObject client.Object) bool {
725746 return oldObject .GetGeneration () != newObject .GetGeneration ()
726747}
727748
728- func webhookConfigPredicate () predicate.Funcs {
729- return predicate.Funcs {
730- UpdateFunc : func (e event.TypedUpdateEvent [client.Object ]) bool {
731- if e .ObjectOld == nil || e .ObjectNew == nil {
732- return false
733- }
734-
735- // Istiod updates the caBundle and failurePolicy fields in its webhook configs.
736- // We must ignore changes to these fields to prevent an endless update loop.
737- // We must use deep copies to avoid mutating the shared informer cache.
738- oldCopy := e .ObjectOld .DeepCopyObject ().(client.Object )
739- newCopy := e .ObjectNew .DeepCopyObject ().(client.Object )
740- clearIgnoredFields (oldCopy )
741- clearIgnoredFields (newCopy )
742- return ! reflect .DeepEqual (newCopy , oldCopy )
743- },
744- }
745- }
746-
747- func clearIgnoredFields (obj client.Object ) {
748- obj .SetResourceVersion ("" )
749- obj .SetGeneration (0 )
750- obj .SetManagedFields (nil )
751- switch webhookConfig := obj .(type ) {
752- case * admissionv1.ValidatingWebhookConfiguration :
753- for i := range len (webhookConfig .Webhooks ) {
754- webhookConfig .Webhooks [i ].FailurePolicy = nil
755- webhookConfig .Webhooks [i ].ClientConfig .CABundle = nil
756- }
757- case * admissionv1.MutatingWebhookConfiguration :
758- for i := range len (webhookConfig .Webhooks ) {
759- webhookConfig .Webhooks [i ].ClientConfig .CABundle = nil
760- }
761- }
762- }
763-
764749func wrapEventHandler (logger logr.Logger , handler handler.EventHandler ) handler.EventHandler {
765750 return enqueuelogger .WrapIfNecessary (v1 .IstioRevisionKind , logger , handler )
766751}
0 commit comments