Skip to content

Commit

Permalink
Merge branch '3.1.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanjbaxter committed Dec 3, 2024
2 parents 6495f46 + d29c69b commit 2d7cbda
Show file tree
Hide file tree
Showing 24 changed files with 913 additions and 1,371 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,21 @@
<filtering>true</filtering>
</resource>
</resources>

<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<id>build-image</id>
<configuration>
<skip>true</skip>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* @author wind57
*/
@SpringBootApplication
public class Fabric8DiscoveryApp {
class Fabric8DiscoveryApp {

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

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
/*
* Copyright 2012-2024 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.fabric8.client.discovery;

import java.io.InputStream;

import io.fabric8.kubernetes.api.model.Service;
import io.fabric8.kubernetes.client.utils.Serialization;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.kubernetes.integration.tests.commons.Images;
import org.springframework.cloud.kubernetes.integration.tests.commons.Phase;
import org.springframework.test.context.TestPropertySource;

import static org.springframework.cloud.kubernetes.fabric8.client.discovery.TestAssertions.assertAllServices;

/**
* @author wind57
*/
class Fabric8DiscoveryAllServicesIT extends Fabric8DiscoveryBase {

private static Service externalServiceName;

@BeforeAll
static void beforeAllInNested() {
InputStream externalNameServiceStream = util.inputStream("external-name-service.yaml");
externalServiceName = Serialization.unmarshal(externalNameServiceStream, Service.class);
}

private void externalNameServices(Phase phase) {
if (phase == Phase.CREATE) {
util.createAndWait(NAMESPACE, null, null, externalServiceName, null, true);
}
else {
util.deleteAndWait(NAMESPACE, null, externalServiceName, null);
}
}

@Nested
@TestPropertySource(properties = { "spring.cloud.kubernetes.discovery.include-external-name-services=true" })
class NonBootstrap {

@Autowired
private DiscoveryClient discoveryClient;

@BeforeEach
void beforeEach() {
Images.loadBusybox(K3S);
util.busybox(NAMESPACE, Phase.CREATE);
externalNameServices(Phase.CREATE);
}

@AfterEach
void afterEach() {
util.busybox(NAMESPACE, Phase.DELETE);
externalNameServices(Phase.DELETE);
}

/**
* <pre>
* - there are 3 services : 'busybox-service', 'kubernetes', 'external-name-service'
* - all of them are found
* </pre>
*/
@Test
void test() {
assertAllServices(discoveryClient);
}

}

@Nested
@TestPropertySource(properties = { "spring.cloud.kubernetes.discovery.include-external-name-services=true",
"spring.cloud.bootstrap.enabled=true" })
class Bootstrap {

@Autowired
private DiscoveryClient discoveryClient;

@BeforeEach
void beforeEach() {
Images.loadBusybox(K3S);
util.busybox(NAMESPACE, Phase.CREATE);
externalNameServices(Phase.CREATE);
}

@AfterEach
void afterEach() {
util.busybox(NAMESPACE, Phase.DELETE);
externalNameServices(Phase.DELETE);
}

/**
* <pre>
* - there are 3 services : 'busybox-service', 'kubernetes', 'external-name-service'
* - all of them are found
* </pre>
*/
@Test
void test() {
assertAllServices(discoveryClient);
}

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Copyright 2012-2024 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.fabric8.client.discovery;

import io.fabric8.kubernetes.client.Config;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClientBuilder;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.extension.ExtendWith;
import org.testcontainers.k3s.K3sContainer;

import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.boot.test.system.OutputCaptureExtension;
import org.springframework.cloud.kubernetes.integration.tests.commons.Commons;
import org.springframework.cloud.kubernetes.integration.tests.commons.fabric8_client.Util;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;
import org.springframework.test.context.TestPropertySource;

/**
* @author wind57
*/
@TestPropertySource(properties = { "spring.main.cloud-platform=kubernetes",
"spring.cloud.config.import-check.enabled=false", "spring.cloud.kubernetes.client.namespace=default",
"spring.cloud.kubernetes.discovery.metadata.add-pod-labels=true",
"spring.cloud.kubernetes.discovery.metadata.add-pod-annotations=true",
"logging.level.org.springframework.cloud.kubernetes.fabric8.discovery=debug" })
@ExtendWith(OutputCaptureExtension.class)
@SpringBootTest(classes = { Fabric8DiscoveryApp.class, Fabric8DiscoveryBase.TestConfig.class },
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
abstract class Fabric8DiscoveryBase {

protected static final String NAMESPACE = "default";

protected static final K3sContainer K3S = Commons.container();

protected static Util util;

@BeforeAll
protected static void beforeAll() {
K3S.start();
util = new Util(K3S);
}

protected static KubernetesClient client() {
String kubeConfigYaml = K3S.getKubeConfigYaml();
Config config = Config.fromKubeconfig(kubeConfigYaml);
return new KubernetesClientBuilder().withConfig(config).build();
}

@TestConfiguration
static class TestConfig {

@Bean
@Primary
KubernetesClient kubernetesClient() {
return client();
}

}

}
Loading

0 comments on commit 2d7cbda

Please sign in to comment.