Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
@@ -1,5 +1,6 @@
package io.quarkus.container.image.openshift.deployment;

import static io.quarkus.container.image.openshift.deployment.OpenshiftUtils.getNamespace;
import static io.quarkus.container.image.openshift.deployment.OpenshiftUtils.mergeConfig;
import static io.quarkus.container.util.PathsUtil.findMainSourcesRoot;
import static io.quarkus.deployment.pkg.steps.JarResultBuildStep.DEFAULT_FAST_JAR_DIRECTORY_NAME;
Expand Down Expand Up @@ -264,7 +265,7 @@ public void openshiftBuildFromJar(OpenshiftConfig openshiftConfig,
return;
}

try (KubernetesClient kubernetesClient = kubernetesClientBuilder.buildClient()) {
try (KubernetesClient kubernetesClient = buildClient(kubernetesClientBuilder)) {
String namespace = Optional.ofNullable(kubernetesClient.getNamespace()).orElse("default");
LOG.info("Starting (in-cluster) container image build for jar using: " + config.buildStrategy + " on server: "
+ kubernetesClient.getMasterUrl() + " in namespace:" + namespace + ".");
Expand Down Expand Up @@ -324,7 +325,7 @@ public void openshiftBuildFromNative(OpenshiftConfig openshiftConfig, S2iConfig
return;
}

try (KubernetesClient kubernetesClient = kubernetesClientBuilder.buildClient()) {
try (KubernetesClient kubernetesClient = buildClient(kubernetesClientBuilder)) {
String namespace = Optional.ofNullable(kubernetesClient.getNamespace()).orElse("default");

LOG.info("Starting (in-cluster) container image build for jar using: " + config.buildStrategy + " on server: "
Expand Down Expand Up @@ -543,6 +544,11 @@ private static KubernetesClientBuilder newClientBuilderWithoutHttp2(Config confi
return new KubernetesClientBuilder().withConfig(configuration).withHttpClientFactory(httpClientFactory);
}

private static KubernetesClient buildClient(KubernetesClientBuildItem kubernetesClientBuilder) {
getNamespace().ifPresent(kubernetesClientBuilder.getConfig()::setNamespace);
return kubernetesClientBuilder.buildClient();
}

// visible for test
static String concatUnixPaths(String... elements) {
StringBuilder result = new StringBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
*/
public class OpenshiftUtils {

private static final String OPENSHIFT_NAMESPACE = "quarkus.openshift.namespace";
private static final String KUBERNETES_NAMESPACE = "quarkus.kubernetes.namespace";

/**
* Wait for the references ImageStreamTags to become available.
*
Expand Down Expand Up @@ -142,4 +145,12 @@ public static OpenshiftConfig mergeConfig(OpenshiftConfig openshiftConfig, S2iCo

return result;
}

/**
* @return the openshift namespace set in the OpenShift extension.
*/
public static Optional<String> getNamespace() {
return ConfigProvider.getConfig().getOptionalValue(OPENSHIFT_NAMESPACE, String.class)
.or(() -> ConfigProvider.getConfig().getOptionalValue(KUBERNETES_NAMESPACE, String.class));
}
}