Skip to content

Commit 0588dfe

Browse files
authored
fix: remove unneeded Jackson exception reference (#1956)
1 parent f9a6f28 commit 0588dfe

File tree

1 file changed

+26
-35
lines changed

1 file changed

+26
-35
lines changed

Diff for: operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/SSABasedGenericKubernetesResourceMatcher.java

+26-35
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
import io.javaoperatorsdk.operator.OperatorException;
2121
import io.javaoperatorsdk.operator.api.reconciler.Context;
2222

23-
import com.fasterxml.jackson.core.JsonProcessingException;
24-
2523
/**
2624
* Matches the actual state on the server vs the desired state. Based on the managedFields of SSA.
2725
*
@@ -65,39 +63,36 @@ public static <L extends HasMetadata> SSABasedGenericKubernetesResourceMatcher<L
6563
LoggerFactory.getLogger(SSABasedGenericKubernetesResourceMatcher.class);
6664

6765

66+
@SuppressWarnings("unchecked")
6867
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+
}
7977

80-
var managedFieldsEntry = optionalManagedFieldsEntry.orElseThrow();
78+
var managedFieldsEntry = optionalManagedFieldsEntry.orElseThrow();
8179

82-
var objectMapper = context.getClient().getKubernetesSerialization();
80+
var objectMapper = context.getClient().getKubernetesSerialization();
8381

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);
8684

87-
log.trace("Original actual: \n {} \n original desired: \n {} ", actual, desiredMap);
85+
log.trace("Original actual: \n {} \n original desired: \n {} ", actual, desiredMap);
8886

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);
9290

93-
removeIrrelevantValues(desiredMap);
91+
removeIrrelevantValues(desiredMap);
9492

95-
log.debug("Pruned actual: \n {} \n desired: \n {} ", prunedActual, desiredMap);
93+
log.debug("Pruned actual: \n {} \n desired: \n {} ", prunedActual, desiredMap);
9694

97-
return prunedActual.equals(desiredMap);
98-
} catch (JsonProcessingException e) {
99-
throw new IllegalStateException(e);
100-
}
95+
return prunedActual.equals(desiredMap);
10196
}
10297

10398
@SuppressWarnings("unchecked")
@@ -115,8 +110,7 @@ private static void removeIrrelevantValues(Map<String, Object> desiredMap) {
115110
@SuppressWarnings("unchecked")
116111
private static void keepOnlyManagedFields(Map<String, Object> result,
117112
Map<String, Object> actualMap,
118-
Map<String, Object> managedFields, KubernetesSerialization objectMapper)
119-
throws JsonProcessingException {
113+
Map<String, Object> managedFields, KubernetesSerialization objectMapper) {
120114

121115
if (managedFields.isEmpty()) {
122116
result.putAll(actualMap);
@@ -157,8 +151,8 @@ private static void keepOnlyManagedFields(Map<String, Object> result,
157151
@SuppressWarnings("unchecked")
158152
private static void fillResultsAndTraverseFurther(Map<String, Object> result,
159153
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) {
162156
var emptyMapValue = new HashMap<String, Object>();
163157
result.put(keyInActual, emptyMapValue);
164158
var actualMapValue = actualMap.get(keyInActual);
@@ -208,11 +202,7 @@ private static void handleListKeyEntrySet(Map<String, Object> result,
208202
targetValuesByIndex.forEach((key, value) -> {
209203
var emptyResMapValue = new HashMap<String, Object>();
210204
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);
216206
});
217207
}
218208

@@ -278,6 +268,7 @@ private static boolean isKeyPrefixedSkippingDotKey(Set<Map.Entry<String, Object>
278268
return managedFieldEntry.getKey().startsWith(prefix);
279269
}
280270

271+
@SuppressWarnings("unchecked")
281272
private static java.util.Map.Entry<Integer, Map<String, Object>> selectListEntryBasedOnKey(
282273
String key,
283274
List<Map<String, Object>> values,

0 commit comments

Comments
 (0)