Extract version from deployments (#773)
* Use replaceable version number in deployment yamls
This commit is contained in:
@@ -49,6 +49,19 @@
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>../src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
</build>
|
||||
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>imagename</id>
|
||||
|
||||
@@ -44,6 +44,7 @@ import org.springframework.web.client.RestTemplate;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.awaitility.Awaitility.await;
|
||||
import static org.springframework.cloud.kubernetes.integration.tests.commons.K8SUtils.createApiClient;
|
||||
import static org.springframework.cloud.kubernetes.integration.tests.commons.K8SUtils.getPomVersion;
|
||||
|
||||
/**
|
||||
* @author Ryan Baxter
|
||||
@@ -185,12 +186,18 @@ public class ConfigMapAndSecretIT {
|
||||
private static V1Deployment getConfigK8sClientItDeployment() throws Exception {
|
||||
V1Deployment deployment = (V1Deployment) k8SUtils
|
||||
.readYamlFromClasspath("spring-cloud-kubernetes-client-config-it-deployment.yaml");
|
||||
String image = deployment.getSpec().getTemplate().getSpec().getContainers().get(0).getImage() + ":"
|
||||
+ getPomVersion();
|
||||
deployment.getSpec().getTemplate().getSpec().getContainers().get(0).setImage(image);
|
||||
return deployment;
|
||||
}
|
||||
|
||||
private static V1Deployment getConfigK8sClientItPollingDeployment() throws Exception {
|
||||
V1Deployment deployment = (V1Deployment) k8SUtils
|
||||
.readYamlFromClasspath("spring-cloud-kubernetes-client-config-it-polling-deployment.yaml");
|
||||
String image = deployment.getSpec().getTemplate().getSpec().getContainers().get(0).getImage() + ":"
|
||||
+ getPomVersion();
|
||||
deployment.getSpec().getTemplate().getSpec().getContainers().get(0).setImage(image);
|
||||
return deployment;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ spec:
|
||||
serviceAccountName: spring-cloud-kubernetes-serviceaccount
|
||||
containers:
|
||||
- name: spring-cloud-kubernetes-client-config-it
|
||||
image: docker.io/springcloud/spring-cloud-kubernetes-client-config-it:2.0.3-SNAPSHOT
|
||||
image: docker.io/springcloud/spring-cloud-kubernetes-client-config-it
|
||||
imagePullPolicy: IfNotPresent
|
||||
readinessProbe:
|
||||
httpGet:
|
||||
|
||||
@@ -14,7 +14,7 @@ spec:
|
||||
serviceAccountName: spring-cloud-kubernetes-serviceaccount
|
||||
containers:
|
||||
- name: spring-cloud-kubernetes-client-config-it
|
||||
image: docker.io/springcloud/spring-cloud-kubernetes-client-config-it:2.0.3-SNAPSHOT
|
||||
image: docker.io/springcloud/spring-cloud-kubernetes-client-config-it
|
||||
imagePullPolicy: IfNotPresent
|
||||
readinessProbe:
|
||||
httpGet:
|
||||
|
||||
@@ -50,6 +50,19 @@
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>../src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
</build>
|
||||
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>skaffold</id>
|
||||
|
||||
@@ -43,6 +43,7 @@ import org.springframework.web.client.RestTemplate;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.awaitility.Awaitility.await;
|
||||
import static org.springframework.cloud.kubernetes.integration.tests.commons.K8SUtils.createApiClient;
|
||||
import static org.springframework.cloud.kubernetes.integration.tests.commons.K8SUtils.getPomVersion;
|
||||
|
||||
/**
|
||||
* @author Ryan Baxter
|
||||
@@ -187,12 +188,18 @@ public class LoadBalancerIT {
|
||||
private V1Deployment getLoadbalancerServiceItDeployment() throws Exception {
|
||||
V1Deployment deployment = (V1Deployment) k8SUtils
|
||||
.readYamlFromClasspath("spring-cloud-kubernetes-client-loadbalancer-service-it-deployment.yaml");
|
||||
String image = deployment.getSpec().getTemplate().getSpec().getContainers().get(0).getImage() + ":"
|
||||
+ getPomVersion();
|
||||
deployment.getSpec().getTemplate().getSpec().getContainers().get(0).setImage(image);
|
||||
return deployment;
|
||||
}
|
||||
|
||||
private V1Deployment getLoadbalancerPodItDeployment() throws Exception {
|
||||
V1Deployment deployment = (V1Deployment) k8SUtils
|
||||
.readYamlFromClasspath("spring-cloud-kubernetes-client-loadbalancer-service-it-deployment.yaml");
|
||||
String image = deployment.getSpec().getTemplate().getSpec().getContainers().get(0).getImage() + ":"
|
||||
+ getPomVersion();
|
||||
deployment.getSpec().getTemplate().getSpec().getContainers().get(0).setImage(image);
|
||||
return deployment;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ spec:
|
||||
env:
|
||||
- name: SPRING_CLOUD_KUBERNETES_LOADBALANCER_MODE
|
||||
value: POD
|
||||
image: docker.io/springcloud/spring-cloud-kubernetes-client-loadbalancer-it:2.0.3-SNAPSHOT
|
||||
image: docker.io/springcloud/spring-cloud-kubernetes-client-loadbalancer-it
|
||||
imagePullPolicy: IfNotPresent
|
||||
readinessProbe:
|
||||
httpGet:
|
||||
|
||||
@@ -17,7 +17,7 @@ spec:
|
||||
env:
|
||||
- name: SPRING_CLOUD_KUBERNETES_LOADBALANCER_MODE
|
||||
value: SERVICE
|
||||
image: docker.io/springcloud/spring-cloud-kubernetes-client-loadbalancer-it:2.0.3-SNAPSHOT
|
||||
image: docker.io/springcloud/spring-cloud-kubernetes-client-loadbalancer-it
|
||||
imagePullPolicy: IfNotPresent
|
||||
readinessProbe:
|
||||
httpGet:
|
||||
|
||||
@@ -49,6 +49,19 @@
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>../src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
</build>
|
||||
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>skaffold</id>
|
||||
|
||||
@@ -44,6 +44,7 @@ import org.springframework.web.client.RestTemplate;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.awaitility.Awaitility.await;
|
||||
import static org.springframework.cloud.kubernetes.integration.tests.commons.K8SUtils.createApiClient;
|
||||
import static org.springframework.cloud.kubernetes.integration.tests.commons.K8SUtils.getPomVersion;
|
||||
|
||||
/**
|
||||
* @author Ryan Baxter
|
||||
@@ -193,6 +194,9 @@ public class ReactiveDiscoveryClientIT {
|
||||
private V1Deployment getReactiveDiscoveryItDeployment() throws Exception {
|
||||
V1Deployment deployment = (V1Deployment) k8SUtils
|
||||
.readYamlFromClasspath("spring-cloud-kubernetes-client-reactive-discovery-it-deployment.yaml");
|
||||
String image = deployment.getSpec().getTemplate().getSpec().getContainers().get(0).getImage() + ":"
|
||||
+ getPomVersion();
|
||||
deployment.getSpec().getTemplate().getSpec().getContainers().get(0).setImage(image);
|
||||
return deployment;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ spec:
|
||||
serviceAccountName: spring-cloud-kubernetes-serviceaccount
|
||||
containers:
|
||||
- name: spring-cloud-kubernetes-client-reactive-discovery-it
|
||||
image: docker.io/springcloud/spring-cloud-kubernetes-client-reactive-discovery-client-it:2.0.3-SNAPSHOT
|
||||
image: docker.io/springcloud/spring-cloud-kubernetes-client-reactive-discovery-client-it
|
||||
imagePullPolicy: IfNotPresent
|
||||
readinessProbe:
|
||||
httpGet:
|
||||
|
||||
@@ -76,4 +76,17 @@
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>../src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
|
||||
@@ -46,6 +46,7 @@ import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
|
||||
import static com.github.tomakehurst.wiremock.client.WireMock.verify;
|
||||
import static org.awaitility.Awaitility.await;
|
||||
import static org.springframework.cloud.kubernetes.integration.tests.commons.K8SUtils.createApiClient;
|
||||
import static org.springframework.cloud.kubernetes.integration.tests.commons.K8SUtils.getPomVersion;
|
||||
|
||||
/**
|
||||
* @author Ryan Baxter
|
||||
@@ -179,6 +180,9 @@ public class ActuatorRefreshIT {
|
||||
private V1Deployment getConfigWatcherDeployment() throws Exception {
|
||||
V1Deployment deployment = (V1Deployment) k8SUtils
|
||||
.readYamlFromClasspath("spring-cloud-kubernetes-configuration-watcher-http-deployment.yaml");
|
||||
String image = deployment.getSpec().getTemplate().getSpec().getContainers().get(0).getImage() + ":"
|
||||
+ getPomVersion();
|
||||
deployment.getSpec().getTemplate().getSpec().getContainers().get(0).setImage(image);
|
||||
return deployment;
|
||||
}
|
||||
|
||||
|
||||
@@ -45,6 +45,7 @@ import org.springframework.web.client.RestTemplate;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.awaitility.Awaitility.await;
|
||||
import static org.springframework.cloud.kubernetes.integration.tests.commons.K8SUtils.createApiClient;
|
||||
import static org.springframework.cloud.kubernetes.integration.tests.commons.K8SUtils.getPomVersion;
|
||||
|
||||
/**
|
||||
* @author Kris Iyer
|
||||
@@ -212,6 +213,9 @@ public class ActuatorRefreshKafkaIT {
|
||||
private V1Deployment getConfigWatcherDeployment() throws Exception {
|
||||
V1Deployment deployment = (V1Deployment) k8SUtils
|
||||
.readYamlFromClasspath("spring-cloud-kubernetes-configuration-watcher-bus-kafka-deployment.yaml");
|
||||
String image = deployment.getSpec().getTemplate().getSpec().getContainers().get(0).getImage() + ":"
|
||||
+ getPomVersion();
|
||||
deployment.getSpec().getTemplate().getSpec().getContainers().get(0).setImage(image);
|
||||
return deployment;
|
||||
}
|
||||
|
||||
@@ -224,6 +228,9 @@ public class ActuatorRefreshKafkaIT {
|
||||
private V1Deployment getItDeployment() throws Exception {
|
||||
String urlString = "spring-cloud-kubernetes-configuration-watcher-it-bus-kafka-deployment.yaml";
|
||||
V1Deployment deployment = (V1Deployment) k8SUtils.readYamlFromClasspath(urlString);
|
||||
String image = deployment.getSpec().getTemplate().getSpec().getContainers().get(0).getImage() + ":"
|
||||
+ getPomVersion();
|
||||
deployment.getSpec().getTemplate().getSpec().getContainers().get(0).setImage(image);
|
||||
return deployment;
|
||||
}
|
||||
|
||||
|
||||
@@ -46,6 +46,7 @@ import org.springframework.web.client.RestTemplate;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.awaitility.Awaitility.await;
|
||||
import static org.springframework.cloud.kubernetes.integration.tests.commons.K8SUtils.createApiClient;
|
||||
import static org.springframework.cloud.kubernetes.integration.tests.commons.K8SUtils.getPomVersion;
|
||||
|
||||
/**
|
||||
* @author Ryan Baxter
|
||||
@@ -204,6 +205,9 @@ public class ActuatorRefreshRabbitMQIT {
|
||||
private V1Deployment getConfigWatcherDeployment() throws Exception {
|
||||
V1Deployment deployment = (V1Deployment) k8SUtils
|
||||
.readYamlFromClasspath("spring-cloud-kubernetes-configuration-watcher-bus-amqp-deployment.yaml");
|
||||
String image = deployment.getSpec().getTemplate().getSpec().getContainers().get(0).getImage() + ":"
|
||||
+ getPomVersion();
|
||||
deployment.getSpec().getTemplate().getSpec().getContainers().get(0).setImage(image);
|
||||
return deployment;
|
||||
}
|
||||
|
||||
@@ -216,6 +220,9 @@ public class ActuatorRefreshRabbitMQIT {
|
||||
private V1Deployment getItDeployment() throws Exception {
|
||||
String urlString = "spring-cloud-kubernetes-configuration-watcher-it-bus-amqp-deployment.yaml";
|
||||
V1Deployment deployment = (V1Deployment) k8SUtils.readYamlFromClasspath(urlString);
|
||||
String image = deployment.getSpec().getTemplate().getSpec().getContainers().get(0).getImage() + ":"
|
||||
+ getPomVersion();
|
||||
deployment.getSpec().getTemplate().getSpec().getContainers().get(0).setImage(image);
|
||||
return deployment;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ spec:
|
||||
serviceAccountName: spring-cloud-kubernetes-serviceaccount
|
||||
containers:
|
||||
- name: spring-cloud-kubernetes-configuration-watcher
|
||||
image: docker.io/springcloud/spring-cloud-kubernetes-configuration-watcher:2.0.3-SNAPSHOT
|
||||
image: docker.io/springcloud/spring-cloud-kubernetes-configuration-watcher
|
||||
imagePullPolicy: IfNotPresent
|
||||
env:
|
||||
- name: SPRING_PROFILES_ACTIVE
|
||||
|
||||
@@ -14,7 +14,7 @@ spec:
|
||||
serviceAccountName: spring-cloud-kubernetes-serviceaccount
|
||||
containers:
|
||||
- name: spring-cloud-kubernetes-configuration-watcher
|
||||
image: docker.io/springcloud/spring-cloud-kubernetes-configuration-watcher:2.0.3-SNAPSHOT
|
||||
image: docker.io/springcloud/spring-cloud-kubernetes-configuration-watcher
|
||||
imagePullPolicy: IfNotPresent
|
||||
env:
|
||||
- name: SPRING_PROFILES_ACTIVE
|
||||
|
||||
@@ -14,7 +14,7 @@ spec:
|
||||
serviceAccountName: spring-cloud-kubernetes-serviceaccount
|
||||
containers:
|
||||
- name: spring-cloud-kubernetes-configuration-watcher
|
||||
image: docker.io/springcloud/spring-cloud-kubernetes-configuration-watcher:2.0.3-SNAPSHOT
|
||||
image: docker.io/springcloud/spring-cloud-kubernetes-configuration-watcher
|
||||
imagePullPolicy: IfNotPresent
|
||||
readinessProbe:
|
||||
httpGet:
|
||||
|
||||
@@ -13,7 +13,7 @@ spec:
|
||||
spec:
|
||||
containers:
|
||||
- name: spring-cloud-kubernetes-configuration-watcher-it
|
||||
image: docker.io/springcloud/spring-cloud-kubernetes-configuration-watcher-it:2.0.3-SNAPSHOT
|
||||
image: docker.io/springcloud/spring-cloud-kubernetes-configuration-watcher-it
|
||||
imagePullPolicy: IfNotPresent
|
||||
env:
|
||||
- name: SPRING_PROFILES_ACTIVE
|
||||
|
||||
@@ -13,7 +13,7 @@ spec:
|
||||
spec:
|
||||
containers:
|
||||
- name: spring-cloud-kubernetes-configuration-watcher-it
|
||||
image: docker.io/springcloud/spring-cloud-kubernetes-configuration-watcher-it:2.0.3-SNAPSHOT
|
||||
image: docker.io/springcloud/spring-cloud-kubernetes-configuration-watcher-it
|
||||
imagePullPolicy: IfNotPresent
|
||||
env:
|
||||
- name: SPRING_PROFILES_ACTIVE
|
||||
|
||||
@@ -48,6 +48,18 @@
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
<build>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>../src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
</build>
|
||||
|
||||
<profiles>
|
||||
<profile>
|
||||
|
||||
@@ -44,6 +44,7 @@ import org.springframework.web.client.RestTemplate;
|
||||
import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
|
||||
import static org.awaitility.Awaitility.await;
|
||||
import static org.springframework.cloud.kubernetes.integration.tests.commons.K8SUtils.createApiClient;
|
||||
import static org.springframework.cloud.kubernetes.integration.tests.commons.K8SUtils.getPomVersion;
|
||||
|
||||
/**
|
||||
* @author Ryan Baxter
|
||||
@@ -94,6 +95,9 @@ public class ActuatorEndpointIT {
|
||||
private static V1Deployment getCoreK8sClientItDeployment() throws Exception {
|
||||
V1Deployment deployment = (V1Deployment) k8SUtils
|
||||
.readYamlFromClasspath("spring-cloud-kubernetes-core-k8s-client-it-deployment.yaml");
|
||||
String image = deployment.getSpec().getTemplate().getSpec().getContainers().get(0).getImage() + ":"
|
||||
+ getPomVersion();
|
||||
deployment.getSpec().getTemplate().getSpec().getContainers().get(0).setImage(image);
|
||||
return deployment;
|
||||
}
|
||||
|
||||
@@ -134,7 +138,8 @@ public class ActuatorEndpointIT {
|
||||
await().timeout(Duration.ofSeconds(60))
|
||||
.until(() -> rest.getForEntity("http://localhost:80/core-k8s-client-it/actuator/health", String.class)
|
||||
.getStatusCode().is2xxSuccessful());
|
||||
|
||||
LOG.debug("Response from /health endpoint: "
|
||||
+ rest.getForEntity("http://localhost:80/core-k8s-client-it/actuator/health", String.class));
|
||||
Map<String, Object> health = rest.getForObject("http://localhost:80/core-k8s-client-it/actuator/health",
|
||||
Map.class);
|
||||
Map<String, Object> components = (Map) health.get("components");
|
||||
@@ -181,7 +186,8 @@ public class ActuatorEndpointIT {
|
||||
await().timeout(Duration.ofSeconds(60))
|
||||
.until(() -> rest.getForEntity("http://localhost:80/core-k8s-client-it/actuator/info", String.class)
|
||||
.getStatusCode().is2xxSuccessful());
|
||||
|
||||
LOG.debug("Response from /info endpoint: "
|
||||
+ rest.getForEntity("http://localhost:80/core-k8s-client-it/actuator/info", String.class));
|
||||
Map<String, Object> info = rest.getForObject("http://localhost:80/core-k8s-client-it/actuator/info", Map.class);
|
||||
Map<String, Object> kubernetes = (Map) info.get("kubernetes");
|
||||
assertThat(kubernetes.containsKey("hostIp")).isTrue();
|
||||
|
||||
@@ -14,7 +14,7 @@ spec:
|
||||
serviceAccountName: spring-cloud-kubernetes-serviceaccount
|
||||
containers:
|
||||
- name: spring-cloud-kubernetes-core-k8s-client-it
|
||||
image: docker.io/springcloud/spring-cloud-kubernetes-core-k8s-client-it:2.0.3-SNAPSHOT
|
||||
image: docker.io/springcloud/spring-cloud-kubernetes-core-k8s-client-it
|
||||
imagePullPolicy: IfNotPresent
|
||||
readinessProbe:
|
||||
httpGet:
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
@project.version@
|
||||
@@ -19,9 +19,11 @@ package org.springframework.cloud.kubernetes.integration.tests.commons;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.Duration;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
@@ -47,6 +49,11 @@ import io.kubernetes.client.util.Yaml;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
import org.springframework.util.StreamUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import static org.awaitility.Awaitility.await;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
@@ -55,6 +62,8 @@ import static org.junit.Assert.fail;
|
||||
*/
|
||||
public class K8SUtils {
|
||||
|
||||
private static final String KUBERNETES_VERSION_FILE = "META-INF/springcloudkubernetes-version.txt";
|
||||
|
||||
private Log log = LogFactory.getLog(getClass());
|
||||
|
||||
private CoreV1Api api;
|
||||
@@ -65,6 +74,21 @@ public class K8SUtils {
|
||||
return createApiClient(false, Duration.ofSeconds(15));
|
||||
}
|
||||
|
||||
public static String getPomVersion() {
|
||||
try (InputStream in = new ClassPathResource(KUBERNETES_VERSION_FILE).getInputStream()) {
|
||||
String version = StreamUtils.copyToString(in, StandardCharsets.UTF_8);
|
||||
if (StringUtils.hasText(version)) {
|
||||
version = version.trim();
|
||||
}
|
||||
return version;
|
||||
}
|
||||
catch (IOException e) {
|
||||
ReflectionUtils.rethrowRuntimeException(e);
|
||||
}
|
||||
// not reachable since exception rethrown at runtime
|
||||
return null;
|
||||
}
|
||||
|
||||
public static ApiClient createApiClient(boolean debug, Duration readTimeout) throws IOException {
|
||||
ApiClient client = Config.defaultClient();
|
||||
client.setHttpClient(client.getHttpClient().newBuilder().readTimeout(readTimeout).build());
|
||||
|
||||
Reference in New Issue
Block a user