Skip to content

Latest commit

 

History

History
264 lines (190 loc) · 9.51 KB

DEVELOPMENT.md

File metadata and controls

264 lines (190 loc) · 9.51 KB

Development Guide

Before you start

The Tekton Operator installs and manages the lifecycle of Tekton components (Pipelines, Triggers, Chains, Results, Dashboard, Pipelines as Code and more) on Kubernetes and OpenShift through a set of custom resources. For an overview of what it manages and how it is structured, see docs/TektonOperator.md.

Install these tools before you begin:

Tool Why Check
go Builds the operator (see go.mod for the minimum version) go version
git Source control git --version
kubectl Talks to the cluster kubectl version --client
ko Builds and deploys the operator images ko version
kustomize Renders the deployment manifests kustomize version
kind Runs the local development cluster kind version
docker or podman Container runtime docker version / podman version

ko and kustomize are installed automatically into .bin/ by the make targets if they are not already on your PATH.

Quick start with kind

This is the supported and tested development path. It gives you a local kind cluster, a local image registry and a running operator in a few commands.

  1. Fork this repository and clone your fork, then add the upstream remote so you can sync later:

    git clone git@github.com:${YOUR_GITHUB_USERNAME}/operator.git
    cd operator
    git remote add upstream git@github.com:tektoncd/operator.git
    git remote set-url --push upstream no_push
  2. Point ko at the local registry that make dev-setup creates:

    export KO_DOCKER_REPO="localhost:5000"
  3. Create the cluster, the registry and deploy the operator:

    make dev-setup

    make dev-setup creates a kind cluster with a local registry and then runs make apply for you, so the operator is deployed by the time it finishes. It prints the location of the generated kubeconfig at the end.

  4. Point kubectl at the new cluster:

    export KUBECONFIG="${HOME}/.kube/config.kind"
  5. Install the Tekton components by creating a TektonConfig custom resource:

    make apply-cr
  6. Verify it worked. The operator pods should be Running in the tekton-operator namespace, the TektonConfig should reconcile, and the components should come up in tekton-pipelines:

    kubectl get pods -n tekton-operator
    kubectl get tektonconfig
    kubectl get pods -n tekton-pipelines

Ports used by the kind cluster (docker runtime):

  • 8443 - cluster API access
  • 80 - ingress http
  • 443 - ingress https

If a step fails, see Troubleshooting.

The development loop

After you change code, rebuild and redeploy the operator with:

make apply

make apply uses ko to build images, push them to KO_DOCKER_REPO and apply the manifests. To build and load images locally without pushing to a registry, add KO_FLAGS=--local:

make KO_FLAGS=--local apply

Choosing which components to install

make apply-cr creates the TektonConfig CR that tells the operator which components to install, selected by profile:

  • lite — installs TektonPipeline
  • basic — installs TektonPipeline and TektonTrigger (the default)
  • all — installs all Tekton components

Select a profile with the CR variable:

make CR=config/lite apply-cr
make CR=config/basic apply-cr
make CR=config/all apply-cr

Reading operator logs

kubectl logs -n tekton-operator deploy/tekton-operator -f

Resetting the cluster

Remove the installed components, then the operator:

make clean-cr
make clean

Testing

The PR template asks you to run make test lint before submitting. Both run without a cluster.

  • Unit tests:

    make test
  • Linters (golangci-lint and yamllint):

    make lint

    To lint a single Go package, pass PKG, for example make lint-go PKG=./pkg/reconciler/kubernetes/tektonpipeline/....

  • End-to-end tests require a live cluster and take longer to run. See the test documentation for how to run them and what they need.

Code generation

Run code generation whenever you change the API types under pkg/apis:

./hack/update-codegen.sh

This regenerates the deepcopy functions and the typed client, informers and listers for the operator API group. Never hand-edit generated files — rerun the script instead, and commit the results alongside your API change.

Updating dependencies

After changing go.mod, refresh the vendored dependencies:

./hack/update-deps.sh

Developing for OpenShift

The same targets work against OpenShift by setting TARGET=openshift:

make TARGET=openshift apply
make TARGET=openshift clean

The OpenShift path deploys OpenShift-specific manifests and components (for example TektonAddon) that do not exist on the Kubernetes path. If you use podman as your container runtime, it is daemonless and needs a user-space socket before you build images:

export CONTAINER_RUNTIME=podman
systemctl --user start podman.socket
export DOCKER_HOST="unix://$XDG_RUNTIME_DIR/podman/podman.sock"

With the podman runtime the kind cluster uses ports 8443 (API), 7080 (ingress http) and 7443 (ingress https).

Other clusters

kind is the supported, tested development path. Any conformant cluster also works if it meets the requirements:

  • Kubernetes 1.28 or newer (see the compatibility matrix in the README)
  • cluster-admin privileges
  • enough capacity to run the operator and the components you install

Use your provider's own documentation to create the cluster (GKE, EKS, AKS), then follow The development loop. Detailed, provider-specific walkthroughs are being moved out of this repo and will be published as dated blog posts on tekton.dev, where they can be updated without a repo change.

Troubleshooting

  • KO_DOCKER_REPO unset or wrong. make apply fails to push images. Export KO_DOCKER_REPO="localhost:5000" for the local kind registry, or use make KO_FLAGS=--local apply to skip pushing entirely.
  • Image pull failures against the local registry. Confirm the registry container is running (docker ps | grep kind-registry) and reachable at localhost:5000. Rerun make dev-setup if the cluster and registry are out of sync.
  • podman socket not running. Start it with systemctl --user start podman.socket and export DOCKER_HOST="unix://$XDG_RUNTIME_DIR/podman/podman.sock" before building.
  • Port conflicts. The kind cluster binds 8443, and 80/443 (docker) or 7080/7443 (podman). Free the port or stop the conflicting service before running make dev-setup.
  • Operator pod crashlooping. Check its logs first: kubectl logs -n tekton-operator deploy/tekton-operator.
  • Stale CRDs after switching branches. Run make clean followed by make apply to re-apply the manifests for the current branch.

Contributing your change

Additional resources

These help you ramp up on the technology the operator is built on:

Ramp up on Custom Resource Definitions (CRDs), which this project uses to extend Kubernetes:

Ramp up on Tekton and Kubernetes operators: