Catch throwables and log in StandardPodUtils. Spock test now set additional properties to prevent cert related errors.

This commit is contained in:
Ioannis Canellos
2016-04-28 23:56:13 +03:00
parent 715300e4b8
commit 5904fa0b27
3 changed files with 25 additions and 12 deletions

View File

@@ -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;
}
}

View File

@@ -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() {

View File

@@ -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()