Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -150,49 +150,6 @@ static void assertBlockingConfiguration(CapturedOutput output, int port) {

}

/**
* Both blocking and reactive are enabled.
*/
static void testDefaultConfiguration(CapturedOutput output, int port) {

waitForLogStatement(output, "Will publish InstanceRegisteredEvent from blocking implementation");
waitForLogStatement(output, "Will publish InstanceRegisteredEvent from reactive implementation");
waitForLogStatement(output, "publishing InstanceRegisteredEvent");
waitForLogStatement(output, "Discovery Client has been initialized");

WebClient healthClient = builder().baseUrl("http://localhost:" + port + "/actuator/health").build();

String healthResult = healthClient.method(HttpMethod.GET)
.retrieve()
.bodyToMono(String.class)
.retryWhen(retrySpec())
.block();

assertThat(BASIC_JSON_TESTER.from(healthResult))
.extractingJsonPathStringValue("$.components.discoveryComposite.status")
.isEqualTo("UP");

assertThat(BASIC_JSON_TESTER.from(healthResult))
.extractingJsonPathStringValue("$.components.discoveryComposite.components.discoveryClient.status")
.isEqualTo("UP");

assertThat(BASIC_JSON_TESTER.from(healthResult))
.extractingJsonPathArrayValue("$.components.discoveryComposite.components.discoveryClient.details.services")
.containsExactlyInAnyOrder("kubernetes", "busybox-service");

assertThat(BASIC_JSON_TESTER.from(healthResult))
.extractingJsonPathStringValue("$.components.reactiveDiscoveryClients.status")
.isEqualTo("UP");

assertThat(BASIC_JSON_TESTER.from(healthResult)).extractingJsonPathStringValue(
"$.components.reactiveDiscoveryClients.components.['Fabric8 Kubernetes Reactive Discovery Client'].status")
.isEqualTo("UP");

assertThat(BASIC_JSON_TESTER.from(healthResult)).extractingJsonPathArrayValue(
"$.components.reactiveDiscoveryClients.components.['Fabric8 Kubernetes Reactive Discovery Client'].details.services")
.containsExactlyInAnyOrder("kubernetes", "busybox-service");
}

/**
* Reactive is enabled, blocking is disabled. As such,
* KubernetesInformerDiscoveryClientAutoConfiguration::indicatorInitializer will post
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@

<artifactId>spring-cloud-kubernetes-k8s-client-discovery</artifactId>

<properties>
<spring-boot.repackage.skip>true</spring-boot.repackage.skip>
<spring-boot.build-image.skip>true</spring-boot.build-image.skip>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
Expand Down Expand Up @@ -41,17 +46,5 @@
</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>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2023 the original author or authors.
* Copyright 2013-2025 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.
Expand All @@ -23,7 +23,7 @@
* @author wind57
*/
@SpringBootApplication
public class DiscoveryApp {
class DiscoveryApp {

public static void main(String[] args) {
SpringApplication.run(DiscoveryApp.class, args);
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*
* Copyright 2013-2025 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.k8s.client.discovery;

import java.util.Set;

import io.kubernetes.client.openapi.ApiClient;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.boot.test.system.CapturedOutput;
import org.springframework.boot.test.web.server.LocalManagementPort;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties;
import org.springframework.cloud.kubernetes.integration.tests.commons.Images;
import org.springframework.cloud.kubernetes.integration.tests.commons.Phase;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;
import org.springframework.test.context.TestPropertySource;

import static org.springframework.cloud.kubernetes.k8s.client.discovery.TestAssertions.assertBlockingConfiguration;
import static org.springframework.cloud.kubernetes.k8s.client.discovery.TestAssertions.assertPodMetadata;

/**
* @author wind57
*/
@SpringBootTest(classes = { DiscoveryApp.class, KubernetesClientBlockingIT.TestConfig.class },
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@TestPropertySource(
properties = { "spring.cloud.discovery.reactive.enabled=false", "spring.cloud.discovery.blocking.enabled=true",
"logging.level.org.springframework.cloud.kubernetes.commons.discovery=debug",
"logging.level.org.springframework.cloud.client.discovery.health=debug",
"logging.level.org.springframework.cloud.kubernetes.client.discovery=debug" })
class KubernetesClientBlockingIT extends KubernetesClientDiscoveryBase {

@LocalManagementPort
private int port;

@Autowired
private DiscoveryClient discoveryClient;

@BeforeEach
void beforeEach() {
Images.loadWiremock(K3S);
util.wiremock(NAMESPACE, "/", Phase.CREATE);
}

@AfterEach
void afterEach() {
util.wiremock(NAMESPACE, "/", Phase.DELETE);
}

/**
* <pre>
*
* Reactive is disabled, only blocking is active. As such,
* We assert for logs and call '/health' endpoint to see that blocking discovery
* client was initialized.
*
* </pre>
*/
@Test
void test(CapturedOutput output) {
assertBlockingConfiguration(output, port);
assertPodMetadata(discoveryClient);
}

@TestConfiguration
static class TestConfig {

@Bean
@Primary
ApiClient client() {
return apiClient();
}

@Bean
@Primary
KubernetesDiscoveryProperties kubernetesDiscoveryProperties() {
return discoveryProperties(false, Set.of(NAMESPACE), null);
}

}

}
Loading
Loading