heidloff.net - Building is my Passion
Post
Cancel

Debugging Tekton on OpenShift

In this blog I explain briefly how to ‘debug’ Tekton tasks.

In my previous article Sample Tekton Pipelines for Microservices I described how to deploy microservices to OpenShift using Tekton. Running pipelines can take quite some time, since tasks run in different containers and data needs to be passed between them. So it is often desirable to run only specific tasks and steps and to pass in context.

Sebastian Daschner has created a great video about a mechanism to run basically only a specific task. The challenge though is how to pass in the right context. For example for most tasks at a minimum you need to clone the repo first.

The trick is to use a task with a step that starts a container but puts it in sleep mode:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
  name: debug-task
  labels:
    app.kubernetes.io/version: "0.3"
  annotations:
    tekton.dev/pipelines.minVersion: "0.21.0"
    tekton.dev/displayName: "debug-task"
spec:
  description: >-
    debug-task
  params:
    - name: project-name
    - name: app-git-url
  workspaces:
    - name: app-source
  steps:
    - name: debug-task
      image: alpine/git:v2.26.2
      workingDir: "$(workspaces.app-source.path)"
      command: ["sleep", "infinity"]

Rather than running a complete pipeline, only the task can be run:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
apiVersion: tekton.dev/v1beta1
kind: TaskRun
metadata:
  name: debug-task-run
spec:
  taskRef:
    name: debug-task
  params:
  - name: project-name
    value: 'app-mod-tekton-dev'
  - name: app-git-url
    value: 'https://github.com/IBM/application-modernization-javaee-quarkus'
  workspaces:
  - name: app-source
    emptyDir: {}

The complete code is in my application modernization repo.

Here are the commands to redeploy the task and the task run:

1
2
3
4
$ oc delete -f debug/debug-task.yaml
$ oc delete -f debug/debug-task-run.yaml
$ oc apply -f debug/debug-task.yaml
$ oc apply -f debug/debug-task-run.yaml

In order to debug the task, you can ‘exec’ into the pod’s container:

1
2
POD_NAME=$(oc get pods -n app-mod-tekton-dev | awk '/debug-task-run-pod/ {print $1;exit}')
kubectl exec -t -i $POD_NAME /bin/sh

If you want to learn more about Tekton, ArgoCD and application modernization, check out my repo.

Featured Blog Posts
Disclaimer
The postings on this site are my own and don’t necessarily represent IBM’s positions, strategies or opinions.
Trending Tags