Skip to content

Commit

Permalink
feat: Introduce tekton support.
Browse files Browse the repository at this point in the history
  • Loading branch information
iocanel committed Oct 4, 2023
1 parent f283c4c commit ef48357
Show file tree
Hide file tree
Showing 13 changed files with 570 additions and 2 deletions.
18 changes: 17 additions & 1 deletion bom/application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2628,7 +2628,7 @@
<artifactId>quarkus-minikube</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-minikube-deployment</artifactId>
<version>${project.version}</version>
Expand All @@ -2642,6 +2642,16 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-kind-deployment</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-tekton</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-tekton-deployment</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
Expand Down Expand Up @@ -3161,6 +3171,12 @@
<version>${dekorate.version}</version>
<classifier>noapt</classifier>
</dependency>
<dependency>
<groupId>io.dekorate</groupId>
<artifactId>tekton-annotations</artifactId>
<version>${dekorate.version}</version>
<classifier>noapt</classifier>
</dependency>
<dependency>
<groupId>io.dekorate</groupId>
<artifactId>helm-annotations</artifactId>
Expand Down
1 change: 1 addition & 0 deletions extensions/kubernetes/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@
<module>minikube</module>
<module>kind</module>
<module>spi</module>
<module>tekton</module>
</modules>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

package io.quarkus.kubernetes.spi;

import java.util.Collection;

import io.quarkus.builder.item.MultiBuildItem;

public final class KubernetesAdditionalResourceBuildItem extends MultiBuildItem {

private final String name;

public KubernetesAdditionalResourceBuildItem(String name) {
this.name = name;
}

public String getName() {
return this.name;
}

public static boolean hasItem(String name, Collection<KubernetesAdditionalResourceBuildItem> items) {
return items.stream().filter(i -> name.equals(i.name)).findAny().isPresent();
}
}
57 changes: 57 additions & 0 deletions extensions/kubernetes/tekton/deployment/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?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-tekton-parent</artifactId>
<version>999-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>quarkus-tekton-deployment</artifactId>
<name>Quarkus - Kubernetes - Tekton - Deployment</name>

<dependencies>
<dependency>
<groupId>io.dekorate</groupId>
<artifactId>tekton-annotations</artifactId>
<classifier>noapt</classifier>
<exclusions>
<exclusion>
<groupId>io.sundr</groupId>
<artifactId>*</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-tekton</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>
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package io.quarkus.tekton.deployment;

import io.dekorate.deps.tekton.pipeline.v1beta1.TaskSpecFluent;
import io.dekorate.kubernetes.decorator.Decorator;
import io.dekorate.kubernetes.decorator.ResourceProvidingDecorator;
import io.dekorate.tekton.decorator.AddParamToTaskDecorator;
import io.dekorate.tekton.decorator.NamedTaskDecorator;
import io.dekorate.tekton.decorator.TaskProvidingDecorator;

