Operations Controller
Overview
Operations Controller is a Kubebuilder project. This Kubebuilder project features an Operation
of type CustomResourceDefinition (CRD) and a Kubernetes Controller for it. It also provides several key resources that are accessible at the given locations:
-
api/v1alpha1/operation_types.go
The operation_types.go
file contains the CRD that is generated by the Operations Controller.
-
config/crd/bases/operations.compass_operations.yaml
The operations.compass_operations.yaml
file is generated from the operation_types.go
CRD.
-
config/samples/operations_v1alpha1_operation.yaml
The operations_v1alpha1_operation.yaml
file contains a sample of the CRD.
-
controllers/operation_controller.go
The operation_controller.go
file is a Kubernetes controller for the CRD.
Prerequisites
- Docker
- Kubernetes CLI
- Kubernetes cluster
Installation
CRD
Steps
- Generate the CRD.
make manifests
- Download the Kustomize binary locally.
make kustomize
- Build the CRD into a single file named
crds.yaml
.
./bin/kustomize build config/crd > crds.yaml
- Apply the generated CRD file onto a Kubernetes cluster.
kubectl apply -f crds.yaml
Controller
Prerequisites
- Make sure you have the CRD installed.
Steps
- Deploy the Kubernetes controller for the operation CRD onto a Kubernetes cluster. To do that, create a Docker image.
docker build -t compass/${IMAGE_NAME}
- Push the Docker image to a Docker repository.
docker push ${IMAGE_NAME}
- Run the controller. To do that, create an instance of the Docker image in the Kubernetes cluster.
kubectl run operations-controller --image=${IMAGE_NAME}
Note: If there's an already existing Kubernetes deployment for the controller (that is, if you have a local installation of Compass), just hotswap its image.
Usage and Development
CRD
-
Make the required changes to the CRD in ./api/v1alpha1/operation_types.go
.
-
Regenerate the CRD.
make manifests
- Copy the new generated CRD to the component's Helm chart at
compass/chart/compass/charts/operations-controller
. You can also use a Makefile target to do this.
make copy-crds-to-chart
Controller
If there are changes to the controller, you have to create a Docker image for the new version of the controller. Then, deploy the image manually on a Kubernetes cluster.