@@ -19,6 +19,7 @@ package controllers
1919import (
2020 "reflect"
2121
22+ appsv1 "k8s.io/api/apps/v1"
2223 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2324 "k8s.io/apimachinery/pkg/runtime"
2425 "sigs.k8s.io/controller-runtime/pkg/client"
@@ -60,9 +61,20 @@ func (p IgnoreSameContentPredicate) Update(e event.UpdateEvent) bool {
6061 // ignore resource version
6162 oldObj .SetResourceVersion ("" )
6263 newObj .SetResourceVersion ("" )
64+ // ignore generation
65+ oldObj .SetGeneration (0 )
66+ newObj .SetGeneration (0 )
6367 // ignore managed fields
6468 oldObj .SetManagedFields ([]metav1.ManagedFieldsEntry {})
6569 newObj .SetManagedFields ([]metav1.ManagedFieldsEntry {})
70+
71+ // logic specific to resource type
72+ switch v := oldObj .(type ) {
73+ case * appsv1.Deployment :
74+ p .handleDeployment (v , newObj .(* appsv1.Deployment ))
75+ default :
76+ }
77+
6678 oldUnstr , err := runtime .DefaultUnstructuredConverter .ToUnstructured (oldObj )
6779 if err != nil {
6880 return false
@@ -73,3 +85,14 @@ func (p IgnoreSameContentPredicate) Update(e event.UpdateEvent) bool {
7385 }
7486 return ! reflect .DeepEqual (oldUnstr , newUnstr )
7587}
88+
89+ func (p IgnoreSameContentPredicate ) handleDeployment (oldObj , newObj * appsv1.Deployment ) {
90+ // ignore object if only Observed generation changed
91+ oldObj .Status .ObservedGeneration = 0
92+ newObj .Status .ObservedGeneration = 0
93+
94+ // ignore annotation which is auto set by Kubernetes
95+ revAnnotation := "deployment.kubernetes.io/revision"
96+ delete (oldObj .Annotations , revAnnotation )
97+ delete (newObj .Annotations , revAnnotation )
98+ }
0 commit comments