Skip to content

Commit 7e824ba

Browse files
authored
clean (#1765)
1 parent 8d02d1a commit 7e824ba

File tree

4 files changed

+131
-75
lines changed

4 files changed

+131
-75
lines changed

spring-cloud-kubernetes-test-support/src/main/java/org/springframework/cloud/kubernetes/integration/tests/commons/Commons.java

Lines changed: 6 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -27,29 +27,29 @@
2727
import java.time.Duration;
2828
import java.util.Arrays;
2929
import java.util.List;
30-
import java.util.Objects;
3130
import java.util.Optional;
3231
import java.util.concurrent.TimeUnit;
3332

3433
import com.github.dockerjava.api.command.ListImagesCmd;
3534
import com.github.dockerjava.api.command.PullImageCmd;
3635
import com.github.dockerjava.api.command.SaveImageCmd;
37-
import com.github.dockerjava.api.model.Bind;
38-
import com.github.dockerjava.api.model.HostConfig;
3936
import com.github.dockerjava.api.model.Image;
4037
import org.apache.commons.logging.Log;
4138
import org.apache.commons.logging.LogFactory;
4239
import org.junit.jupiter.api.Assertions;
4340
import org.testcontainers.containers.Container;
4441
import org.testcontainers.k3s.K3sContainer;
45-
import org.testcontainers.utility.DockerImageName;
4642

4743
import org.springframework.core.io.ClassPathResource;
4844
import org.springframework.util.ReflectionUtils;
4945
import org.springframework.util.StreamUtils;
5046
import org.springframework.util.StringUtils;
5147

5248
import static org.awaitility.Awaitility.await;
49+
import static org.springframework.cloud.kubernetes.integration.tests.commons.Constants.KUBERNETES_VERSION_FILE;
50+
import static org.springframework.cloud.kubernetes.integration.tests.commons.Constants.TEMP_FOLDER;
51+
import static org.springframework.cloud.kubernetes.integration.tests.commons.Constants.TMP_IMAGES;
52+
import static org.springframework.cloud.kubernetes.integration.tests.commons.FixedPortsK3sContainer.CONTAINER;
5353

5454
/**
5555
* A few commons things that can be re-used across clients. This is meant to be used for
@@ -61,44 +61,10 @@ public final class Commons {
6161

6262
private static final Log LOG = LogFactory.getLog(Commons.class);
6363

64-
/**
65-
* this path is generated by the pipeline of github actions.
66-
*/
67-
private static final String TMP_IMAGES = "/tmp/docker/images";
68-
6964
private Commons() {
7065
throw new AssertionError("No instance provided");
7166
}
7267

73-
private static final String KUBERNETES_VERSION_FILE = "META-INF/springcloudkubernetes-version.txt";
74-
75-
/**
76-
* Rancher version to use for test-containers.
77-
*/
78-
public static final String RANCHER = "rancher/k3s:v1.28.8-k3s1";
79-
80-
/**
81-
* Command to use when starting rancher. Without "server" option, traefik is not
82-
* installed
83-
*/
84-
public static final String RANCHER_COMMAND = "server";
85-
86-
/**
87-
* Test containers exposed ports.
88-
*/
89-
public static final int[] EXPOSED_PORTS = new int[] { 80, 6443, 8080, 8888, 9092 };
90-
91-
/**
92-
* Temporary folder where to load images.
93-
*/
94-
public static final String TEMP_FOLDER = new File(System.getProperty("java.io.tmpdir")).getAbsolutePath();
95-
96-
private static final K3sContainer CONTAINER = new FixedPortsK3sContainer(DockerImageName.parse(Commons.RANCHER))
97-
.configureFixedPorts()
98-
.addBinds()
99-
.withCommand(Commons.RANCHER_COMMAND)
100-
.withReuse(true);
101-
10268
public static K3sContainer container() {
10369
return CONTAINER;
10470
}
@@ -180,7 +146,7 @@ public static void loadImage(String image, String tag, String tarName, K3sContai
180146
* either get the tar from '/tmp/docker/images', or pull the image.
181147
*/
182148
public static void load(K3sContainer container, String tarName, String imageNameForDownload, String imageVersion) {
183-
File dockerImagesRootDir = Paths.get(Commons.TMP_IMAGES).toFile();
149+
File dockerImagesRootDir = Paths.get(TMP_IMAGES).toFile();
184150
if (dockerImagesRootDir.exists() && dockerImagesRootDir.isDirectory()) {
185151
File[] tars = dockerImagesRootDir.listFiles();
186152
if (tars != null && tars.length > 0) {
@@ -189,8 +155,7 @@ public static void load(K3sContainer container, String tarName, String imageName
189155
.filter(x -> x.contains(tarName))
190156
.findFirst();
191157
if (found.isPresent()) {
192-
LOG.info("running in github actions, will load from : " + Commons.TMP_IMAGES + " tar : "
193-
+ found.get());
158+
LOG.info("running in github actions, will load from : " + TMP_IMAGES + " tar : " + found.get());
194159
Commons.loadImageFromPath(found.get(), container);
195160
return;
196161
}
@@ -321,35 +286,4 @@ public static void waitForLogStatement(String message, K3sContainer k3sContainer
321286

322287
}
323288

324-
/**
325-
* A K3sContainer, but with fixed port mappings. This is needed because of the nature
326-
* of some integration tests.
327-
*
328-
* @author wind57
329-
*/
330-
private static final class FixedPortsK3sContainer extends K3sContainer {
331-
332-
private FixedPortsK3sContainer(DockerImageName dockerImageName) {
333-
super(dockerImageName);
334-
}
335-
336-
private FixedPortsK3sContainer configureFixedPorts() {
337-
for (int port : Commons.EXPOSED_PORTS) {
338-
super.addFixedExposedPort(port, port);
339-
}
340-
return this;
341-
}
342-
343-
private FixedPortsK3sContainer addBinds() {
344-
super.withCreateContainerCmdModifier(cmd -> {
345-
HostConfig hostConfig = Objects.requireNonNull(cmd.getHostConfig());
346-
hostConfig.withBinds(Bind.parse(TEMP_FOLDER + ":" + TEMP_FOLDER),
347-
Bind.parse(TMP_IMAGES + ":" + TMP_IMAGES));
348-
});
349-
350-
return this;
351-
}
352-
353-
}
354-
355289
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright 2013-2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.cloud.kubernetes.integration.tests.commons;
18+
19+
import java.io.File;
20+
21+
/**
22+
* @author wind57
23+
*/
24+
final class Constants {
25+
26+
private Constants() {
27+
28+
}
29+
30+
/**
31+
* this path is generated by the pipeline of github actions.
32+
*/
33+
static final String TMP_IMAGES = "/tmp/docker/images";
34+
35+
/**
36+
* Temporary folder where to load images.
37+
*/
38+
static final String TEMP_FOLDER = new File(System.getProperty("java.io.tmpdir")).getAbsolutePath();
39+
40+
/**
41+
* where is the version situated.
42+
*/
43+
static final String KUBERNETES_VERSION_FILE = "META-INF/springcloudkubernetes-version.txt";
44+
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
* Copyright 2013-2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.cloud.kubernetes.integration.tests.commons;
18+
19+
import java.util.Objects;
20+
21+
import com.github.dockerjava.api.model.Bind;
22+
import com.github.dockerjava.api.model.HostConfig;
23+
import org.testcontainers.k3s.K3sContainer;
24+
import org.testcontainers.utility.DockerImageName;
25+
26+
import static org.springframework.cloud.kubernetes.integration.tests.commons.Constants.TEMP_FOLDER;
27+
import static org.springframework.cloud.kubernetes.integration.tests.commons.Constants.TMP_IMAGES;
28+
29+
/**
30+
* A K3sContainer, but with fixed port mappings. This is needed because of the nature of
31+
* some integration tests.
32+
*
33+
* @author wind57
34+
*/
35+
final class FixedPortsK3sContainer extends K3sContainer {
36+
37+
/**
38+
* Test containers exposed ports.
39+
*/
40+
private static final int[] EXPOSED_PORTS = new int[] { 80, 6443, 8080, 8888, 9092 };
41+
42+
/**
43+
* Rancher version to use for test-containers.
44+
*/
45+
private static final String RANCHER_VERSION = "rancher/k3s:v1.28.8-k3s1";
46+
47+
/**
48+
* Command to use when starting rancher. Without "server" option, traefik is not
49+
* installed
50+
*/
51+
private static final String RANCHER_COMMAND = "server";
52+
53+
static final K3sContainer CONTAINER = new FixedPortsK3sContainer(DockerImageName.parse(RANCHER_VERSION))
54+
.configureFixedPorts()
55+
.addBinds()
56+
.withCommand(RANCHER_COMMAND)
57+
.withReuse(true);
58+
59+
FixedPortsK3sContainer(DockerImageName dockerImageName) {
60+
super(dockerImageName);
61+
}
62+
63+
FixedPortsK3sContainer configureFixedPorts() {
64+
for (int port : EXPOSED_PORTS) {
65+
super.addFixedExposedPort(port, port);
66+
}
67+
return this;
68+
}
69+
70+
FixedPortsK3sContainer addBinds() {
71+
super.withCreateContainerCmdModifier(cmd -> {
72+
HostConfig hostConfig = Objects.requireNonNull(cmd.getHostConfig());
73+
hostConfig.withBinds(Bind.parse(TEMP_FOLDER + ":" + TEMP_FOLDER),
74+
Bind.parse(TMP_IMAGES + ":" + TMP_IMAGES));
75+
});
76+
77+
return this;
78+
}
79+
80+
}

spring-cloud-kubernetes-test-support/src/main/java/org/springframework/cloud/kubernetes/integration/tests/commons/fabric8_client/Util.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,6 @@ public final class Util {
6565

6666
private static final Log LOG = LogFactory.getLog(Util.class);
6767

68-
/** Image we get {@code istioctl} from in order to install Istio. */
69-
public static final String ISTIO_ISTIOCTL = "istio/istioctl";
70-
7168
private final K3sContainer container;
7269

7370
private final KubernetesClient client;

0 commit comments

Comments
 (0)