Skip to content

Commit

Permalink
Merge pull request #28172 from michalvavrik/feature/fix-knative-clien…
Browse files Browse the repository at this point in the history
…t-validation

Fix Knative/OpenShift client environment check
  • Loading branch information
Sgitario committed Sep 27, 2022
2 parents adff7c4 + 621fc75 commit 463f9a6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import java.util.List;
import java.util.Optional;

import io.fabric8.knative.client.KnativeClient;
import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.kubernetes.client.spi.KubernetesClientBuildItem;
Expand All @@ -23,7 +22,8 @@ public void checkEnvironment(Optional<SelectedKubernetesDeploymentTargetBuildIte
return;
}
if (target.getEntry().getName().equals(KNATIVE)) {
if (client.getClient().isAdaptable(KnativeClient.class)) {
// use 'isSupported' once https://github.com/fabric8io/kubernetes-client/issues/4447 is resolved
if (client.getClient().hasApiGroup("knative.dev", false)) {
deploymentCluster.produce(new KubernetesDeploymentClusterBuildItem(KNATIVE));
} else {
throw new IllegalStateException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,16 @@ public void checkEnvironment(Optional<SelectedKubernetesDeploymentTargetBuildIte
return;
}
if (target.getEntry().getName().equals(OPENSHIFT)) {
if (client.getClient().isAdaptable(OpenShiftClient.class)) {
deploymentCluster.produce(new KubernetesDeploymentClusterBuildItem(OPENSHIFT));
} else {
throw new IllegalStateException(
"Openshift was requested as a deployment, but the target cluster is not an Openshift cluster!");
try (var openShiftClient = client.getClient().adapt(OpenShiftClient.class)) {
if (openShiftClient.isSupported()) {
deploymentCluster.produce(new KubernetesDeploymentClusterBuildItem(OPENSHIFT));
} else {
throw new IllegalStateException(
"Openshift was requested as a deployment, but the target cluster is not an Openshift cluster!");
}
} catch (Exception e) {
throw new RuntimeException(
"Failed to configure OpenShift. Make sure you have the Quarkus OpenShift extension.", e);
}
}
});
Expand Down

0 comments on commit 463f9a6

Please sign in to comment.