Development Guide
December 18, 2024 ยท View on GitHub
Development Prerequisites
Getting started
- Development Guide
Ramp up
Welcome to the project!! You may find these resources helpful to ramp up on some of the technology this project is built on.
Ramp up on CRDs
This project extends Kubernetes (aka
k8s) with Custom Resource Definitions (CRDSs). To find out more:
- The Kubernetes docs on Custom Resources - These will orient you on what words like "Resource" and "Controller" concretely mean
- Understanding Kubernetes objects - This will further solidify k8s nomenclature
- API conventions - Types(kinds) - Another useful set of words describing words. "Objects" and "Lists" in k8s land
- Extend the Kubernetes API with CustomResourceDefinitions- A tutorial demonstrating how a Custom Resource Definition can be added to Kubernetes without anything actually "happening" beyond being able to list Objects of that kind
Ramp up on Tekton Pipelines
- Tekton Pipelines README - Some of the terms here may make more sense!
- Install via official installation docs or continue though getting started for development
- Tekton Pipeline "Hello World" tutorial -
Define
Tasks,Pipelines, andPipelineResources, see what happens when they are run
Ramp up on Kubernetes Operators
Checkout your fork
The Go tools require that you clone the repository to the
src/github.com/tektoncd/operator directory in your
GOPATH.
To check out this repository:
- Create your own fork of this repo
- Clone it to your machine:
mkdir -p ${GOPATH}/src/github.com/tektoncd
cd ${GOPATH}/src/github.com/tektoncd
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
Adding the upstream remote sets you up nicely for regularly
syncing your fork.
Requirements
You must install these tools:
go: The language Tekton Pipelines is built ingit: For source controldep: For managing external Go dependencies. - Please Install dep v0.5.0 or greater.kubectl: For interacting with your kube cluster
Your [$GOPATH] setting is critical for go to function properly.
Kubernetes cluster
Docker for Desktop using an edge version has been proven to work for both developing and running Pipelines. The recommended configuration is:
- Kubernetes version 1.11 or later
- 4 vCPU nodes (
n1-standard-4) - Node autoscaling, up to 3 nodes
- API scopes for cloud-platform
To setup a cluster with GKE:
-
Install required tools and setup GCP project (You may find it useful to save the ID of the project in an environment variable (e.g.
PROJECT_ID). -
Create a GKE cluster (with
--cluster-version=latestbut you can use any version 1.11 or later):export PROJECT_ID=my-gcp-project export CLUSTER_NAME=mycoolcluster gcloud container clusters create $CLUSTER_NAME \ --enable-autoscaling \ --min-nodes=1 \ --max-nodes=3 \ --scopes=cloud-platform \ --enable-basic-auth \ --no-issue-client-certificate \ --project=$PROJECT_ID \ --region=us-central1 \ --machine-type=n1-standard-4 \ --image-type=cos \ --num-nodes=1 \ --cluster-version=latestNote that the
--scopesargument togcloud container cluster createcontrols what GCP resources the cluster's default service account has access to; for example to give the default service account full access to your GCR registry, you can addstorage-fullto your--scopesarg. -
Grant cluster-admin permissions to the current user:
kubectl create clusterrolebinding cluster-admin-binding \ --clusterrole=cluster-admin \ --user=$(gcloud config get-value core/account)
Environment Setup
To run/test your operator you'll need to set these
environment variables (we recommend adding them to your .bashrc):
GOPATH: If you don't have one, simply pick a directory and addexport GOPATH=...$GOPATH/binonPATH: This is so that tooling installed viago getwill work properly.
.bashrc example:
export GOPATH="$HOME/go"
export PATH="${PATH}:${GOPATH}/bin"
Iterating
While iterating on the project, you may need to:
-
Verify it's working by looking at the logs
-
Update your (external) dependencies with:
./hack/update-deps.sh.Running dep ensure manually, will pull a bunch of scripts deleted here
-
Update your type definitions with:
./hack/update-codegen.sh.
Install Operator
Note: this needs to be completed! We don't yet have any code or config to deploy, watch this space!
Accessing logs
Note: this needs to be completed! We don't yet have any code or config to deploy, watch this space!
Running Codegen
If the files in pkg/apis are updated we need to run codegen scripts
./hack/update-codegen.sh
Setup development environment on localhost
Here are the steps to setup development environment on your localhost with local registry
Pre-requests
- either
dockerorpodmanruntime - kind
setup with docker runtime
export KO_DOCKER_REPO="localhost:5000"
make dev-setup
kubernetes cluster ports used
8443- cluster api access80- ingress http443- ingress https
setup with podman runtime
podman is a daemonless container engine. You have to setup a socket service on user space.
$ export KO_DOCKER_REPO="localhost:5000"
$ export CONTAINER_RUNTIME=podman
$ systemctl --user start podman.socket
$ export DOCKER_HOST=unix://$XDG_RUNTIME_DIR/podman/podman.sock
$ make dev-setup
kubernetes cluster ports used
8443- cluster api access7080- ingress http7443- ingress https
Running Operator (Development)
Reset (Clean) Cluster
Target: Kubernetes
make clean
Target Openshift
make TARGET=openshift clean
Setup
- Set
KO_DOCKER_REPOenvironment variable (ko#usage) - If you want to use local image rather than pushing image to registry you can set flags with
KO_FLAGS=--localwhen you run operator
Run operator
Target: Kubernetes
make apply
Target Openshift
make TARGET=openshift apply
Install Tekton components
Operator provides an option to choose which components needs to be installed by specifying profile.
profile is an optional field and supported profile are
- lite
- basic
- all
- If profile is
liteTektonPipeline will be installed - If profile is
basicTektonPipeline and TektonTrigger will be installed - If profile is
allthen all the Tekton Components installed
To create Tekton Components run
make apply-cr
make CR=config/basic apply-cr
To delete installed Tekton Components run
make clean-cr
make CR=config/basic clean-cr