This makefile target will invoke controller-gen to generate the CRD manifests at config/crd/bases/demo.lfr31.com_demoes.yaml
Implement the Controller (Business Logic -> Core of this operator ;)!)
Create a demo Deployment if it doesn’t exist
Ensure that the Deployment foo and size are the same as specified by the Demo CR spec
Update the Demo CR status using the status writer with the names of the demo pods
You can implement others features if you want ... to Infinity and Beyond!
Build and run the operator
make install
Once this is done, there are two ways to run the operator:
As Go program outside a cluster
make run ENABLE_WEBHOOKS=false
As a Deployment inside a Kubernetes cluster
Build and push the image
# Build the image
export REGISTRY=<dockerhub-username>
# you need to be loggued to Docker registry -> docker login
make docker-build IMG=$REGISTRY/demo-operator:v0.0.1
# Push the image to the docker hub registry
make docker-push IMG=$REGISTRY/demo-operator:v0.0.1
Deploy the operator
For this demo we will run the operator in the demo namespace which can be specified for all resources in config/default/kustomization.yaml
cd config/default/ && kustomize edit set namespace "demo" && cd ../..
Ensure that the demo operator creates the deployment for the sample CR with the correct size:
$ kubectl get deployment
NAME READY UP-TO-DATE AVAILABLE AGE
demo-operator-controller-manager 1/1 1 1 5m
demo-sample 3/3 3 3 1m
Check the pods and CR status to confirm the status is updated with the demo pod names:
$ kubectl get po
NAME READY STATUS RESTARTS AGE
demo-sample-9df5c78d7-5pmde 1/1 Running 0 1m
demo-sample-9df5c78d7-5pmde 1/1 Running 0 1m
demo-sample-9df5c78d7-5pmde 1/1 Running 0 1m