Merge branch '3.0.x'

This commit is contained in:
Ryan Baxter
2023-09-19 08:39:59 -04:00
12 changed files with 62 additions and 375 deletions

View File

@@ -58,7 +58,6 @@
<module>spring-cloud-kubernetes-discoveryclient-it</module>
<module>spring-cloud-kubernetes-client-loadbalancer-it</module>
<module>spring-cloud-kubernetes-configuration-watcher-it</module>
<module>spring-cloud-kubernetes-core-k8s-client-it</module>
<module>spring-cloud-kubernetes-client-event-and-polling-reload</module>
<module>spring-cloud-kubernetes-client-configmap-event-reload-multiple-apps</module>
<module>spring-cloud-kubernetes-client-secrets-event-reload-multiple-apps</module>

View File

@@ -308,7 +308,7 @@ class KubernetesClientDiscoveryClientIT {
// patch the deployment to change what namespaces are take into account
KubernetesClientDiscoveryClientUtils.patchForTwoNamespacesMatchViaThePredicate(DEPLOYMENT_NAME, NAMESPACE);
new KubernetesClientDiscoveryFilterITDelegate().filterMatchesBothNamespacesViaThePredicate(util);
new KubernetesClientDiscoveryFilterITDelegate().filterMatchesBothNamespacesViaThePredicate();
}
@Test
@@ -339,7 +339,7 @@ class KubernetesClientDiscoveryClientIT {
KubernetesClientDiscoveryClientUtils.patchForBlockingAndReactiveHealth(DEPLOYMENT_NAME, NAMESPACE);
new KubernetesClientDiscoveryHealthITDelegate().testDefaultConfiguration(util, K3S);
new KubernetesClientDiscoveryHealthITDelegate().testDefaultConfiguration(K3S);
}
private void deleteNamespacesAndWiremock() {

View File

@@ -95,7 +95,7 @@ class KubernetesClientDiscoveryFilterITDelegate {
* As such, both services are found via 'getInstances' call.
* </pre>
*/
void filterMatchesBothNamespacesViaThePredicate(Util util) {
void filterMatchesBothNamespacesViaThePredicate() {
// patch the deployment to change what namespaces are take into account
KubernetesClientDiscoveryClientUtils.patchForTwoNamespacesMatchViaThePredicate(DEPLOYMENT_NAME, NAMESPACE);

View File

@@ -29,7 +29,6 @@ import reactor.util.retry.Retry;
import reactor.util.retry.RetryBackoffSpec;
import org.springframework.boot.test.json.BasicJsonTester;
import org.springframework.cloud.kubernetes.integration.tests.commons.native_client.Util;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpMethod;
import org.springframework.http.client.reactive.ReactorClientHttpConnector;
@@ -142,7 +141,7 @@ class KubernetesClientDiscoveryHealthITDelegate {
/**
* Both blocking and reactive are enabled.
*/
void testDefaultConfiguration(Util util, K3sContainer container) {
void testDefaultConfiguration(K3sContainer container) {
KubernetesClientDiscoveryClientUtils.patchForBlockingAndReactiveHealth(DEPLOYMENT_NAME, NAMESPACE);
@@ -153,9 +152,12 @@ class KubernetesClientDiscoveryHealthITDelegate {
"received InstanceRegisteredEvent from pod with 'app' label value : spring-cloud-kubernetes-client-discovery-it");
WebClient healthClient = builder().baseUrl("http://localhost/actuator/health").build();
WebClient infoClient = builder().baseUrl("http://localhost/actuator/info").build();
String healthResult = healthClient.method(HttpMethod.GET).retrieve().bodyToMono(String.class)
.retryWhen(retrySpec()).block();
String infoResult = infoClient.method(HttpMethod.GET).retrieve().bodyToMono(String.class)
.retryWhen(retrySpec()).block();
Assertions.assertThat(BASIC_JSON_TESTER.from(healthResult))
.extractingJsonPathStringValue("$.components.discoveryComposite.status").isEqualTo("UP");
@@ -180,6 +182,61 @@ class KubernetesClientDiscoveryHealthITDelegate {
"$.components.reactiveDiscoveryClients.components.['Kubernetes Reactive Discovery Client'].details.services")
.containsExactlyInAnyOrder("spring-cloud-kubernetes-client-discovery-it", "kubernetes");
// assert health/info also
assertHealth(healthResult);
assertInfo(infoResult);
}
private void assertHealth(String healthResult) {
Assertions.assertThat(BASIC_JSON_TESTER.from(healthResult)).extractingJsonPathStringValue(
"$.components.kubernetes.status").isEqualTo("UP");
Assertions.assertThat(BASIC_JSON_TESTER.from(healthResult)).extractingJsonPathStringValue(
"$.components.kubernetes.details.hostIp").isNotEmpty();
Assertions.assertThat(BASIC_JSON_TESTER.from(healthResult)).extractingJsonPathBooleanValue(
"$.components.kubernetes.details.inside").isEqualTo(true);
Assertions.assertThat(BASIC_JSON_TESTER.from(healthResult)).extractingJsonPathStringValue(
"$.components.kubernetes.details.labels.app").isEqualTo("spring-cloud-kubernetes-client-discovery-it");
Assertions.assertThat(BASIC_JSON_TESTER.from(healthResult)).extractingJsonPathStringValue(
"$.components.kubernetes.details.namespace").isNotEmpty();
Assertions.assertThat(BASIC_JSON_TESTER.from(healthResult)).extractingJsonPathStringValue(
"$.components.kubernetes.details.nodeName").isNotEmpty();
Assertions.assertThat(BASIC_JSON_TESTER.from(healthResult)).extractingJsonPathStringValue(
"$.components.kubernetes.details.podIp").isNotEmpty();
Assertions.assertThat(BASIC_JSON_TESTER.from(healthResult)).extractingJsonPathStringValue(
"$.components.kubernetes.details.podName").isNotEmpty();
Assertions.assertThat(BASIC_JSON_TESTER.from(healthResult)).extractingJsonPathStringValue(
"$.components.kubernetes.details.serviceAccount").isNotEmpty();
}
private void assertInfo(String infoResult) {
Assertions.assertThat(BASIC_JSON_TESTER.from(infoResult)).extractingJsonPathStringValue(
"$.kubernetes.hostIp").isNotEmpty();
Assertions.assertThat(BASIC_JSON_TESTER.from(infoResult)).extractingJsonPathBooleanValue(
"$.kubernetes.inside").isEqualTo(true);
Assertions.assertThat(BASIC_JSON_TESTER.from(infoResult)).extractingJsonPathStringValue(
"$.kubernetes.namespace").isNotEmpty();
Assertions.assertThat(BASIC_JSON_TESTER.from(infoResult)).extractingJsonPathStringValue(
"$.kubernetes.nodeName").isNotEmpty();
Assertions.assertThat(BASIC_JSON_TESTER.from(infoResult)).extractingJsonPathStringValue(
"$.kubernetes.podIp").isNotEmpty();
Assertions.assertThat(BASIC_JSON_TESTER.from(infoResult)).extractingJsonPathStringValue(
"$.kubernetes.podName").isNotEmpty();
Assertions.assertThat(BASIC_JSON_TESTER.from(infoResult)).extractingJsonPathStringValue(
"$.kubernetes.serviceAccount").isNotEmpty();
}
private WebClient.Builder builder() {

View File

@@ -1,105 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-kubernetes-integration-tests</artifactId>
<version>3.1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>spring-cloud-kubernetes-core-k8s-client-it</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-kubernetes-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-kubernetes-test-support</artifactId>
</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>
<plugins>
<!-- build image in the 'package' phase, and ignore plain tests -->
<!-- via maven-surefire-plugin::skipTests -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<imageName>docker.io/springcloud/${project.artifactId}:${project.version}</imageName>
</configuration>
<executions>
<execution>
<id>build-image</id>
<configuration>
<skip>${skip.build.image}</skip>
</configuration>
<phase>package</phase>
<goals>
<goal>build-image</goal>
</goals>
</execution>
<execution>
<id>repackage</id>
<phase>package</phase>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- ignore plain tests (in the 'test' phase), so that we could build the image first, see above -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
<!-- run tests in the 'integration-tests' phase, one that is after 'package' (where we build the image) -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
</executions>
<configuration>
<includes>
<include>${testsToRun}</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@@ -1,32 +0,0 @@
/*
* Copyright 2013-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.kubernetes.core.k8s.it;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* @author Ryan Baxter
*/
@SpringBootApplication
public class CoreK8SApplicationIt {
public static void main(String[] args) {
SpringApplication.run(CoreK8SApplicationIt.class, args);
}
}

View File

@@ -1,8 +0,0 @@
management:
endpoint:
health:
show-details: always
endpoints:
web:
exposure:
include: "*"

View File

@@ -1,152 +0,0 @@
/*
* Copyright 2013-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.kubernetes.core.k8s.it;
import java.time.Duration;
import java.util.Map;
import java.util.Objects;
import io.kubernetes.client.openapi.models.V1Deployment;
import io.kubernetes.client.openapi.models.V1Ingress;
import io.kubernetes.client.openapi.models.V1Service;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.testcontainers.k3s.K3sContainer;
import reactor.netty.http.client.HttpClient;
import reactor.util.retry.Retry;
import reactor.util.retry.RetryBackoffSpec;
import org.springframework.cloud.kubernetes.integration.tests.commons.Commons;
import org.springframework.cloud.kubernetes.integration.tests.commons.Phase;
import org.springframework.cloud.kubernetes.integration.tests.commons.native_client.Util;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.core.ResolvableType;
import org.springframework.http.HttpMethod;
import org.springframework.http.client.reactive.ReactorClientHttpConnector;
import org.springframework.web.reactive.function.client.WebClient;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Ryan Baxter
*/
class ActuatorEndpointIT {
private static final String K8S_CONFIG_CLIENT_IT_SERVICE_NAME = "spring-cloud-kubernetes-core-k8s-client-it";
private static final String NAMESPACE = "default";
private static final K3sContainer K3S = Commons.container();
private static Util util;
@BeforeAll
static void beforeAll() throws Exception {
K3S.start();
Commons.validateImage(K8S_CONFIG_CLIENT_IT_SERVICE_NAME, K3S);
Commons.loadSpringCloudKubernetesImage(K8S_CONFIG_CLIENT_IT_SERVICE_NAME, K3S);
util = new Util(K3S);
util.setUp(NAMESPACE);
coreK8sClientIt(Phase.CREATE);
}
@AfterAll
static void afterAll() {
coreK8sClientIt(Phase.DELETE);
Commons.systemPrune();
}
@Test
@SuppressWarnings("unchecked")
void testHealth() {
WebClient.Builder builder = builder();
WebClient serviceClient = builder.baseUrl("http://localhost:80/actuator/health").build();
ResolvableType resolvableType = ResolvableType.forClassWithGenerics(Map.class, String.class, Object.class);
@SuppressWarnings("unchecked")
Map<String, Object> health = (Map<String, Object>) serviceClient.method(HttpMethod.GET).retrieve()
.bodyToMono(ParameterizedTypeReference.forType(resolvableType.getType())).retryWhen(retrySpec())
.block();
Map<String, Object> components = (Map<String, Object>) health.get("components");
assertThat(components.containsKey("kubernetes")).isTrue();
Map<String, Object> kubernetes = (Map<String, Object>) components.get("kubernetes");
assertThat(kubernetes.get("status")).isEqualTo("UP");
Map<String, Object> details = (Map<String, Object>) kubernetes.get("details");
assertThat(details.containsKey("hostIp")).isTrue();
assertThat(details.containsKey("inside")).isTrue();
assertThat(details.containsKey("labels")).isTrue();
assertThat(details.containsKey("namespace")).isTrue();
assertThat(details.containsKey("nodeName")).isTrue();
assertThat(details.containsKey("podIp")).isTrue();
assertThat(details.containsKey("podName")).isTrue();
assertThat(details.containsKey("serviceAccount")).isTrue();
assertThat(components.containsKey("discoveryComposite")).isTrue();
Map<String, Object> discoveryComposite = (Map<String, Object>) components.get("discoveryComposite");
assertThat(discoveryComposite.get("status")).isEqualTo("UP");
}
@Test
@SuppressWarnings("unchecked")
void testInfo() {
WebClient.Builder builder = builder();
WebClient serviceClient = builder.baseUrl("http://localhost:80/actuator/info").build();
ResolvableType resolvableType = ResolvableType.forClassWithGenerics(Map.class, String.class, Object.class);
@SuppressWarnings("unchecked")
Map<String, Object> info = (Map<String, Object>) serviceClient.method(HttpMethod.GET).retrieve()
.bodyToMono(ParameterizedTypeReference.forType(resolvableType.getType())).retryWhen(retrySpec())
.block();
Map<String, Object> kubernetes = (Map<String, Object>) info.get("kubernetes");
assertThat(kubernetes.containsKey("hostIp")).isTrue();
assertThat(kubernetes.containsKey("inside")).isTrue();
assertThat(kubernetes.containsKey("namespace")).isTrue();
assertThat(kubernetes.containsKey("nodeName")).isTrue();
assertThat(kubernetes.containsKey("podIp")).isTrue();
assertThat(kubernetes.containsKey("podName")).isTrue();
assertThat(kubernetes.containsKey("serviceAccount")).isTrue();
}
private static void coreK8sClientIt(Phase phase) {
V1Deployment deployment = (V1Deployment) util
.yaml("spring-cloud-kubernetes-core-k8s-client-it-deployment.yaml");
V1Service service = (V1Service) util.yaml("spring-cloud-kubernetes-core-k8s-client-it-service.yaml");
V1Ingress ingress = (V1Ingress) util.yaml("spring-cloud-kubernetes-core-k8s-client-it-ingress.yaml");
if (phase.equals(Phase.CREATE)) {
util.createAndWait(NAMESPACE, null, deployment, service, ingress, true);
}
else {
util.deleteAndWait(NAMESPACE, deployment, service, ingress);
}
}
private WebClient.Builder builder() {
return WebClient.builder().clientConnector(new ReactorClientHttpConnector(HttpClient.create()));
}
private RetryBackoffSpec retrySpec() {
return Retry.fixedDelay(15, Duration.ofSeconds(1)).filter(Objects::nonNull);
}
}

View File

@@ -1,14 +0,0 @@
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger - %msg%n</pattern>
</encoder>
</appender>
<root level="info">
<appender-ref ref="STDOUT"/>
</root>
<logger name="org.testcontainers" level="INFO"/>
<logger name="com.github.dockerjava" level="WARN"/>
</configuration>

View File

@@ -1,28 +0,0 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: spring-cloud-kubernetes-core-k8s-client-it-deployment
spec:
selector:
matchLabels:
app: spring-cloud-kubernetes-core-k8s-client-it
template:
metadata:
labels:
app: spring-cloud-kubernetes-core-k8s-client-it
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
imagePullPolicy: IfNotPresent
readinessProbe:
httpGet:
port: 8080
path: /actuator/health/readiness
livenessProbe:
httpGet:
port: 8080
path: /actuator/health/liveness
ports:
- containerPort: 8080

View File

@@ -1,16 +0,0 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: it-ingress
namespace: default
spec:
rules:
- http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: spring-cloud-kubernetes-core-k8s-client-it
port:
number: 8080

View File

@@ -1,14 +0,0 @@
apiVersion: v1
kind: Service
metadata:
labels:
app: spring-cloud-kubernetes-core-k8s-client-it
name: spring-cloud-kubernetes-core-k8s-client-it
spec:
ports:
- name: http
port: 8080
targetPort: 8080
selector:
app: spring-cloud-kubernetes-core-k8s-client-it
type: ClusterIP