Skip to content

Commit

Permalink
Merge pull request #24449 from gsmet/kind-support
Browse files Browse the repository at this point in the history
Introduce Kind extension that supports autoloading
  • Loading branch information
gsmet authored Mar 21, 2022
2 parents c9b15fb + dc05461 commit 7d435c8
Show file tree
Hide file tree
Showing 19 changed files with 500 additions and 98 deletions.
10 changes: 10 additions & 0 deletions bom/application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2392,6 +2392,16 @@
<artifactId>quarkus-minikube-deployment</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-kind</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-kind-deployment</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-kubernetes-client</artifactId>
Expand Down
13 changes: 13 additions & 0 deletions devtools/bom-descriptor-json/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1085,6 +1085,19 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-kind</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-kotlin</artifactId>
Expand Down
13 changes: 13 additions & 0 deletions docs/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1045,6 +1045,19 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-kind-deployment</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-kotlin-deployment</artifactId>
Expand Down
15 changes: 15 additions & 0 deletions docs/src/main/asciidoc/deploying-to-kubernetes.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,21 @@ only. When deploying to production, consider using the vanilla Kubernetes manife
NOTE: If the assumptions the Minikube extension makes don't fit your workflow, nothing prevents you from using the regular Kubernetes extension to generate Kubernetes manifests
and apply those to your Minikube cluster.

=== Deploying to Kind
https://kind.sigs.k8s.io/[Kind] is an other popular tool used as a Kubernetes cluster for development purposes. To make the deployment to Kind
experience as frictionless as possible, Quarkus provides the `quarkus-kind` extension. This extension can be added to a project like so:

[source,xml]
----
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-kind</artifactId>
</dependency>
----

The purpose of this extension is to generate Kubernetes manifests (`kind.yaml` and `kind.json`) that are tailored to Kind and also to automate the process of loading images to the cluster
when performing container image builds. The tailor made manifests will be pretty similar (they share the same rules) with Minikube (see above).

== Tuning the generated resources using application.properties

