Skip to content

Latest commit

 

History

History
153 lines (105 loc) · 4.54 KB

DEVELOPMENT.md

File metadata and controls

153 lines (105 loc) · 4.54 KB

Development

Requirements

You must install these tools:

  1. go: The language Pipeline CRD is built in
  2. git: For source control
  3. dep: For managing external Go dependencies. - Please Install dep v0.5.0 or greater.
  4. ko: For development.
  5. kubectl: For interacting with your kube cluster
  6. kubebuilder
  7. kustomize

Update vendoring

Use dep to update dependencies:

dep ensure

Updating code generation

To update the generated client-go libs:

./hack/update-codegen.sh

The controllers

This repo contains 3 implementations of the cat controller:

Description

The Cat controller watches for Cat resources to be created. When they are, it creates a Deployment of an nginx service with the same name as the Cat.

Interestingly, kubebuilder would not allow me to create a resource called Cat, so in the kubebuilder version the CRD is called Feline instead.

client-go controllers

Deploying

The controllers can be built and deployed with ko, which requires the environment variable KO_DOCKER_REGISTRY to be set to a docker registry you can push to (i.e. one you've logged into using docker login or via gcloud):

# This currenly deploys only the well-factored controller.
# We can't really run both b/c they'll try to reconcile the same objects.
ko apply -f client-go/config/

You can remove it with:

ko delete -f client-go/config/

You can get controller logs with:

kubectl -n cattopia logs $(kubectl -n cattopia get pods -l app=cat-controller -o name)
Running locally

You can run the controllers locally by building it with go and running the binary directly:

# Add the CRD def'n to your k8s cluster
kubectl apply -f client-go/config/300-cat.yaml

# Build one of the controllers and run it locally
go build -o cat-controller ./client-go/cmd/coupled-controller
# or 
go build -o cat-controller ./client-go/cmd/factored-controller

# Run the built controller
./cat-controller -kubeconfig=$HOME/.kube/config

# Deploy the example Cat instance
kubectl apply -f client-go/example.yaml

# Look at the created resources
kubectl get cats
kubectl get deployments
Coupled controller

The coupled controller lives in:

In this controller, all of the business logic is implemented directly in the controller's syncHandler.

Factored controller

The well factored controller lives in:

This controller is a refactored verwsion of the coupled controller. In this controller, the business logic has been moved into packages outside the controller itself, and the functions in the todo package are implemented loosely as a functional core.

Kubebuilder based controller

This controller was created with kubebuilder by running:

kubebuilder init --domain bobcatfish.com --license apache2 --owner "The Kubernetes authors"
kubebuilder create api --group cat --version v1alpha1 --kind Feline

Couldn't use Cat as resource name b/c kubebuilder complained:

kubebuilder create api --group cat --version v1alpha1 --kind Cat
...
2018/11/11 14:53:54 Kind must be camelcase (expected CAT was Cat)
Running

Use make to interact with it

# To test and build
make

# To run a controller process locally
make run

# To deploy the controller and types
# I couldn't figure out how to get kubebulider deploy to work for me so for now I'll use `ko`
# Bonus that `ko` doesn't require docker to be installed or for me to change anything manually
 ko apply -f koconfig