Skip to content

Commit

Permalink
Merge pull request quarkusio#31737 from Sgitario/26180
Browse files Browse the repository at this point in the history
OpenShift binary build fails when current namespace is different
  • Loading branch information
iocanel authored Mar 10, 2023
2 parents 0231a81 + a884712 commit 90a11d6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
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));
}
}

0 comments on commit 90a11d6

Please sign in to comment.