View Source Bonny Mix Tasks
There are a number of mix tasks to help create a Kubernetes operator.
mix help | grep bonny
Initialize your Operator (mix bonny.init
)
To add bonny to your existing elixir project (mix new your_operator
), this tasks
helps you to generate application configuration and initializing your test suite.
Just run mix bonny.init
, the task will ask you questions about your operator
and initialize it.
Controller Generation (mix bonny.gen.controller
)
Guides you through the creation of a controller. Normally, a controller of an operator watches a custom resource defined by that same operator. This is the default flow through this mix task. However, you can also create a controller that watches and reacts on events of core resources or custom resources defined by another operator.
See the controllers guide for further information about controllers.
After the mix task ran through, open up your controller and add functionality for your resource's lifecycles:
- Apply (or Add/Modify)
- Delete
- Reconcile; periodically called with each every instance of a CRD's resources
Ideally you'd also open up the generated CRD versions and add OpenAPIV3 schema, additional printer columns, etc.
Your operator can also have multiple controllers if you want to watch multiple resources in your operator. Just run the mix task again.
Generating Kubernetes manifest for operator (mix bonny.gen.manifest
)
This will generate the entire manifest for this operator including:
- CRD manifests
- RBAC
- Service Account
- Operator Deployment
The operator manifest generator requires the image
flag to be passed if you plan to deploy the operator in your cluster. This is the docker image URL of your operators docker image created by mix bonny.gen.docker
above.
mix bonny.gen.manifest --image ${BONNY_IMAGE}
You may omit the --image
flag if you want to generate a manifest without the deployment so that you can develop locally running the operator outside of the cluster.
By default the manifest will generate the service account and deployment in the "default" namespace.
To set the namespace explicitly:
mix bonny.gen.manifest --out - -n test
Alternatively you can apply it directly to kubectl:
mix bonny.gen.manifest --out - -n test | kubectl apply -f - -n test
Generating a dockerfile (mix bonny.gen.dockerfile
)
The following command will generate a dockerfile for your operator. This will need to be pushed to a docker repository that your Kubernetes cluster can access.
Again, this Dockerfile is for your operator, not for the pods your operator may deploy.
You can skip this step when developing by running your operator external to the cluster.
mix bonny.gen.dockerfile
export BONNY_IMAGE=YOUR_IMAGE_NAME_HERE
docker build -t ${BONNY_IMAGE} .
docker push ${BONNY_IMAGE}:latest