Skip to content

Commit

Permalink
Merge pull request #16269 from geoand/k8s-polish
Browse files Browse the repository at this point in the history
Print error message is printed with certificate is self-signed when deploying to OpenShift
  • Loading branch information
geoand authored Apr 6, 2021
2 parents 272514c + 3058227 commit 668c83b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
import io.quarkus.deployment.pkg.builditem.NativeImageBuildItem;
import io.quarkus.deployment.pkg.builditem.OutputTargetBuildItem;
import io.quarkus.deployment.pkg.steps.NativeBuild;
import io.quarkus.kubernetes.client.deployment.KubernetesClientErrorHanlder;
import io.quarkus.kubernetes.client.deployment.KubernetesClientErrorHandler;
import io.quarkus.kubernetes.client.spi.KubernetesClientBuildItem;
import io.quarkus.kubernetes.spi.DecoratorBuildItem;
import io.quarkus.kubernetes.spi.KubernetesCommandBuildItem;
Expand Down Expand Up @@ -340,7 +340,7 @@ public static void createContainerImage(KubernetesClientBuildItem kubernetesClie
//Let's disable http2 as it causes issues with duplicate build triggers.
config.setHttp2Disable(true);
try (KubernetesClient client = Clients.fromConfig(config)) {
OpenShiftClient openShiftClient = client.adapt(OpenShiftClient.class);
OpenShiftClient openShiftClient = toOpenshiftClient(client);
KubernetesList kubernetesList = Serialization
.unmarshalAsList(new ByteArrayInputStream(openshiftManifests.getData()));

Expand All @@ -353,6 +353,15 @@ public static void createContainerImage(KubernetesClientBuildItem kubernetesClie
}
}

private static OpenShiftClient toOpenshiftClient(KubernetesClient client) {
try {
return client.adapt(OpenShiftClient.class);
} catch (KubernetesClientException e) {
KubernetesClientErrorHandler.handle(e);
return null; // will never happen
}
}

/**
* Apply the openshift resources and wait until ImageStreamTags are created.
*
Expand Down Expand Up @@ -391,7 +400,7 @@ private static void applyOpenshiftResources(OpenShiftClient client, List<HasMeta
OpenshiftUtils.waitForImageStreamTags(client, buildResources, 2, TimeUnit.MINUTES);

} catch (KubernetesClientException e) {
KubernetesClientErrorHanlder.handle(e);
KubernetesClientErrorHandler.handle(e);
}
}

Expand Down Expand Up @@ -499,7 +508,7 @@ private static Stream<Build> runningBuildsOf(OpenShiftClient client, BuildConfig

private static RuntimeException openshiftException(Throwable t) {
if (t instanceof KubernetesClientException) {
KubernetesClientErrorHanlder.handle((KubernetesClientException) t);
KubernetesClientErrorHandler.handle((KubernetesClientException) t);
}
return new RuntimeException("Execution of openshift build failed. See build output for more details", t);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
import io.quarkus.deployment.pkg.builditem.NativeImageBuildItem;
import io.quarkus.deployment.pkg.builditem.OutputTargetBuildItem;
import io.quarkus.deployment.pkg.steps.NativeBuild;
import io.quarkus.kubernetes.client.deployment.KubernetesClientErrorHanlder;
import io.quarkus.kubernetes.client.deployment.KubernetesClientErrorHandler;
import io.quarkus.kubernetes.client.spi.KubernetesClientBuildItem;
import io.quarkus.kubernetes.spi.KubernetesCommandBuildItem;
import io.quarkus.kubernetes.spi.KubernetesEnvBuildItem;
Expand Down Expand Up @@ -313,7 +313,7 @@ private static void applyS2iResources(OpenShiftClient client, List<HasMetadata>
S2iUtils.waitForImageStreamTags(client, buildResources, 2, TimeUnit.MINUTES);

} catch (KubernetesClientException e) {
KubernetesClientErrorHanlder.handle(e);
KubernetesClientErrorHandler.handle(e);
}
}

Expand Down Expand Up @@ -400,7 +400,7 @@ private static Stream<Build> runningBuildsOf(OpenShiftClient client, BuildConfig

private static RuntimeException s2iException(Throwable t) {
if (t instanceof KubernetesClientException) {
KubernetesClientErrorHanlder.handle((KubernetesClientException) t);
KubernetesClientErrorHandler.handle((KubernetesClientException) t);
}
return new RuntimeException("Execution of s2i build failed. See s2i output for more details", t);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

import org.jboss.logging.Logger;

public class KubernetesClientErrorHanlder {
public class KubernetesClientErrorHandler {

private static final Logger LOG = Logger.getLogger(KubernetesClientErrorHanlder.class);
private static final Logger LOG = Logger.getLogger(KubernetesClientErrorHandler.class);

public static void handle(Exception e) {
if (e.getCause() instanceof SSLHandshakeException) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
import io.quarkus.deployment.pkg.builditem.ArtifactResultBuildItem;
import io.quarkus.deployment.pkg.builditem.DeploymentResultBuildItem;
import io.quarkus.deployment.pkg.builditem.OutputTargetBuildItem;
import io.quarkus.kubernetes.client.deployment.KubernetesClientErrorHanlder;
import io.quarkus.kubernetes.client.deployment.KubernetesClientErrorHandler;
import io.quarkus.kubernetes.client.spi.KubernetesClientBuildItem;
import io.quarkus.kubernetes.spi.KubernetesDeploymentTargetBuildItem;

Expand Down Expand Up @@ -192,7 +192,7 @@ private DeploymentResultBuildItem deploy(DeploymentTargetEntry deploymentTarget,
} catch (FileNotFoundException e) {
throw new IllegalStateException("Can't find generated kubernetes manifest: " + manifest.getAbsolutePath());
} catch (KubernetesClientException e) {
KubernetesClientErrorHanlder.handle(e);
KubernetesClientErrorHandler.handle(e);
throw e;
} catch (IOException e) {
throw new RuntimeException("Error closing file: " + manifest.getAbsolutePath());
Expand Down

0 comments on commit 668c83b

Please sign in to comment.