2727import java .time .Duration ;
2828import java .util .Arrays ;
2929import java .util .List ;
30- import java .util .Objects ;
3130import java .util .Optional ;
3231import java .util .concurrent .TimeUnit ;
3332
3433import com .github .dockerjava .api .command .ListImagesCmd ;
3534import com .github .dockerjava .api .command .PullImageCmd ;
3635import com .github .dockerjava .api .command .SaveImageCmd ;
37- import com .github .dockerjava .api .model .Bind ;
38- import com .github .dockerjava .api .model .HostConfig ;
3936import com .github .dockerjava .api .model .Image ;
4037import org .apache .commons .logging .Log ;
4138import org .apache .commons .logging .LogFactory ;
4239import org .junit .jupiter .api .Assertions ;
4340import org .testcontainers .containers .Container ;
4441import org .testcontainers .k3s .K3sContainer ;
45- import org .testcontainers .utility .DockerImageName ;
4642
4743import org .springframework .core .io .ClassPathResource ;
4844import org .springframework .util .ReflectionUtils ;
4945import org .springframework .util .StreamUtils ;
5046import org .springframework .util .StringUtils ;
5147
5248import 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}
0 commit comments