14
14
import io .fabric8 .kubernetes .client .informers .ResourceEventHandler ;
15
15
import io .javaoperatorsdk .operator .api .config .informer .InformerEventSourceConfiguration ;
16
16
import io .javaoperatorsdk .operator .api .reconciler .EventSourceContext ;
17
+ import io .javaoperatorsdk .operator .processing .dependent .kubernetes .GenericKubernetesResourceMatcher ;
18
+ import io .javaoperatorsdk .operator .processing .dependent .kubernetes .SSABasedGenericKubernetesResourceMatcher ;
17
19
import io .javaoperatorsdk .operator .processing .event .Event ;
18
20
import io .javaoperatorsdk .operator .processing .event .EventHandler ;
19
21
import io .javaoperatorsdk .operator .processing .event .ResourceID ;
@@ -68,6 +70,8 @@ public class InformerEventSource<R extends HasMetadata, P extends HasMetadata>
68
70
private final PrimaryToSecondaryIndex <R > primaryToSecondaryIndex ;
69
71
private final PrimaryToSecondaryMapper <P > primaryToSecondaryMapper ;
70
72
private final String id = UUID .randomUUID ().toString ();
73
+ private final KubernetesClient client ;
74
+ private final String fieldManager ;
71
75
72
76
public InformerEventSource (
73
77
InformerEventSourceConfiguration <R > configuration , EventSourceContext <P > context ) {
@@ -77,18 +81,20 @@ public InformerEventSource(
77
81
context
78
82
.getControllerConfiguration ()
79
83
.getConfigurationService ()
80
- .parseResourceVersionsForEventFilteringAndCaching ());
84
+ .parseResourceVersionsForEventFilteringAndCaching (),
85
+ context .getControllerConfiguration ().fieldManager ());
81
86
}
82
87
83
88
InformerEventSource (InformerEventSourceConfiguration <R > configuration , KubernetesClient client ) {
84
- this (configuration , client , false );
89
+ this (configuration , client , false , "manager" );
85
90
}
86
91
87
92
@ SuppressWarnings ({"unchecked" , "rawtypes" })
88
93
private InformerEventSource (
89
94
InformerEventSourceConfiguration <R > configuration ,
90
95
KubernetesClient client ,
91
- boolean parseResourceVersions ) {
96
+ boolean parseResourceVersions ,
97
+ String fieldManager ) {
92
98
super (
93
99
configuration .name (),
94
100
configuration
@@ -112,6 +118,8 @@ private InformerEventSource(
112
118
onUpdateFilter = informerConfig .getOnUpdateFilter ();
113
119
onDeleteFilter = informerConfig .getOnDeleteFilter ();
114
120
genericFilter = informerConfig .getGenericFilter ();
121
+ this .client = client ;
122
+ this .fieldManager = fieldManager ;
115
123
}
116
124
117
125
@ Override
@@ -215,10 +223,22 @@ private boolean isEventKnownFromAnnotation(R newObject, R oldObject) {
215
223
if (id .equals (parts [0 ])) {
216
224
if (oldObject == null && parts .length == 1 ) {
217
225
known = true ;
218
- } else if (oldObject != null
219
- && parts .length == 2
220
- && oldObject .getMetadata ().getResourceVersion ().equals (parts [1 ])) {
221
- known = true ;
226
+ } else if (oldObject != null && parts .length == 2 ) {
227
+ if (oldObject .getMetadata ().getResourceVersion ().equals (parts [1 ])) {
228
+ known = true ;
229
+ } else {
230
+ // if the resource version doesn't match, there's a chance that it's due
231
+ // to a change that is not meaningful, but causes the matcher logic between
232
+ // desired and newObject to see a change.
233
+ // TODO: this likely should be conditional on useSSA, not just the presense of the
234
+ // field manager
235
+ var ssaMatcher = SSABasedGenericKubernetesResourceMatcher .getInstance ();
236
+ if (ssaMatcher .checkIfFieldManagerExists (newObject , fieldManager ).isPresent ()) {
237
+ known = ssaMatcher .matches (newObject , oldObject , fieldManager , client );
238
+ } else {
239
+ // do we even need to worry about this case
240
+ }
241
+ }
222
242
}
223
243
}
224
244
}
0 commit comments