Using Jsonnet to Generate Dynamic Tekton Pipelines in Kubernetes · Mustafa Akın

submited by
Style Pass
2021-07-03 22:00:03

For the readers that might be unaware, Tekton is a cloud-native CI/CD solution. In other words, it’s a pipeline for Kubernetes that can generate DAGs (directed acyclic graph). It’s one of the most straightforward solutions to run dependent Pods and steps in Kubernetes. Tekton runs pipelines as Task CRDs (Custom Resource Definition), whereas every task can have one or more sequential steps. Also, a Task can have a dependency on another task, which allows building a DAG. Also, a Task and Pipeline can be parameterized, which allows reusing components.

In this blog post, I will take it one step further and introduce you to a methodology to generate more dynamic tasks, with the help of Jsonnet. Jsonnet is a data templating language by Google, which looks like JSON, but also allows conditionals, iterations, methods to enable writing cleaner files. Although JSON is human-readable, it’s not easily human writable when you want to lots of stuff. And also, templating Kubernetes with YAML is an abomination that I never like or accept, and tools that embrace Jsonnet makes it easy to template Kubernetes configuration files. Ksonnet is an excellent example. But you might also ask, “why the hell am I templating too much configuration for Kubernetes, I just wanted to deploy my microservice,” but that’s another topic that can start flamewars.

Tekton consists of Task, TaskRun, Pipeline, and PipelineRun objects. Tasks define the steps. Pipeline define which tasks are going to be used. PipelineRun is a Pipeline instance that you want to execute, possibly with multiple parameters as input. As we are going to use Jsonnet to generate dynamic PipelineRun’s procedurally, we are not going to use Tasks, but embed the Task spec to PipelineRun itself. The following is an example of a Pipeline with embedded Tasks:

Leave a Comment