Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor fabric8 discovery integration tests (2) #1756

Merged
merged 41 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
40252b6
started work
wind57 Oct 4, 2024
86d2e8a
dirty
wind57 Oct 5, 2024
0589167
dirty
wind57 Oct 5, 2024
840fc59
fix
wind57 Oct 5, 2024
71d0a5e
Merge branch 'change-delete-sequence' into refactor-integration-tests-1
wind57 Oct 5, 2024
fe07a73
dirty
wind57 Oct 5, 2024
6b3200f
first working
wind57 Oct 5, 2024
e4a88a9
cleanup
wind57 Oct 5, 2024
f88a581
cleanup
wind57 Oct 5, 2024
ed6565c
cleanup
wind57 Oct 5, 2024
096cf99
dirty
wind57 Oct 6, 2024
8824f14
more improvements
wind57 Oct 6, 2024
543c8a5
Merge branch 'refactor-integration-tests-1' into refactor-integration…
wind57 Oct 6, 2024
7dda032
more improvements
wind57 Oct 6, 2024
53db36f
Merge branch 'refactor-integration-tests-1' into refactor-integration…
wind57 Oct 6, 2024
d0d3b03
dirty
wind57 Oct 6, 2024
947cc43
cleanup
wind57 Oct 6, 2024
e38293f
Merge branch 'refactor-integration-tests-1' into refactor-integration…
wind57 Oct 6, 2024
b87b82b
dirty
wind57 Oct 6, 2024
566dfd6
dirty
wind57 Oct 6, 2024
fe9b3f5
dirty
wind57 Oct 6, 2024
b138b42
static import
wind57 Oct 6, 2024
ab24227
Merge branch 'refactor-integration-tests-1' into refactor-integration…
wind57 Oct 6, 2024
6d7e298
dirty
wind57 Oct 6, 2024
7b134e6
Merge branch '3.1.x' into refactor-integration-tests-1
wind57 Oct 6, 2024
260af17
Merge branch 'refactor-integration-tests-1' into refactor-integration…
wind57 Oct 6, 2024
c5d83f6
dirty
wind57 Oct 6, 2024
f1fa96e
dirty
wind57 Oct 6, 2024
b0dcb45
first ready
wind57 Oct 7, 2024
1a95e9d
read yaml only once
wind57 Oct 9, 2024
f5cd354
read yaml only once, simpler
wind57 Oct 9, 2024
e8b4fe6
Merge branch '3.1.x' into refactor-integration-tests-2
wind57 Oct 15, 2024
565eb64
drop unused import
wind57 Oct 15, 2024
56ffc9f
checkstyle
wind57 Oct 15, 2024
35ffe5d
merge
wind57 Oct 16, 2024
ff92354
merge 3.1.x
wind57 Oct 18, 2024
f5f666f
merge 3.1.x
wind57 Oct 18, 2024
8cdfdee
fix
wind57 Oct 18, 2024
5c637e5
Merge branch 'more-improvements' into refactor-integration-tests-2
wind57 Oct 18, 2024
6c11f96
lower visibility
wind57 Nov 29, 2024
3e48a27
Merge branch '3.1.x' into refactor-integration-tests-2
wind57 Nov 29, 2024
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 @@ -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
Loading