Skip to content

Commit

Permalink
Merge pull request #23052 from ioforks/issue-21311
Browse files Browse the repository at this point in the history
Ιmprove k8s deployment errors related to target platform
  • Loading branch information
iocanel authored Feb 22, 2022
2 parents 4233735 + 5da5dba commit 2961655
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

package io.quarkus.kubernetes.spi;

import io.quarkus.builder.item.MultiBuildItem;

public final class KubernetesDeploymentClusterBuildItem extends MultiBuildItem {

private final String kind;

public KubernetesDeploymentClusterBuildItem(String kind) {
this.kind = kind;
}

public String getKind() {
return kind;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package io.quarkus.kubernetes.deployment;

import static io.quarkus.kubernetes.deployment.Constants.KNATIVE;

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;
import io.quarkus.kubernetes.spi.GeneratedKubernetesResourceBuildItem;
import io.quarkus.kubernetes.spi.KubernetesDeploymentClusterBuildItem;

public class KnativeDeployer {

@BuildStep
public void checkEnvironment(Optional<SelectedKubernetesDeploymentTargetBuildItem> selectedDeploymentTarget,
List<GeneratedKubernetesResourceBuildItem> resources,
KubernetesClientBuildItem client, BuildProducer<KubernetesDeploymentClusterBuildItem> deploymentCluster) {
selectedDeploymentTarget.ifPresent(target -> {
if (!KubernetesDeploy.INSTANCE.checkSilently()) {
return;
}
if (target.getEntry().getName().equals(KNATIVE)) {
if (client.getClient().isAdaptable(KnativeClient.class)) {
deploymentCluster.produce(new KubernetesDeploymentClusterBuildItem(KNATIVE));
} else {
throw new IllegalStateException(
"Knative was requested as a deployment, but the target cluster is not a Knative cluster!");
}
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
import io.quarkus.deployment.pkg.builditem.OutputTargetBuildItem;
import io.quarkus.kubernetes.client.deployment.KubernetesClientErrorHandler;
import io.quarkus.kubernetes.client.spi.KubernetesClientBuildItem;
import io.quarkus.kubernetes.spi.GeneratedKubernetesResourceBuildItem;
import io.quarkus.kubernetes.spi.KubernetesDeploymentClusterBuildItem;
import io.quarkus.kubernetes.spi.KubernetesOptionalResourceDefinitionBuildItem;

public class KubernetesDeployer {
Expand Down Expand Up @@ -77,9 +79,25 @@ public void selectDeploymentTarget(ContainerImageInfoBuildItem containerImageInf
selectedDeploymentTarget.produce(new SelectedKubernetesDeploymentTargetBuildItem(selectedTarget));
}

@BuildStep
public void checkEnvironment(Optional<SelectedKubernetesDeploymentTargetBuildItem> selectedDeploymentTarget,
KubernetesClientBuildItem client,
List<GeneratedKubernetesResourceBuildItem> resources,
BuildProducer<KubernetesDeploymentClusterBuildItem> deploymentCluster) {

if (!KubernetesDeploy.INSTANCE.checkSilently()) {
return;
}
String target = selectedDeploymentTarget.map(s -> s.getEntry().getName()).orElse(KUBERNETES);
if (target.equals(KUBERNETES)) {
deploymentCluster.produce(new KubernetesDeploymentClusterBuildItem(KUBERNETES));
}
}

@BuildStep(onlyIf = IsNormalNotRemoteDev.class)
public void deploy(KubernetesClientBuildItem kubernetesClient,
Capabilities capabilities,
List<KubernetesDeploymentClusterBuildItem> deploymentClusters,
Optional<SelectedKubernetesDeploymentTargetBuildItem> selectedDeploymentTarget,
OutputTargetBuildItem outputTarget,
OpenshiftConfig openshiftConfig,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

package io.quarkus.kubernetes.deployment;

import static io.quarkus.kubernetes.deployment.Constants.OPENSHIFT;

import java.util.List;
import java.util.Optional;

import io.fabric8.openshift.client.OpenShiftClient;
import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.kubernetes.client.spi.KubernetesClientBuildItem;
import io.quarkus.kubernetes.spi.GeneratedKubernetesResourceBuildItem;
import io.quarkus.kubernetes.spi.KubernetesDeploymentClusterBuildItem;

public class OpenshiftDeployer {

@BuildStep
public void checkEnvironment(Optional<SelectedKubernetesDeploymentTargetBuildItem> selectedDeploymentTarget,
List<GeneratedKubernetesResourceBuildItem> resources,
KubernetesClientBuildItem client, BuildProducer<KubernetesDeploymentClusterBuildItem> deploymentCluster) {
selectedDeploymentTarget.ifPresent(target -> {
if (!KubernetesDeploy.INSTANCE.checkSilently()) {
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!");
}
}
});
}
}

0 comments on commit 2961655

Please sign in to comment.