Skip to content
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

fix: do not log sensitive resources #2003

Merged
merged 1 commit into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
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
@@ -0,0 +1,14 @@
package io.javaoperatorsdk.operator.processing;

import io.fabric8.kubernetes.api.model.HasMetadata;
import io.fabric8.kubernetes.api.model.Secret;

public class LoggingUtils {

private LoggingUtils() {}

public static boolean isNotSensitiveResource(HasMetadata resource) {
return !(resource instanceof Secret);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import io.fabric8.kubernetes.client.utils.KubernetesSerialization;
import io.javaoperatorsdk.operator.OperatorException;
import io.javaoperatorsdk.operator.api.reconciler.Context;
import io.javaoperatorsdk.operator.processing.LoggingUtils;

/**
* Matches the actual state on the server vs the desired state. Based on the managedFields of SSA.
Expand Down Expand Up @@ -81,16 +82,19 @@ public boolean matches(R actual, R desired, Context<?> context) {

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);
if (LoggingUtils.isNotSensitiveResource(desired)) {
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);

removeIrrelevantValues(desiredMap);

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

return prunedActual.equals(desiredMap);
}
Expand Down
Loading