Catch throwables and log in StandardPodUtils. Spock test now set additional properties to prevent cert related errors.
This commit is contained in:
@@ -19,12 +19,15 @@ package io.fabric8.spring.cloud.kubernetes;
|
||||
import io.fabric8.kubernetes.api.model.Pod;
|
||||
import io.fabric8.kubernetes.client.Config;
|
||||
import io.fabric8.kubernetes.client.KubernetesClient;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.nio.file.Paths;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class StandardPodUtils implements PodUtils {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(StandardPodUtils.class);
|
||||
public static final String HOSTNAME = "HOSTNAME";
|
||||
|
||||
private final KubernetesClient client;
|
||||
@@ -48,9 +51,14 @@ public class StandardPodUtils implements PodUtils {
|
||||
}
|
||||
|
||||
private synchronized Pod internalGetPod() {
|
||||
if (isServiceAccountFound() && isHostNameEnvVarPresent()) {
|
||||
return client.pods().withName(hostName).get();
|
||||
} else {
|
||||
try {
|
||||
if (isServiceAccountFound() && isHostNameEnvVarPresent()) {
|
||||
return client.pods().withName(hostName).get();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
LOGGER.warn("Failed to get pod with name:[" + hostName + "]. Ignoring.");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,21 +39,21 @@ import spock.lang.Specification
|
||||
@EnableConfigurationProperties
|
||||
class CoreTest extends Specification {
|
||||
|
||||
private static KubernetesMockServer mockServer = new KubernetesMockServer();
|
||||
private static KubernetesClient mockClient;
|
||||
private static KubernetesMockServer mockServer = new KubernetesMockServer()
|
||||
private static KubernetesClient mockClient
|
||||
|
||||
@Autowired
|
||||
Environment environment;
|
||||
Environment environment
|
||||
|
||||
@Autowired(required = false)
|
||||
Config config;
|
||||
Config config
|
||||
|
||||
@Autowired(required = false)
|
||||
KubernetesClient client;
|
||||
KubernetesClient client
|
||||
|
||||
def setupSpec() {
|
||||
mockServer.init();
|
||||
mockClient = mockServer.createClient();
|
||||
mockServer.init()
|
||||
mockClient = mockServer.createClient()
|
||||
|
||||
//Setup configmap data
|
||||
Map<String, String> data = new HashMap<>();
|
||||
@@ -63,8 +63,10 @@ class CoreTest extends Specification {
|
||||
.build()).always()
|
||||
|
||||
//Configure the kubernetes master url to point to the mock server
|
||||
System.setProperty(Config.KUBERNETES_MASTER_SYSTEM_PROPERTY, mockClient.getConfiguration().getMasterUrl());
|
||||
|
||||
System.setProperty(Config.KUBERNETES_MASTER_SYSTEM_PROPERTY, mockClient.getConfiguration().getMasterUrl())
|
||||
System.setProperty(Config.KUBERNETES_TRUST_CERT_SYSTEM_PROPERTY, "true")
|
||||
System.setProperty(Config.KUBERNETES_AUTH_TRYKUBECONFIG_SYSTEM_PROPERTY, "false")
|
||||
System.setProperty(Config.KUBERNETES_AUTH_TRYSERVICEACCOUNT_SYSTEM_PROPERTY, "false")
|
||||
}
|
||||
|
||||
def cleanupSpec() {
|
||||
|
||||
@@ -62,6 +62,9 @@ class RibbonTest extends Specification {
|
||||
|
||||
//Configure the kubernetes master url to point to the mock server
|
||||
System.setProperty(Config.KUBERNETES_MASTER_SYSTEM_PROPERTY, mockClient.getConfiguration().getMasterUrl())
|
||||
System.setProperty(Config.KUBERNETES_TRUST_CERT_SYSTEM_PROPERTY, "true")
|
||||
System.setProperty(Config.KUBERNETES_AUTH_TRYKUBECONFIG_SYSTEM_PROPERTY, "false")
|
||||
System.setProperty(Config.KUBERNETES_AUTH_TRYSERVICEACCOUNT_SYSTEM_PROPERTY, "false")
|
||||
|
||||
//Configured
|
||||
mockServer.expect().get().withPath("/api/v1/namespaces/testns/endpoints/testapp").andReturn(200, new EndpointsBuilder()
|
||||
|
||||
Reference in New Issue
Block a user