20
20
import io .javaoperatorsdk .operator .OperatorException ;
21
21
import io .javaoperatorsdk .operator .api .reconciler .Context ;
22
22
23
- import com .fasterxml .jackson .core .JsonProcessingException ;
24
-
25
23
/**
26
24
* Matches the actual state on the server vs the desired state. Based on the managedFields of SSA.
27
25
*
@@ -65,39 +63,36 @@ public static <L extends HasMetadata> SSABasedGenericKubernetesResourceMatcher<L
65
63
LoggerFactory .getLogger (SSABasedGenericKubernetesResourceMatcher .class );
66
64
67
65
66
+ @ SuppressWarnings ("unchecked" )
68
67
public boolean matches (R actual , R desired , Context <?> context ) {
69
- try {
70
- var optionalManagedFieldsEntry =
71
- checkIfFieldManagerExists (actual , context .getControllerConfiguration ().fieldManager ());
72
- // If no field is managed by our controller, that means the controller hasn't touched the
73
- // resource yet and the resource probably doesn't match the desired state. Not matching here
74
- // means that the resource will need to be updated and since this will be done using SSA, the
75
- // fields our controller cares about will become managed by it
76
- if (optionalManagedFieldsEntry .isEmpty ()) {
77
- return false ;
78
- }
68
+ var optionalManagedFieldsEntry =
69
+ checkIfFieldManagerExists (actual , context .getControllerConfiguration ().fieldManager ());
70
+ // If no field is managed by our controller, that means the controller hasn't touched the
71
+ // resource yet and the resource probably doesn't match the desired state. Not matching here
72
+ // means that the resource will need to be updated and since this will be done using SSA, the
73
+ // fields our controller cares about will become managed by it
74
+ if (optionalManagedFieldsEntry .isEmpty ()) {
75
+ return false ;
76
+ }
79
77
80
- var managedFieldsEntry = optionalManagedFieldsEntry .orElseThrow ();
78
+ var managedFieldsEntry = optionalManagedFieldsEntry .orElseThrow ();
81
79
82
- var objectMapper = context .getClient ().getKubernetesSerialization ();
80
+ var objectMapper = context .getClient ().getKubernetesSerialization ();
83
81
84
- var actualMap = objectMapper .convertValue (actual , Map .class );
85
- var desiredMap = objectMapper .convertValue (desired , Map .class );
82
+ var actualMap = objectMapper .convertValue (actual , Map .class );
83
+ var desiredMap = objectMapper .convertValue (desired , Map .class );
86
84
87
- log .trace ("Original actual: \n {} \n original desired: \n {} " , actual , desiredMap );
85
+ log .trace ("Original actual: \n {} \n original desired: \n {} " , actual , desiredMap );
88
86
89
- var prunedActual = new HashMap <String , Object >(actualMap .size ());
90
- keepOnlyManagedFields (prunedActual , actualMap ,
91
- managedFieldsEntry .getFieldsV1 ().getAdditionalProperties (), objectMapper );
87
+ var prunedActual = new HashMap <String , Object >(actualMap .size ());
88
+ keepOnlyManagedFields (prunedActual , actualMap ,
89
+ managedFieldsEntry .getFieldsV1 ().getAdditionalProperties (), objectMapper );
92
90
93
- removeIrrelevantValues (desiredMap );
91
+ removeIrrelevantValues (desiredMap );
94
92
95
- log .debug ("Pruned actual: \n {} \n desired: \n {} " , prunedActual , desiredMap );
93
+ log .debug ("Pruned actual: \n {} \n desired: \n {} " , prunedActual , desiredMap );
96
94
97
- return prunedActual .equals (desiredMap );
98
- } catch (JsonProcessingException e ) {
99
- throw new IllegalStateException (e );
100
- }
95
+ return prunedActual .equals (desiredMap );
101
96
}
102
97
103
98
@ SuppressWarnings ("unchecked" )
@@ -115,8 +110,7 @@ private static void removeIrrelevantValues(Map<String, Object> desiredMap) {
115
110
@ SuppressWarnings ("unchecked" )
116
111
private static void keepOnlyManagedFields (Map <String , Object > result ,
117
112
Map <String , Object > actualMap ,
118
- Map <String , Object > managedFields , KubernetesSerialization objectMapper )
119
- throws JsonProcessingException {
113
+ Map <String , Object > managedFields , KubernetesSerialization objectMapper ) {
120
114
121
115
if (managedFields .isEmpty ()) {
122
116
result .putAll (actualMap );
@@ -157,8 +151,8 @@ private static void keepOnlyManagedFields(Map<String, Object> result,
157
151
@ SuppressWarnings ("unchecked" )
158
152
private static void fillResultsAndTraverseFurther (Map <String , Object > result ,
159
153
Map <String , Object > actualMap , Map <String , Object > managedFields ,
160
- KubernetesSerialization objectMapper ,
161
- String key , String keyInActual , Object managedFieldValue ) throws JsonProcessingException {
154
+ KubernetesSerialization objectMapper , String key , String keyInActual ,
155
+ Object managedFieldValue ) {
162
156
var emptyMapValue = new HashMap <String , Object >();
163
157
result .put (keyInActual , emptyMapValue );
164
158
var actualMapValue = actualMap .get (keyInActual );
@@ -208,11 +202,7 @@ private static void handleListKeyEntrySet(Map<String, Object> result,
208
202
targetValuesByIndex .forEach ((key , value ) -> {
209
203
var emptyResMapValue = new HashMap <String , Object >();
210
204
valueList .add (emptyResMapValue );
211
- try {
212
- keepOnlyManagedFields (emptyResMapValue , value , managedEntryByIndex .get (key ), objectMapper );
213
- } catch (JsonProcessingException ex ) {
214
- throw new IllegalStateException (ex );
215
- }
205
+ keepOnlyManagedFields (emptyResMapValue , value , managedEntryByIndex .get (key ), objectMapper );
216
206
});
217
207
}
218
208
@@ -278,6 +268,7 @@ private static boolean isKeyPrefixedSkippingDotKey(Set<Map.Entry<String, Object>
278
268
return managedFieldEntry .getKey ().startsWith (prefix );
279
269
}
280
270
271
+ @ SuppressWarnings ("unchecked" )
281
272
private static java .util .Map .Entry <Integer , Map <String , Object >> selectListEntryBasedOnKey (
282
273
String key ,
283
274
List <Map <String , Object >> values ,
0 commit comments