-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
420ad1e
commit ca0256c
Showing
6 changed files
with
138 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"auths":{"cloud.openshift.com":{"auth":"something","email":"[email protected]"},"quay.io":{"auth":"something","email":"[email protected]"},"registry.connect.redhat.com":{"auth":"something","email":"[email protected]"},"registry.redhat.io":{"auth":"something","email":"[email protected]"}}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 41 additions & 7 deletions
48
src/test/java/org/trustify/operator/controllers/setup/K3sResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,60 @@ | ||
package org.trustify.operator.controllers.setup; | ||
|
||
import io.quarkus.test.common.QuarkusTestResourceLifecycleManager; | ||
import org.jboss.logging.Logger; | ||
import org.testcontainers.k3s.K3sContainer; | ||
import org.testcontainers.utility.DockerImageName; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Paths; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
public class K3sResource implements QuarkusTestResourceLifecycleManager { | ||
static K3sContainer k3sContainer = new K3sContainer(DockerImageName.parse("rancher/k3s:" + Optional.ofNullable(System.getenv("KUBERNETES_VERSION")).orElse("latest"))); | ||
private static final Logger logger = Logger.getLogger(K3sConfigProducer.class); | ||
|
||
static K3sContainer k3sContainer; | ||
|
||
// If ENV HOST_KUBERNETES_CONFIG_FILE is set then use the host k8s config | ||
public static final String HOST_KUBERNETES_CONFIG_FILE = "HOST_KUBERNETES_CONFIG_FILE"; | ||
|
||
// If ENV HOST_KUBERNETES_CONFIG_FILE is not set then rancher/k3s for k8s. If KUBERNETES_VERSION is not set then "latest" is used | ||
public static final String KUBERNETES_VERSION = "KUBERNETES_VERSION"; | ||
|
||
@Override | ||
public Map<String, String> start() { | ||
k3sContainer.start(); | ||
return Map.of( | ||
"kubeConfigYaml", k3sContainer.getKubeConfigYaml(), | ||
"quarkus.kubernetes.namespace", "trustify-operator" | ||
); | ||
Map<String, String> result = new HashMap<>(); | ||
result.put("quarkus.kubernetes.namespace", "trustify-operator"); | ||
|
||
String kubeConfigYaml; | ||
Optional<String> hostKubernetesConfigFile = Optional.ofNullable(System.getenv(HOST_KUBERNETES_CONFIG_FILE)); | ||
if (hostKubernetesConfigFile.isPresent()) { | ||
logger.info("Using " + hostKubernetesConfigFile.get() + " as kubernetes config file"); | ||
try { | ||
kubeConfigYaml = Files.readString(Paths.get(hostKubernetesConfigFile.get())); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} else { | ||
String rancherVersion = Optional.ofNullable(System.getenv(KUBERNETES_VERSION)).orElse("latest"); | ||
logger.info("Using rancher/k3s:" + rancherVersion); | ||
|
||
k3sContainer = new K3sContainer(DockerImageName.parse("rancher/k3s:" + rancherVersion)); | ||
k3sContainer.start(); | ||
|
||
kubeConfigYaml = k3sContainer.getKubeConfigYaml(); | ||
} | ||
|
||
result.put("kubeConfigYaml", kubeConfigYaml); | ||
return result; | ||
} | ||
|
||
@Override | ||
public void stop() { | ||
k3sContainer.stop(); | ||
if (k3sContainer != null) { | ||
k3sContainer.stop(); | ||
} | ||
} | ||
} |