Access Tekton Pipelines in Java using Fabric8 Tekton Client

Rohan Kumar
ITNEXT
Published in
3 min readOct 7, 2020

--

Fabric8 Tekton Client

Fabric8 Kubernetes Client also offers very useful extensions for Istio, Knative, Tekton and Service Catalog. Since then, it has evolved a lot. Today I would be giving a quick overview of Fabric8 Tekton extension.

Getting Fabric8 Tekton Client:

You can find Tekton Client on Maven Central as usual. You can start using Tekton client by adding it as a dependency in your pom.xml :

<dependencies>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>tekton-client</artifactId>
<version>${tekton-client.version}</version>
</dependency>
</dependencies>

Most of the usage of Tekton Client is easily understandable and similar to it’s parent Fabric8 Kubernetes Client. This is a very basic top level overview of it’s usage of using v1alpha1 or v1beta1 apiVersions:

DSL entrypoints in Fabric8 Tekton Client

Listing all Pipelines in a given namespace:

Once added as a dependency, you can start using Fabric8 Tekton Client. Let’s start by listing all the Pipelineobjects. Here is how you would do it with Fabric8 Tekton client:

Listing all Pipelines in default namespace

Creating Tekton resources using Fabric8’s builders:

Since Tekton Client is based on Tekton Model which is formed via parsing go structs inside Tekton source into a JSON schema and then using sundrio on top of it. We get very useful builder objects with which we can quickly build up Tekton resources without loading anything from any Yaml manifest. Here is an example of creating a hello world Task and TaskRun :

Creating a hello world task with builders

Loading YAML Tekton manifests into Java objects:

Fabric8 Tekton Client, just like Fabric8 Kubernetes Client provides a seamless developer experience when it comes to serializing/de-serializing YAML manifests to/from Java objects. Let’s say you have a simple Pipeline like this(taken from Tekton Github repository examples):

Simple Pipeline YAML manifest

If I want to load this Pipeline into a Java object and then apply it onto Kubernetes, here is how I would do it:

Loading YAML manifest into Java object

Creating, Updating and Deleting Tekton resources:

If you’re already familiar with Fabric8 Kubernetes Client API, you won’t face any problems with standard operations. If you’re accessing some resource (for example, Task). You can access it using:

CRUD operations overview

let’s have a look at a working example of CRUD operations using Fabric8 Tekton Client. We would be loading, editing and finally deleting a Route object. Here is code for these series of operations:

CRUD operations for tekton.dev/v1beta1#Task

Creating Triggers:

Fabric8 Tekton Client recently got support for Tekton Triggers. Now you can easily define triggers of your pipelines using Fabric8 Tekton Client. Let’s consider an example, Assume you create this simple maven deployer pipeline using Fabric8 Tekton Client which deploys any Maven based application using Eclipse JKube:

Now if I want to create a TriggerTemplate , TriggerBinding and EventListener using Fabric8 Tekton Client. Here is how I would do it:

This would create all the mentioned resources. EventListener would also create a Pod which you can port forward with kubectl port-forward $(kubectl get pod -o=name -l eventlistener=jkube-listener) 8080 . This will expose your trigger for accepting connections.

This concludes my short overview of Fabric8 Tekton Client. I hope you liked it. Please try it out and provide feedback. I’ve provided all code related to this blog in this Github repository:

Join Us:

Do you like Fabric8 Kubernetes Client and want to get involved in development of project. Feel free to get involved by methods:

--

--