The Kubernetes extension allows tuning the generated manifest, using the `application.properties` file.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import io.quarkus.container.image.deployment.util.NativeBinaryUtil;
import io.quarkus.container.spi.AvailableContainerImageExtensionBuildItem;
import io.quarkus.container.spi.ContainerImageBuildRequestBuildItem;
import io.quarkus.container.spi.ContainerImageBuilderBuildItem;
import io.quarkus.container.spi.ContainerImageInfoBuildItem;
import io.quarkus.container.spi.ContainerImageLabelBuildItem;
import io.quarkus.container.spi.ContainerImagePushRequestBuildItem;
Expand Down Expand Up @@ -67,7 +68,8 @@ public void buildFromJar(ContainerImageConfig containerImageConfig, BuildpackCon
Optional<ContainerImagePushRequestBuildItem> pushRequest,
List<ContainerImageLabelBuildItem> containerImageLabels,
Optional<AppCDSResultBuildItem> appCDSResult,
BuildProducer<ArtifactResultBuildItem> artifactResultProducer) {
BuildProducer<ArtifactResultBuildItem> artifactResultProducer,
BuildProducer<ContainerImageBuilderBuildItem> containerImageBuilder) {

if (containerImageConfig.isBuildExplicitlyDisabled()) {
return;
Expand All @@ -84,6 +86,7 @@ public void buildFromJar(ContainerImageConfig containerImageConfig, BuildpackCon

artifactResultProducer.produce(new ArtifactResultBuildItem(null, "jar-container",
Collections.singletonMap("container-image", targetImageName)));
containerImageBuilder.produce(new ContainerImageBuilderBuildItem(BUILDPACK));
}

@BuildStep(onlyIf = { IsNormalNotRemoteDev.class, BuildpackBuild.class, NativeBuild.class })
Expand All @@ -94,7 +97,8 @@ public void buildFromNative(ContainerImageConfig containerImageConfig, Buildpack
Optional<ContainerImageBuildRequestBuildItem> buildRequest,
Optional<ContainerImagePushRequestBuildItem> pushRequest,
List<ContainerImageLabelBuildItem> containerImageLabels,
BuildProducer<ArtifactResultBuildItem> artifactResultProducer) {
BuildProducer<ArtifactResultBuildItem> artifactResultProducer,
BuildProducer<ContainerImageBuilderBuildItem> containerImageBuilder) {

if (containerImageConfig.isBuildExplicitlyDisabled()) {
return;
Expand All @@ -116,6 +120,7 @@ public void buildFromNative(ContainerImageConfig containerImageConfig, Buildpack

artifactResultProducer.produce(new ArtifactResultBuildItem(null, "native-container",
Collections.singletonMap("container-image", targetImageName)));
containerImageBuilder.produce(new ContainerImageBuilderBuildItem(BUILDPACK));
}

private Map<ProjectDirs, Path> getPaths(OutputTargetBuildItem outputTarget) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import io.quarkus.container.image.deployment.util.NativeBinaryUtil;
import io.quarkus.container.spi.AvailableContainerImageExtensionBuildItem;
import io.quarkus.container.spi.ContainerImageBuildRequestBuildItem;
import io.quarkus.container.spi.ContainerImageBuilderBuildItem;
import io.quarkus.container.spi.ContainerImageInfoBuildItem;
import io.quarkus.container.spi.ContainerImagePushRequestBuildItem;
import io.quarkus.deployment.IsDockerWorking;
Expand Down Expand Up @@ -71,6 +72,7 @@ public void dockerBuildFromJar(DockerConfig dockerConfig,
Optional<ContainerImagePushRequestBuildItem> pushRequest,
@SuppressWarnings("unused") Optional<AppCDSResultBuildItem> appCDSResult, // ensure docker build will be performed after AppCDS creation
BuildProducer<ArtifactResultBuildItem> artifactResultProducer,
BuildProducer<ContainerImageBuilderBuildItem> containerImageBuilder,
PackageConfig packageConfig,
@SuppressWarnings("unused") // used to ensure that the jar has been built
JarBuildItem jar) {
Expand Down Expand Up @@ -109,6 +111,7 @@ public void dockerBuildFromJar(DockerConfig dockerConfig,
// locally before pushing it to the registry
artifactResultProducer.produce(new ArtifactResultBuildItem(null, "jar-container",
Map.of("container-image", builtContainerImage, "pull-required", "false")));
containerImageBuilder.produce(new ContainerImageBuilderBuildItem(DOCKER));
}

@BuildStep(onlyIf = { IsNormalNotRemoteDev.class, NativeBuild.class, DockerBuild.class })
Expand All @@ -120,6 +123,7 @@ public void dockerBuildFromNativeImage(DockerConfig dockerConfig,
OutputTargetBuildItem out,
Optional<UpxCompressedBuildItem> upxCompressed, // used to ensure that we work with the compressed native binary if compression was enabled
BuildProducer<ArtifactResultBuildItem> artifactResultProducer,
BuildProducer<ContainerImageBuilderBuildItem> containerImageBuilder,
PackageConfig packageConfig,
// used to ensure that the native binary has been built
NativeImageBuildItem nativeImage) {
Expand Down Expand Up @@ -149,6 +153,8 @@ public void dockerBuildFromNativeImage(DockerConfig dockerConfig,
// locally before pushing it to the registry
artifactResultProducer.produce(new ArtifactResultBuildItem(null, "native-container",
Map.of("container-image", builtContainerImage, "pull-required", "false")));

containerImageBuilder.produce(new ContainerImageBuilderBuildItem(DOCKER));
}

private String createContainerImage(ContainerImageConfig containerImageConfig, DockerConfig dockerConfig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import io.quarkus.container.image.deployment.util.NativeBinaryUtil;
import io.quarkus.container.spi.AvailableContainerImageExtensionBuildItem;
import io.quarkus.container.spi.ContainerImageBuildRequestBuildItem;
import io.quarkus.container.spi.ContainerImageBuilderBuildItem;
import io.quarkus.container.spi.ContainerImageInfoBuildItem;
import io.quarkus.container.spi.ContainerImageLabelBuildItem;
import io.quarkus.container.spi.ContainerImagePushRequestBuildItem;
Expand Down Expand Up @@ -134,7 +135,8 @@ public void buildFromJar(ContainerImageConfig containerImageConfig, JibConfig ji
Optional<ContainerImagePushRequestBuildItem> pushRequest,
List<ContainerImageLabelBuildItem> containerImageLabels,
Optional<AppCDSResultBuildItem> appCDSResult,
BuildProducer<ArtifactResultBuildItem> artifactResultProducer) {
BuildProducer<ArtifactResultBuildItem> artifactResultProducer,
BuildProducer<ContainerImageBuilderBuildItem> containerImageBuilder) {

boolean buildContainerImage = buildContainerImageNeeded(containerImageConfig, buildRequest);
boolean pushContainerImage = pushContainerImageNeeded(containerImageConfig, pushRequest);
Expand Down Expand Up @@ -168,6 +170,7 @@ public void buildFromJar(ContainerImageConfig containerImageConfig, JibConfig ji
artifactResultProducer.produce(new ArtifactResultBuildItem(null, "jar-container",
Map.of("container-image", container.getTargetImage().toString(), "pull-required",
Boolean.toString(pushContainerImage))));
containerImageBuilder.produce(new ContainerImageBuilderBuildItem(JIB));
}

@BuildStep(onlyIf = { IsNormalNotRemoteDev.class, JibBuild.class, NativeBuild.class })
Expand All @@ -179,7 +182,8 @@ public void buildFromNative(ContainerImageConfig containerImageConfig, JibConfig
Optional<ContainerImagePushRequestBuildItem> pushRequest,
List<ContainerImageLabelBuildItem> containerImageLabels,
Optional<UpxCompressedBuildItem> upxCompressed, // used to ensure that we work with the compressed native binary if compression was enabled
BuildProducer<ArtifactResultBuildItem> artifactResultProducer) {
BuildProducer<ArtifactResultBuildItem> artifactResultProducer,
BuildProducer<ContainerImageBuilderBuildItem> containerImageBuilder) {

boolean buildContainerImage = buildContainerImageNeeded(containerImageConfig, buildRequest);
boolean pushContainerImage = pushContainerImageNeeded(containerImageConfig, pushRequest);
Expand All @@ -206,6 +210,7 @@ public void buildFromNative(ContainerImageConfig containerImageConfig, JibConfig
artifactResultProducer.produce(new ArtifactResultBuildItem(null, "native-container",
Map.of("container-image", container.getTargetImage().toString(), "pull-required",
"" + pushContainerImage)));
containerImageBuilder.produce(new ContainerImageBuilderBuildItem(JIB));
}

private JibContainer containerize(ContainerImageConfig containerImageConfig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import io.quarkus.container.spi.AvailableContainerImageExtensionBuildItem;
import io.quarkus.container.spi.BaseImageInfoBuildItem;
import io.quarkus.container.spi.ContainerImageBuildRequestBuildItem;
import io.quarkus.container.spi.ContainerImageBuilderBuildItem;
import io.quarkus.container.spi.ContainerImageInfoBuildItem;
import io.quarkus.container.spi.ContainerImagePushRequestBuildItem;
import io.quarkus.deployment.IsNormalNotRemoteDev;
Expand Down Expand Up @@ -222,6 +223,7 @@ public void openshiftBuildFromJar(OpenshiftConfig openshiftConfig,
Optional<ContainerImageBuildRequestBuildItem> buildRequest,
Optional<ContainerImagePushRequestBuildItem> pushRequest,
BuildProducer<ArtifactResultBuildItem> artifactResultProducer,
BuildProducer<ContainerImageBuilderBuildItem> containerImageBuilder,
// used to ensure that the jar has been built
JarBuildItem jar) {

Expand Down Expand Up @@ -265,6 +267,7 @@ public void openshiftBuildFromJar(OpenshiftConfig openshiftConfig,
jar.getPath());
}
artifactResultProducer.produce(new ArtifactResultBuildItem(null, "jar-container", Collections.emptyMap()));
containerImageBuilder.produce(new ContainerImageBuilderBuildItem(OPENSHIFT));
}

private String getContextRoot(String outputDirName, boolean isFastJar, BuildStrategy buildStrategy) {
Expand All @@ -287,6 +290,7 @@ public void openshiftBuildFromNative(OpenshiftConfig openshiftConfig, S2iConfig
Optional<ContainerImageBuildRequestBuildItem> buildRequest,
Optional<ContainerImagePushRequestBuildItem> pushRequest,
BuildProducer<ArtifactResultBuildItem> artifactResultProducer,
BuildProducer<ContainerImageBuilderBuildItem> containerImageBuilder,
NativeImageBuildItem nativeImage) {

OpenshiftConfig config = mergeConfig(openshiftConfig, s2iConfig);
Expand Down Expand Up @@ -321,6 +325,7 @@ public void openshiftBuildFromNative(OpenshiftConfig openshiftConfig, S2iConfig
createContainerImage(kubernetesClient, openshiftYml.get(), config, contextRoot, out.getOutputDirectory(),
nativeImage.getPath());
artifactResultProducer.produce(new ArtifactResultBuildItem(null, "native-container", Collections.emptyMap()));
containerImageBuilder.produce(new ContainerImageBuilderBuildItem(OPENSHIFT));
}

public static void createContainerImage(KubernetesClientBuildItem kubernetesClient,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import io.quarkus.container.spi.AvailableContainerImageExtensionBuildItem;
import io.quarkus.container.spi.BaseImageInfoBuildItem;
import io.quarkus.container.spi.ContainerImageBuildRequestBuildItem;
import io.quarkus.container.spi.ContainerImageBuilderBuildItem;
import io.quarkus.container.spi.ContainerImageInfoBuildItem;
import io.quarkus.container.spi.ContainerImagePushRequestBuildItem;
import io.quarkus.deployment.IsNormalNotRemoteDev;
Expand Down Expand Up @@ -176,6 +177,7 @@ public void s2iBuildFromJar(S2iConfig s2iConfig, ContainerImageConfig containerI
Optional<ContainerImageBuildRequestBuildItem> buildRequest,
Optional<ContainerImagePushRequestBuildItem> pushRequest,
BuildProducer<ArtifactResultBuildItem> artifactResultProducer,
BuildProducer<ContainerImageBuilderBuildItem> containerImageBuilder,
// used to ensure that the jar has been built
JarBuildItem jar) {

Expand Down Expand Up @@ -206,6 +208,7 @@ public void s2iBuildFromJar(S2iConfig s2iConfig, ContainerImageConfig containerI
createContainerImage(kubernetesClient, openshiftYml.get(), s2iConfig, out.getOutputDirectory(), jar.getPath(),
out.getOutputDirectory().resolve("lib"));
artifactResultProducer.produce(new ArtifactResultBuildItem(null, "jar-container", Collections.emptyMap()));
containerImageBuilder.produce(new ContainerImageBuilderBuildItem(S2I));
}

@BuildStep(onlyIf = { IsNormalNotRemoteDev.class, S2iBuild.class, NativeBuild.class })
Expand All @@ -217,6 +220,7 @@ public void s2iBuildFromNative(S2iConfig s2iConfig, ContainerImageConfig contain
Optional<ContainerImageBuildRequestBuildItem> buildRequest,
Optional<ContainerImagePushRequestBuildItem> pushRequest,
BuildProducer<ArtifactResultBuildItem> artifactResultProducer,
BuildProducer<ContainerImageBuilderBuildItem> containerImageBuilder,
NativeImageBuildItem nativeImage) {

if (containerImageConfig.isBuildExplicitlyDisabled()) {
Expand Down Expand Up @@ -246,6 +250,7 @@ public void s2iBuildFromNative(S2iConfig s2iConfig, ContainerImageConfig contain
createContainerImage(kubernetesClient, openshiftYml.get(), s2iConfig, out.getOutputDirectory(),
nativeImage.getPath());
artifactResultProducer.produce(new ArtifactResultBuildItem(null, "native-container", Collections.emptyMap()));
containerImageBuilder.produce(new ContainerImageBuilderBuildItem(S2I));
}

public static void createContainerImage(KubernetesClientBuildItem kubernetesClient,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

package io.quarkus.container.spi;

import io.quarkus.builder.item.MultiBuildItem;

/**
* A {@link MultiBuildItem} that represents eligible container image builders.
* Some extension have a dependency on external services (e.g. openshift and s2i).
* So, the persennce of the extension alone is not enough to let the build system know that extension is usable.
* This build item is produced only when all environment requirements are met.
*/
public final class ContainerImageBuilderBuildItem extends MultiBuildItem {

private final String builder;

public ContainerImageBuilderBuildItem(String builder) {
this.builder = builder;
}

public String getBuilder() {
return builder;
}
}
42 changes: 42 additions & 0 deletions extensions/kubernetes/kind/deployment/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-kind-parent</artifactId>
<version>999-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>quarkus-kind-deployment</artifactId>
<name>Quarkus - Kubernetes - Kind - Deployment</name>

<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-kind</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-kubernetes-deployment</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-extension-processor</artifactId>
<version>${project.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
</project>
Loading

0 comments on commit 7d435c8

Please sign in to comment.