Skip to content

Commit

Permalink
fix(kubernetes): Fix log message when checking readable kinds (#4000)
Browse files Browse the repository at this point in the history
We're now logging the KubernetesKindProperties which doesn't have
a nice string representation, so is not helpful in the logs.

While fixing the log, it's actually easier if canReadKind just
takes in the KubernetesKind and looks up the properties in the
registry itself.
  • Loading branch information
ezimanyi authored and ethanfrogers committed Sep 4, 2019
1 parent f84bee5 commit 6650178
Showing 1 changed file with 6 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import java.nio.file.Paths;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import javax.annotation.Nonnull;
Expand Down Expand Up @@ -424,12 +425,9 @@ private void determineOmitKinds() {
.filter(Objects::nonNull)
.filter(k -> !k.equals(KubernetesKind.NONE))
.filter(k -> !omitKindsComputed.containsKey(k))
.map(kindRegistry::getRegisteredKind)
.filter(k -> !canReadKind(k, checkNamespace))
.collect(
Collectors.toConcurrentMap(
KubernetesKindProperties::getKubernetesKind,
k -> InvalidKindReason.READ_ERROR));
Collectors.toConcurrentMap(Function.identity(), k -> InvalidKindReason.READ_ERROR));
long endTime = System.nanoTime();
long duration = (endTime - startTime) / 1000000;
log.info("determineOmitKinds for account {} took {} ms", accountName, duration);
Expand All @@ -450,15 +448,13 @@ private void determineOmitKinds() {
}
}

private boolean canReadKind(KubernetesKindProperties kind, String checkNamespace) {
private boolean canReadKind(KubernetesKind kind, String checkNamespace) {
log.info("Checking if {} is readable in account '{}'...", kind, accountName);
boolean allowed;
if (kind.isNamespaced()) {
allowed =
jobExecutor.authCanINamespaced(
this, checkNamespace, kind.getKubernetesKind().getName(), "list");
if (kindRegistry.getRegisteredKind(kind).isNamespaced()) {
allowed = jobExecutor.authCanINamespaced(this, checkNamespace, kind.getName(), "list");
} else {
allowed = jobExecutor.authCanI(this, kind.getKubernetesKind().getName(), "list");
allowed = jobExecutor.authCanI(this, kind.getName(), "list");
}

if (!allowed) {
Expand Down

0 comments on commit 6650178

Please sign in to comment.