-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
help wantedDenotes an issue that needs help from a contributor. Must meet "help wanted" guidelines.Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines.kind/miscCategorizes issue or PR as a miscellaneuous one.Categorizes issue or PR as a miscellaneuous one.
Description
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 thereconcile
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:
- Breakpoint issue: https://github.com/golang/vscode-go/wiki/debugging#my-program-does-not-stop-at-breakpoints
- Ko go build settings
-trimpath
: https://ko.build/configuration/#overriding-go-build-settings
Here are some Articles:
- https://pretired.dazwilkin.com/posts/280524
- https://alexsniffin.medium.com/debugging-remotely-in-kubernetes-with-go-fda4f3332316
- https://dchaykin.medium.com/debugging-a-go-service-in-kubernetes-f1dd48865e1d
/kind misc
waveywaves
Metadata
Metadata
Assignees
Labels
help wantedDenotes an issue that needs help from a contributor. Must meet "help wanted" guidelines.Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines.kind/miscCategorizes issue or PR as a miscellaneuous one.Categorizes issue or PR as a miscellaneuous one.
Type
Projects
Status
Done