Skip to content

Configure delve debugger for Tekton controller in VSCode. #8876

@twoGiants

Description

@twoGiants

Summary

While developing the Tekton controller it is sometimes necessary to use the debugger to investigate complex issues. So far this is done mostly via logs.

This is a step by step instruction on how to setup debugging for Tekton controllers.

We can use the following configuration to start the controller with delve enabled:

  • comment out the probes in the controller.yaml
        # livenessProbe:
        #   httpGet:
        #     path: /health
        #     port: probes
        #     scheme: HTTP
        #   initialDelaySeconds: 5
        #   periodSeconds: 10
        #   timeoutSeconds: 5
        # readinessProbe:
        #   httpGet:
        #     path: /readiness
        #     port: probes
        #     scheme: HTTP
        #   initialDelaySeconds: 5
        #   periodSeconds: 10
        #   timeoutSeconds: 5
  • build the controller with delve using:
ko apply -f config/controller.yaml --debug --disable-optimizations
  • port forward connections to the controller
kubectl port-forward -n tekton-pipelines pod/tekton-pipelines-controller-XXX-YYY 40000:40000
  • create a launch.json to connect to delve in the cluster:
{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Attach to Delve (Tekton Controller)",
      "type": "go",
      "request": "attach",
      "mode": "remote",
      "port": 40000,
      "host": "127.0.0.1",
      "apiVersion": 2,
      "substitutePath": [
        {
          "from": "${workspaceFolder}",
          "to": "github.com/tektoncd/pipeline"
        }
      ]
    }
  ]
}
  • add breakpoints to pipelinerun.go for example in the reconcile method
  • attach debugger in VSCode
  • run a hello world PipelineRun
kubectl create -f - <<EOF
apiVersion: tekton.dev/v1
kind: PipelineRun
metadata:
  generateName: hello-embedded-run-
spec:
  pipelineSpec:
    tasks:
      - name: hello-task
        taskSpec:
          steps:
            - name: hello-step
              image: alpine
              script: |
                echo "Hello from embedded pipelineSpec!"
EOF

Additional Info

You can change the base image in .ko.yaml for the controller so that you can exec into the controller and investigate the binary which ko created.

baseImageOverrides:
  # ...
  github.com/tektoncd/pipeline/cmd/controller: cgr.dev/chainguard/go:latest-dev

When you exec into the controller pod, yo can go into the ko-app directory and investigate the binary a bit, then you know what paths the binary uses for the different files where the breakpoints are set.

kubectl exec -it -n tekton-pipelines tekton-pipelines-controller-XXX-YYY -- /bin/sh

Inside the container:

cd ko-app
strings controller | grep pipelinerun.go
github.com/tektoncd/pipeline/pkg/client/clientset/versioned/typed/pipeline/v1/pipelinerun.go
github.com/tektoncd/pipeline/pkg/client/clientset/versioned/typed/pipeline/v1beta1/pipelinerun.go
github.com/tektoncd/pipeline/pkg/client/listers/pipeline/v1/pipelinerun.go
github.com/tektoncd/pipeline/pkg/client/informers/externalversions/pipeline/v1/pipelinerun.go
github.com/tektoncd/pipeline/pkg/client/listers/pipeline/v1beta1/pipelinerun.go
github.com/tektoncd/pipeline/pkg/client/informers/externalversions/pipeline/v1beta1/pipelinerun.go
github.com/tektoncd/pipeline/pkg/client/injection/informers/pipeline/v1/pipelinerun/pipelinerun.go
github.com/tektoncd/pipeline/pkg/reconciler/pipelinerun/pipelinerun.go

Resources

VSCode Go debugging:

Here are some Articles:


/kind misc

Metadata

Metadata

Assignees

Labels

help wantedDenotes an issue that needs help from a contributor. Must meet "help wanted" guidelines.kind/miscCategorizes issue or PR as a miscellaneuous one.

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions