1414import io .fabric8 .kubernetes .client .informers .ResourceEventHandler ;
1515import io .javaoperatorsdk .operator .api .config .informer .InformerEventSourceConfiguration ;
1616import io .javaoperatorsdk .operator .api .reconciler .EventSourceContext ;
17+ import io .javaoperatorsdk .operator .processing .dependent .kubernetes .SSABasedGenericKubernetesResourceMatcher ;
1718import io .javaoperatorsdk .operator .processing .event .Event ;
1819import io .javaoperatorsdk .operator .processing .event .EventHandler ;
1920import io .javaoperatorsdk .operator .processing .event .ResourceID ;
@@ -68,6 +69,8 @@ public class InformerEventSource<R extends HasMetadata, P extends HasMetadata>
6869 private final PrimaryToSecondaryIndex <R > primaryToSecondaryIndex ;
6970 private final PrimaryToSecondaryMapper <P > primaryToSecondaryMapper ;
7071 private final String id = UUID .randomUUID ().toString ();
72+ private final KubernetesClient client ;
73+ private final String fieldManager ;
7174
7275 public InformerEventSource (
7376 InformerEventSourceConfiguration <R > configuration , EventSourceContext <P > context ) {
@@ -77,18 +80,20 @@ public InformerEventSource(
7780 context
7881 .getControllerConfiguration ()
7982 .getConfigurationService ()
80- .parseResourceVersionsForEventFilteringAndCaching ());
83+ .parseResourceVersionsForEventFilteringAndCaching (),
84+ context .getControllerConfiguration ().fieldManager ());
8185 }
8286
8387 InformerEventSource (InformerEventSourceConfiguration <R > configuration , KubernetesClient client ) {
84- this (configuration , client , false );
88+ this (configuration , client , false , "manager" );
8589 }
8690
8791 @ SuppressWarnings ({"unchecked" , "rawtypes" })
8892 private InformerEventSource (
8993 InformerEventSourceConfiguration <R > configuration ,
9094 KubernetesClient client ,
91- boolean parseResourceVersions ) {
95+ boolean parseResourceVersions ,
96+ String fieldManager ) {
9297 super (
9398 configuration .name (),
9499 configuration
@@ -112,6 +117,8 @@ private InformerEventSource(
112117 onUpdateFilter = informerConfig .getOnUpdateFilter ();
113118 onDeleteFilter = informerConfig .getOnDeleteFilter ();
114119 genericFilter = informerConfig .getGenericFilter ();
120+ this .client = client ;
121+ this .fieldManager = fieldManager ;
115122 }
116123
117124 @ Override
@@ -215,10 +222,22 @@ private boolean isEventKnownFromAnnotation(R newObject, R oldObject) {
215222 if (id .equals (parts [0 ])) {
216223 if (oldObject == null && parts .length == 1 ) {
217224 known = true ;
218- } else if (oldObject != null
219- && parts .length == 2
220- && oldObject .getMetadata ().getResourceVersion ().equals (parts [1 ])) {
221- known = true ;
225+ } else if (oldObject != null && parts .length == 2 ) {
226+ if (oldObject .getMetadata ().getResourceVersion ().equals (parts [1 ])) {
227+ known = true ;
228+ } else {
229+ // if the resource version doesn't match, there's a chance that it's due
230+ // to a change that is not meaningful, but causes the matcher logic between
231+ // desired and newObject to see a change.
232+ // TODO: this likely should be conditional on useSSA, not just the presence of the
233+ // field manager
234+ var ssaMatcher = SSABasedGenericKubernetesResourceMatcher .getInstance ();
235+ if (ssaMatcher .checkIfFieldManagerExists (newObject , fieldManager ).isPresent ()) {
236+ known = ssaMatcher .matches (oldObject , newObject , fieldManager , client , true );
237+ } else {
238+ // do we even need to worry about this case
239+ }
240+ }
222241 }
223242 }
224243 }
0 commit comments