- Ramp up on kubernetes and CRDs
- Create a GitHub account
- Setup GitHub access via SSH
- Set up your development environment
- Create and checkout a repo fork
- Set up a Kubernetes cluster
- Configure kubectl to use your cluster
- Set up a docker repository you can push to
Then you can iterate (including
running the controllers with ko
).
Welcome to the project!! You may find these resources helpful to ramp up on some
of the technology this project is built on. This project extends Kubernetes (aka
k8s
) with Custom Resource Definitions (CRDs). 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
At this point, you may find it useful to return to these Tekton Pipeline
docs:
- Tekton Pipeline README - Some of the terms here may make more sense!
- Install via official installation docs or continue through getting started for development
- Tekton Pipeline "Hello World" tutorial -
Define
Tasks
,Pipelines
, andPipelineResources
, see what happens when they are run
You must install these tools:
-
git
: For source control -
go
: The language Tekton Pipelines is built in. You need go version v1.15 or higher.
Your [$GOPATH
] setting is critical for ko apply
to function properly: a
successful run will typically involve building pushing images instead of only
configuring Kubernetes resources.
To run your controllers with ko
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/bin
onPATH
: This is so that tooling installed viago get
will work properly.KO_DOCKER_REPO
: The docker repository to which developer images should be pushed (e.g.gcr.io/[gcloud-project]
). You can also run a local registry and setKO_DOCKER_REPO
to reference the registry (e.g. atlocalhost:5000/mypipelineimages
).
.bashrc
example:
export GOPATH="$HOME/go"
export PATH="${PATH}:${GOPATH}/bin"
export KO_DOCKER_REPO='gcr.io/my-gcloud-project-name'
Make sure to configure
authentication
for your KO_DOCKER_REPO
if required. To be able to push images to
gcr.io/<project>
, you need to run this once:
gcloud auth configure-docker
After setting GOPATH
and putting $GOPATH/bin
on your PATH
, you must then install these tools:
-
ko
: For development.ko
version v0.5.1 or higher is required forpipeline
to work correctly. -
kubectl
: For interacting with your kube cluster
The user you are using to interact with your k8s cluster must be a cluster admin to create role bindings:
# Using gcloud to get your current user
USER=$(gcloud config get-value core/account)
# Make that user a cluster admin
kubectl create clusterrolebinding cluster-admin-binding \
--clusterrole=cluster-admin \
--user="${USER}"
- To install into a different namespace you can use this script :
#!/usr/bin/env bash
set -e
# Set your target namespace here
TARGET_NAMESPACE=new-target-namespace
ko resolve -f config | sed -e '/kind: Namespace/!b;n;n;s/:.*/: '"${TARGET_NAMESPACE}"'/' | \
sed "s/namespace: tekton-pipelines$/namespace: ${TARGET_NAMESPACE}/" | \
kubectl apply -f-
kubectl set env deployments --all SYSTEM_NAMESPACE=${TARGET_NAMESPACE} -n ${TARGET_NAMESPACE}
The Go tools require that you clone the repository to the
src/github.com/tektoncd/pipeline
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 [email protected]:${YOUR_GITHUB_USERNAME}/pipeline.git
cd pipeline
git remote add upstream [email protected]:tektoncd/pipeline.git
git remote set-url --push upstream no_push
Adding the upstream
remote sets you up nicely for regularly
syncing your fork.
The recommended configuration is:
- Kubernetes version 1.16 or later
- 4 vCPU nodes (
n1-standard-4
) - Node autoscaling, up to 3 nodes
- API scopes for cloud-platform
- Follow instructions for your platform to Install Minikube and start a session as follows:
minikube start eval $(minikube docker-env)
Docker Desktop versions come integrated with an edge version of Kubernetes that has been proven to work for both developing and running Pipelines. To find out what Kubernetes a specific version of Docker Desktop includes, please refer to the release notes for your platform here: https://docs.docker.com/.
To enable the Kubernetes that comes with Docker Desktop:
-
From the Docker Desktop dropdown menu, open the
preferences...
interface. -
Under the
Resources
tab ensure that in theADVANCED
menuitem you have at allocated at least 4 CPUs, 8.0 GiB Memory, and 1.0 GiB Swap. -
Under the
Kubernetes
tab, check theEnable Kubernetes
box.- Note: the Kubernetes version Docker Desktop will use is displayed at the top of the window.
-
Click the
Apply and Restart
button to save the preferences. -
Switch the proper
kubectl
config context:kubectl config get-contexts # You should see docker-for-desktop in the previous command output kubectl config use-context docker-for-desktop
- Note: Docker Desktop menu provides a
Kubernetes
menuitem that allows you to select between contexts which is equivalent to thekubectl
command.
- Note: Docker Desktop menu provides a
-
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=latest
but you can use any version 1.16 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=1.16
Note that the
--scopes
argument togcloud container cluster create
controls 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-full
to your--scopes
arg. -
Grant cluster-admin permissions to the current user:
kubectl create clusterrolebinding cluster-admin-binding \ --clusterrole=cluster-admin \ --user=$(gcloud config get-value core/account)
While iterating on the project, you may need to:
- Install/Run everything
- Verify it's working by looking at the logs
- Update your (external) dependencies with:
./hack/update-deps.sh
. - Update your type definitions with:
./hack/update-codegen.sh
. - Add new CRD types
- Add and run tests
To make changes to these CRDs, you will probably interact with:
- The CRD type definitions in ./pkg/apis/pipeline/alpha1
- The reconcilers in ./pkg/reconciler
- The clients are in ./pkg/client (these are generated by
./hack/update-codegen.sh
)
You can stand up a version of this controller on-cluster (to your kubectl config current-context
):
ko apply -f config/
As you make changes to the code, you can redeploy your controller with:
ko apply -f config/controller.yaml
You can clean up everything with:
ko delete -f config/
To look at the controller logs, run:
kubectl -n tekton-pipelines logs $(kubectl -n tekton-pipelines get pods -l app=tekton-pipelines-controller -o name)
To look at the webhook logs, run:
kubectl -n tekton-pipelines logs $(kubectl -n tekton-pipelines get pods -l app=tekton-pipelines-webhook -o name)
To look at the logs for individual TaskRuns
or PipelineRuns
, see
docs on accessing logs.
If you need to add a new CRD type, you will need to add:
- A yaml definition in config/
- Add the type to the cluster roles in:
- Add go structs for the types in pkg/apis/pipeline/v1alpha1 e.g condition_types.go This should implement the Defaultable and Validatable interfaces as they are needed for the webhook in the next step.
- Register it with the webhook
- Add the new type to the list of known types