/**
* Adds a param to a task.
* Similar to {@link AddParamToTaskDecorator} but is meant to be executed at a later point, so it can replace values added by
* it.
*/
public class ApplyParamToTaskDecorator extends NamedTaskDecorator {

private final String name;
private final String description;
private final String defaultValue;

public ApplyParamToTaskDecorator(String taskName, String name, String description, String defaultValue) {
super(taskName);
this.name = name;
this.description = description;
this.defaultValue = defaultValue;
}

@Override
public void andThenVisit(TaskSpecFluent<?> taskSpec) {
taskSpec.removeMatchingFromParams(p -> name.equals(p.getName()));
taskSpec.addNewParam().withName(name).withDescription(description).withNewDefault().withStringVal(defaultValue)
.endDefault().endParam();
}

@Override
public Class<? extends Decorator>[] after() {
return new Class[] { ResourceProvidingDecorator.class, TaskProvidingDecorator.class, AddParamToTaskDecorator.class };
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
package io.quarkus.tekton.deployment;

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

import io.quarkus.kubernetes.deployment.PvcVolumeConfig;
import io.quarkus.runtime.annotations.ConfigItem;
import io.quarkus.runtime.annotations.ConfigRoot;

@ConfigRoot
public class TektonConfig {

public static final String DEFAULT_DEPLOYER_IMAGE = "lachlanevenson/k8s-kubectl:v1.18.0";

public static final String DEFAULT_JVM_DOCKERFILE = "src/main/docker/Dockerfile.jvm";
public static final String DEFAULT_NATIVE_DOCKERFILE = "src/main/docker/Dockerfile.native";

/**
* Feature flag for tekton
*/
@ConfigItem(defaultValue = "true")
boolean enabled;

/**
* The name of the group this component belongs too
*/
@ConfigItem
Optional<String> partOf;

/**
* The name of the application. This value will be used for naming Kubernetes
* resources like: - Deployment - Service and so on ...
*/
@ConfigItem(defaultValue = "${quarkus.container-image.name}")
Optional<String> name;

/**
* The version of the application.
*/
@ConfigItem(defaultValue = "${quarkus.container-image.tag}")
Optional<String> version;

/**
* The namespace the generated resources should belong to. If not value is set,
* then the 'namespace' field will not be added to the 'metadata' section of the
* generated manifests. This in turn means that when the manifests are applied
* to a cluster, the namespace will be resolved from the current Kubernetes
* context (see
* https://kubernetes.io/docs/concepts/configuration/organize-cluster-access-kubeconfig/#context
* for more details).
*/
@ConfigItem
Optional<String> namespace;

/**
* Custom labels to add to all resources
*/
@ConfigItem
Map<String, String> labels;

/**
* Custom annotations to add to all resources
*/
@ConfigItem
Map<String, String> annotations;

/**
* The name of an external git pipeline resource.
*/
@ConfigItem
Optional<String> externalGitPipelineResource;

/**
* The name of the source workspace.
*/
@ConfigItem(defaultValue = "source")
Optional<String> sourceWorkspace;

/**
* The name of an external PVC to be used for the source workspace.
*/
@ConfigItem
Optional<String> externalSourceWorkspaceClaim;

/**
* The persistent volume claim configuration for the source workspace. The
* option only makes sense when the PVC is going to be generated (no external
* pvc specified).
*/
@ConfigItem
Optional<PvcVolumeConfig> sourceWorkspaceClaim;

/**
* The name of workspace to use as a maven artifact repository.
*/
@ConfigItem
Optional<String> m2Workspace;

/**
* The name of an external PVC to be used for the m2 artifact repository.
*/
@ConfigItem
Optional<String> externalM2WorkspaceClaim;

/**
* The persistent volume claim configuration for the artifact repository. The
* option only makes sense when the PVC is going to be generated (no external
* pvc specified).
*/
@ConfigItem
Optional<PvcVolumeConfig> m2WorkspaceClaim;

/**
* The builder image to use.
*/
@ConfigItem
Optional<String> builderImage;

/**
* The builder command to use.
*/
@ConfigItem
Optional<String> builderCommand;

/**
* The builder command arguments to use.
*/
@ConfigItem
Optional<List<String>> builderArguments;

/**
* The docker image to be used for the deployment task. Such image needs to have
* kubectl available.
*/
@ConfigItem(defaultValue = DEFAULT_DEPLOYER_IMAGE)
Optional<String> deployerImage;

/**
* The service account to use for the image pushing tasks. An existing or a
* generated service account can be used. If no existing service account is
* provided one will be generated based on the context.
*/
@ConfigItem
Optional<String> imagePushServiceAccount;

/**
* The secret to use when generating an image push service account. When no
* existing service account is provided, one will be generated. The generated
* service account may or may not use an existing secret.
*/
@ConfigItem
Optional<String> imagePushSecret;

/**
* Wether to upload the local `.docker/config.json` to automatically create the
* secret.
*/
@ConfigItem
boolean useLocalDockerConfigJson;

/**
* The username to use for generating image builder secrets.
*/
@ConfigItem(defaultValue = "docker.io")
Optional<String> registry;

/**
* The username to use for generating image builder secrets.
*/
Optional<String> registryUsername;

/**
* The password to use for generating image builder secrets.
*/
@ConfigItem
Optional<String> registryPassword;

/**
* The default Dockerfile to use for jvm builds
*/
@ConfigItem(defaultValue = DEFAULT_JVM_DOCKERFILE)
public String jvmDockerfile;

/**
* The default Dockerfile to use for native builds
*/
@ConfigItem(defaultValue = DEFAULT_NATIVE_DOCKERFILE)
public String nativeDockerfile;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

package io.quarkus.tekton.deployment;

import java.util.function.BooleanSupplier;

public class TektonEnabled implements BooleanSupplier {

private final TektonConfig config;

public TektonEnabled(TektonConfig config) {
this.config = config;
}

@Override
public boolean getAsBoolean() {
return config.enabled;
}
}
Loading

0 comments on commit ef48357

Please sign in to comment.