You must install these tools:
go
: The languagePipeline CRD
is built ingit
: For source controldep
: For managing external Go dependencies. - Please Install dep v0.5.0 or greater.ko
: For development.kubectl
: For interacting with your kube clusterkubebuilder
kustomize
Use dep
to update dependencies:
dep ensure
To update the generated client-go
libs:
./hack/update-codegen.sh
This repo contains 3 implementations of the cat controller:
- The tightly coupled client-go controller
- The better factored client-go controller
- The kubebuilder controller
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.
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)
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
The coupled controller lives in:
In this controller, all of the business logic is implemented directly in the controller's syncHandler
.
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.
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)
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