Skip to content

fix: remove unneeded Jackson exception reference #1956

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
import io.javaoperatorsdk.operator.OperatorException;
import io.javaoperatorsdk.operator.api.reconciler.Context;

import com.fasterxml.jackson.core.JsonProcessingException;

/**
* Matches the actual state on the server vs the desired state. Based on the managedFields of SSA.
*
Expand Down Expand Up @@ -65,39 +63,36 @@ public static <L extends HasMetadata> SSABasedGenericKubernetesResourceMatcher<L
LoggerFactory.getLogger(SSABasedGenericKubernetesResourceMatcher.class);


@SuppressWarnings("unchecked")
public boolean matches(R actual, R desired, Context<?> context) {
try {
var optionalManagedFieldsEntry =
checkIfFieldManagerExists(actual, context.getControllerConfiguration().fieldManager());
// If no field is managed by our controller, that means the controller hasn't touched the
// resource yet and the resource probably doesn't match the desired state. Not matching here
// means that the resource will need to be updated and since this will be done using SSA, the
// fields our controller cares about will become managed by it
if (optionalManagedFieldsEntry.isEmpty()) {
return false;
}
var optionalManagedFieldsEntry =
checkIfFieldManagerExists(actual, context.getControllerConfiguration().fieldManager());
// If no field is managed by our controller, that means the controller hasn't touched the
// resource yet and the resource probably doesn't match the desired state. Not matching here
// means that the resource will need to be updated and since this will be done using SSA, the
// fields our controller cares about will become managed by it
if (optionalManagedFieldsEntry.isEmpty()) {
return false;
}

var managedFieldsEntry = optionalManagedFieldsEntry.orElseThrow();
var managedFieldsEntry = optionalManagedFieldsEntry.orElseThrow();

var objectMapper = context.getClient().getKubernetesSerialization();
var objectMapper = context.getClient().getKubernetesSerialization();

var actualMap = objectMapper.convertValue(actual, Map.class);
var desiredMap = objectMapper.convertValue(desired, Map.class);
var actualMap = objectMapper.convertValue(actual, Map.class);
var desiredMap = objectMapper.convertValue(desired, Map.class);

log.trace("Original actual: \n {} \n original desired: \n {} ", actual, desiredMap);
log.trace("Original actual: \n {} \n original desired: \n {} ", actual, desiredMap);

var prunedActual = new HashMap<String, Object>(actualMap.size());
keepOnlyManagedFields(prunedActual, actualMap,
managedFieldsEntry.getFieldsV1().getAdditionalProperties(), objectMapper);
var prunedActual = new HashMap<String, Object>(actualMap.size());
keepOnlyManagedFields(prunedActual, actualMap,
managedFieldsEntry.getFieldsV1().getAdditionalProperties(), objectMapper);

removeIrrelevantValues(desiredMap);
removeIrrelevantValues(desiredMap);

log.debug("Pruned actual: \n {} \n desired: \n {} ", prunedActual, desiredMap);
log.debug("Pruned actual: \n {} \n desired: \n {} ", prunedActual, desiredMap);

return prunedActual.equals(desiredMap);
} catch (JsonProcessingException e) {
throw new IllegalStateException(e);
}
return prunedActual.equals(desiredMap);
}

@SuppressWarnings("unchecked")
Expand All @@ -115,8 +110,7 @@ private static void removeIrrelevantValues(Map<String, Object> desiredMap) {
@SuppressWarnings("unchecked")
private static void keepOnlyManagedFields(Map<String, Object> result,
Map<String, Object> actualMap,
Map<String, Object> managedFields, KubernetesSerialization objectMapper)
throws JsonProcessingException {
Map<String, Object> managedFields, KubernetesSerialization objectMapper) {

if (managedFields.isEmpty()) {
result.putAll(actualMap);
Expand Down Expand Up @@ -157,8 +151,8 @@ private static void keepOnlyManagedFields(Map<String, Object> result,
@SuppressWarnings("unchecked")
private static void fillResultsAndTraverseFurther(Map<String, Object> result,
Map<String, Object> actualMap, Map<String, Object> managedFields,
KubernetesSerialization objectMapper,
String key, String keyInActual, Object managedFieldValue) throws JsonProcessingException {
KubernetesSerialization objectMapper, String key, String keyInActual,
Object managedFieldValue) {
var emptyMapValue = new HashMap<String, Object>();
result.put(keyInActual, emptyMapValue);
var actualMapValue = actualMap.get(keyInActual);
Expand Down Expand Up @@ -208,11 +202,7 @@ private static void handleListKeyEntrySet(Map<String, Object> result,
targetValuesByIndex.forEach((key, value) -> {
var emptyResMapValue = new HashMap<String, Object>();
valueList.add(emptyResMapValue);
try {
keepOnlyManagedFields(emptyResMapValue, value, managedEntryByIndex.get(key), objectMapper);
} catch (JsonProcessingException ex) {
throw new IllegalStateException(ex);
}
keepOnlyManagedFields(emptyResMapValue, value, managedEntryByIndex.get(key), objectMapper);
});
}

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

@SuppressWarnings("unchecked")
private static java.util.Map.Entry<Integer, Map<String, Object>> selectListEntryBasedOnKey(
String key,
List<Map<String, Object>> values,
Expand Down