@@ -51,12 +51,7 @@ static <R extends HasMetadata, P extends HasMetadata> Matcher<R, P> matcherFor(
51
51
@ Override
52
52
public Result <R > match (R actualResource , P primary , Context <P > context ) {
53
53
var desired = dependentResource .desired (primary , context );
54
- return match (desired , actualResource , true , false , false );
55
- }
56
-
57
- public static <R extends HasMetadata > Result <R > match (R desired , R actualResource ,
58
- boolean considerMetadata ) {
59
- return match (desired , actualResource , considerMetadata , false );
54
+ return match (desired , actualResource , false , false , false );
60
55
}
61
56
62
57
/**
@@ -65,10 +60,14 @@ public static <R extends HasMetadata> Result<R> match(R desired, R actualResourc
65
60
*
66
61
* @param desired the desired resource
67
62
* @param actualResource the actual resource
68
- * @param considerMetadata {@code true} if labels and annotations will be checked for equality,
69
- * {@code false} otherwise (meaning that metadata changes will be ignored for matching
70
- * purposes)
71
- * @param equality if {@code false}, the algorithm checks if the properties in the desired
63
+ * @param considerLabelsAndAnnotations {@code true} if labels and annotations will be checked for
64
+ * equality, {@code false} otherwise (meaning that metadata changes will be ignored for
65
+ * matching purposes)
66
+ * @param labelsAndAnnotationsEquality if true labels and annotation match exactly in the actual
67
+ * and desired state if false, additional elements are allowed in actual annotations.
68
+ * Considered only if considerLabelsAndAnnotations is true.
69
+ *
70
+ * @param specEquality if {@code false}, the algorithm checks if the properties in the desired
72
71
* resource spec are same as in the actual resource spec. The reason is that admission
73
72
* controllers and default Kubernetes controllers might add default values to some
74
73
* properties which are not set in the desired resources' spec and comparing it with simple
@@ -84,22 +83,41 @@ public static <R extends HasMetadata> Result<R> match(R desired, R actualResourc
84
83
* @param <R> resource
85
84
*/
86
85
public static <R extends HasMetadata > Result <R > match (R desired , R actualResource ,
87
- boolean considerMetadata , boolean equality ) {
88
- return match (desired , actualResource , considerMetadata , false , equality );
89
- }
90
-
91
- public static <R extends HasMetadata > Result <R > match (R desired , R actualResource ,
92
- boolean considerMetadata , String ... ignoreList ) {
93
- return match (desired , actualResource , considerMetadata , false , false , ignoreList );
86
+ boolean considerLabelsAndAnnotations , boolean labelsAndAnnotationsEquality ,
87
+ boolean specEquality ) {
88
+ return match (desired , actualResource , considerLabelsAndAnnotations ,
89
+ labelsAndAnnotationsEquality , specEquality , new String [0 ]);
94
90
}
95
91
92
+ /**
93
+ * Determines whether the specified actual resource matches the specified desired resource,
94
+ * possibly considering metadata and deeper equality checks.
95
+ *
96
+ * @param desired the desired resource
97
+ * @param actualResource the actual resource
98
+ * @param considerLabelsAndAnnotations {@code true} if labels and annotations will be checked for
99
+ * equality, {@code false} otherwise (meaning that metadata changes will be ignored for
100
+ * matching purposes)
101
+ * @param labelsAndAnnotationsEquality if true labels and annotation match exactly in the actual
102
+ * and desired state if false, additional elements are allowed in actual annotations.
103
+ * Considered only if considerLabelsAndAnnotations is true.
104
+ *
105
+ * @param ignorePaths are paths in the resource that are ignored on matching (basically an ignore
106
+ * list). All changes with a target prefix path on a calculated JSON Patch between actual
107
+ * and desired will be ignored. If there are other changes, non-present on ignore list
108
+ * match fails.
109
+ * @return results of matching
110
+ * @param <R> resource
111
+ */
96
112
public static <R extends HasMetadata > Result <R > match (R desired , R actualResource ,
97
- boolean considerMetadata , boolean metadataEquality , String ... ignoreList ) {
98
- return match (desired , actualResource , considerMetadata , metadataEquality , false , ignoreList );
113
+ boolean considerLabelsAndAnnotations , boolean labelsAndAnnotationsEquality ,
114
+ String ... ignorePaths ) {
115
+ return match (desired , actualResource , considerLabelsAndAnnotations ,
116
+ labelsAndAnnotationsEquality , false , ignorePaths );
99
117
}
100
118
101
119
private static <R extends HasMetadata > Result <R > match (R desired , R actualResource ,
102
- boolean considerMetadata , boolean metadataEquality , boolean specEquality ,
120
+ boolean considerMetadata , boolean labelsAndAnnotationsEquality , boolean specEquality ,
103
121
String ... ignoredPaths ) {
104
122
final List <String > ignoreList =
105
123
ignoredPaths != null && ignoredPaths .length > 0 ? Arrays .asList (ignoredPaths )
@@ -120,7 +138,7 @@ private static <R extends HasMetadata> Result<R> match(R desired, R actualResour
120
138
121
139
if (considerMetadata ) {
122
140
Optional <Result <R >> res =
123
- matchMetadata (desired , actualResource , metadataEquality , wholeDiffJsonPatch );
141
+ matchMetadata (desired , actualResource , labelsAndAnnotationsEquality , wholeDiffJsonPatch );
124
142
if (res .isPresent ()) {
125
143
return res .orElseThrow ();
126
144
}
@@ -162,8 +180,8 @@ private static <R extends HasMetadata> Result<R> matchSpec(R desired, boolean sp
162
180
}
163
181
164
182
private static <R extends HasMetadata > Optional <Result <R >> matchMetadata (R desired ,
165
- R actualResource , boolean metadataEquality , JsonNode wholeDiffJsonPatch ) {
166
- if (metadataEquality ) {
183
+ R actualResource , boolean labelsAndAnnotationsEquality , JsonNode wholeDiffJsonPatch ) {
184
+ if (labelsAndAnnotationsEquality ) {
167
185
final var desiredMetadata = desired .getMetadata ();
168
186
final var actualMetadata = actualResource .getMetadata ();
169
187
@@ -224,31 +242,20 @@ private static List<JsonNode> getDiffsImpactingPathsWithPrefixes(JsonNode diffJs
224
242
return Collections .emptyList ();
225
243
}
226
244
227
- /**
228
- * Determines whether the specified actual resource matches the desired state defined by the
229
- * specified {@link KubernetesDependentResource} based on the observed state of the associated
230
- * specified primary resource.
231
- *
232
- * @param dependentResource the {@link KubernetesDependentResource} implementation used to
233
- * computed the desired state associated with the specified primary resource
234
- * @param actualResource the observed dependent resource for which we want to determine whether it
235
- * matches the desired state or not
236
- * @param primary the primary resource from which we want to compute the desired state
237
- * @param context the {@link Context} instance within which this method is called
238
- * @param considerMetadata {@code true} to consider the metadata of the actual resource when
239
- * determining if it matches the desired state, {@code false} if matching should occur only
240
- * considering the spec of the resources
241
- * @return a {@link io.javaoperatorsdk.operator.processing.dependent.Matcher.Result} object
242
- * @param <R> the type of resource we want to determine whether they match or not
243
- * @param <P> the type of primary resources associated with the secondary resources we want to
244
- * match
245
- * @param strongEquality if the resource should match exactly
246
- */
245
+ @ Deprecated (forRemoval = true )
246
+ public static <R extends HasMetadata , P extends HasMetadata > Result <R > match (
247
+ KubernetesDependentResource <R , P > dependentResource , R actualResource , P primary ,
248
+ Context <P > context , boolean considerLabelsAndAnnotations , boolean specEquality ) {
249
+ final var desired = dependentResource .desired (primary , context );
250
+ return match (desired , actualResource , considerLabelsAndAnnotations , specEquality );
251
+ }
252
+
253
+ @ Deprecated (forRemoval = true )
247
254
public static <R extends HasMetadata , P extends HasMetadata > Result <R > match (
248
255
KubernetesDependentResource <R , P > dependentResource , R actualResource , P primary ,
249
- Context <P > context , boolean considerMetadata , boolean strongEquality ) {
256
+ Context <P > context , boolean considerLabelsAndAnnotations , String ... ignorePaths ) {
250
257
final var desired = dependentResource .desired (primary , context );
251
- return match (desired , actualResource , considerMetadata , strongEquality );
258
+ return match (desired , actualResource , considerLabelsAndAnnotations , true , ignorePaths );
252
259
}
253
260
254
261
/**
@@ -262,39 +269,38 @@ public static <R extends HasMetadata, P extends HasMetadata> Result<R> match(
262
269
* matches the desired state or not
263
270
* @param primary the primary resource from which we want to compute the desired state
264
271
* @param context the {@link Context} instance within which this method is called
265
- * @param considerMetadata {@code true} to consider the metadata of the actual resource when
266
- * determining if it matches the desired state, {@code false} if matching should occur only
267
- * considering the spec of the resources
268
- * @return a {@link io.javaoperatorsdk.operator.processing.dependent.Matcher.Result} object
272
+ * @param considerLabelsAndAnnotations {@code true} to consider the metadata of the actual
273
+ * resource when determining if it matches the desired state, {@code false} if matching
274
+ * should occur only considering the spec of the resources
275
+ * @param labelsAndAnnotationsEquality if true labels and annotation match exactly in the actual
276
+ * and desired state if false, additional elements are allowed in actual annotations.
277
+ * Considered only if considerLabelsAndAnnotations is true.
269
278
* @param <R> the type of resource we want to determine whether they match or not
270
279
* @param <P> the type of primary resources associated with the secondary resources we want to
271
280
* match
272
281
* @param ignorePaths are paths in the resource that are ignored on matching (basically an ignore
273
282
* list). All changes with a target prefix path on a calculated JSON Patch between actual
274
283
* and desired will be ignored. If there are other changes, non-present on ignore list
275
284
* match fails.
276
- *
285
+ * @return a {@link io.javaoperatorsdk.operator.processing.dependent.Matcher.Result} object
277
286
*/
278
287
public static <R extends HasMetadata , P extends HasMetadata > Result <R > match (
279
288
KubernetesDependentResource <R , P > dependentResource , R actualResource , P primary ,
280
- Context <P > context , boolean considerMetadata , String ... ignorePaths ) {
281
- final var desired = dependentResource .desired (primary , context );
282
- return match (desired , actualResource , considerMetadata , ignorePaths );
283
- }
284
-
285
- public static <R extends HasMetadata , P extends HasMetadata > Result <R > match (
286
- KubernetesDependentResource <R , P > dependentResource , R actualResource , P primary ,
287
- Context <P > context , boolean considerMetadata , boolean metadataEquality ,
289
+ Context <P > context , boolean considerLabelsAndAnnotations ,
290
+ boolean labelsAndAnnotationsEquality ,
288
291
String ... ignorePaths ) {
289
292
final var desired = dependentResource .desired (primary , context );
290
- return match (desired , actualResource , considerMetadata , metadataEquality , ignorePaths );
293
+ return match (desired , actualResource , considerLabelsAndAnnotations ,
294
+ labelsAndAnnotationsEquality , ignorePaths );
291
295
}
292
296
293
297
public static <R extends HasMetadata , P extends HasMetadata > Result <R > match (
294
298
KubernetesDependentResource <R , P > dependentResource , R actualResource , P primary ,
295
- Context <P > context , boolean considerMetadata , boolean metadataEquality ,
296
- boolean strongEquality ) {
299
+ Context <P > context , boolean considerLabelsAndAnnotations ,
300
+ boolean labelsAndAnnotationsEquality ,
301
+ boolean specEquality ) {
297
302
final var desired = dependentResource .desired (primary , context );
298
- return match (desired , actualResource , considerMetadata , metadataEquality , strongEquality );
303
+ return match (desired , actualResource , considerLabelsAndAnnotations ,
304
+ labelsAndAnnotationsEquality , specEquality );
299
305
}
300
306
}
0 commit comments