Skip to content

Commit

Permalink
use simpler OpenShift support test
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Azores <aazores@redhat.com>
  • Loading branch information
andrewazores committed Feb 22, 2023
1 parent 616abb8 commit fc7c3c6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@
package io.cryostat.platform.internal;

import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ForkJoinPool;
import java.util.function.BiFunction;

import io.cryostat.configuration.Variables;
import io.cryostat.core.log.Logger;
Expand Down Expand Up @@ -89,11 +89,7 @@ public int getPriority() {
public boolean isAvailable() {
logger.trace("Testing {} Availability", getClass().getSimpleName());
try (KubernetesClient client = createClient()) {
String namespace = getOwnNamespace();
if (namespace != null) {
testAvailability();
return true;
}
return testAvailability(client);
} catch (Exception e) {
logger.info(e);
}
Expand All @@ -116,9 +112,12 @@ protected KubernetesClient createClient() {
return new KubernetesClientBuilder().withTaskExecutor(ForkJoinPool.commonPool()).build();
}

protected BiFunction<? extends KubernetesClient, String, ?> testAvailability() {
// ServiceAccount should have sufficient permissions on its own to do this
return (client, ns) -> client.endpoints().inNamespace(ns).list();
@SuppressFBWarnings("DMI_HARDCODED_ABSOLUTE_FILENAME")
protected boolean testAvailability(KubernetesClient client) {
boolean hasNamespace = StringUtils.isNotBlank(getOwnNamespace());
boolean hasSecrets = fs.isDirectory(Path.of("/var/run/secrets/kubernetes.io"));
boolean hasServiceHost = env.hasEnv("KUBERNETES_SERVICE_HOST");
return hasNamespace || hasSecrets || hasServiceHost;
}

@SuppressFBWarnings("DMI_HARDCODED_ABSOLUTE_FILENAME")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,14 @@
*/
package io.cryostat.platform.internal;

import java.util.function.BiFunction;

import io.cryostat.core.log.Logger;
import io.cryostat.core.net.JFRConnectionToolkit;
import io.cryostat.core.sys.Environment;
import io.cryostat.core.sys.FileSystem;
import io.cryostat.net.AuthManager;

import dagger.Lazy;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.openshift.client.OpenShiftClient;

class OpenShiftPlatformStrategy extends KubeApiPlatformStrategy {
Expand All @@ -65,8 +64,8 @@ public int getPriority() {
}

@Override
protected BiFunction<OpenShiftClient, String, ?> testAvailability() {
return (client, ns) -> client.routes().inNamespace(ns).list();
protected boolean testAvailability(KubernetesClient client) {
return super.testAvailability(client) && (((OpenShiftClient) client).isSupported());
}

@Override
Expand Down

0 comments on commit fc7c3c6

Please sign in to comment.