Developing the Drupal Operator
The Drupal Operator is built with the Operator SDK (Ansible-based) and uses Kustomize for its Kubernetes manifests. This page describes how to work on and test the operator itself.
- Current Operator SDK version used: v1.29.0
Prerequisites
To develop the operator you need:
- A Kubernetes cluster for testing (kind, Minikube, MicroK8s, or a test cluster)
kubectlinstalled and configured- Docker (or another container runtime) and access to a container registry
make- Operator SDK installed:
- See: https://sdk.operatorframework.io/docs/building-operators/ansible/
Environment setup
In the operator repository, copy the example environment file and edit it:
cp .env.example .env
In .env, set (for example):
KUBECONFIG– your kubeconfig path if not default-
IMG– the operator image to build and push, for example:IMG=ozziio/drupal-operator:3.1.6
Then load it:
source .env
For local testing with kind or Minikube, you can use .env.local.example
(if present) as a reference.
Build and push the operator image
Build the operator image:
make docker-build IMG=$IMG
Log in to your container registry (for example, Docker Hub), then push:
make docker-push IMG=$IMG
After this, the image $IMG should be available to your cluster.
Install CRDs and deploy the operator
Install the CRDs and base configuration:
make install
This applies:
- CRDs from
config/crd/ - RBAC from
config/rbac/ - Other base manifests
Deploy the operator controller manager:
make deploy IMG=$IMG
This creates:
- The operator Deployment
- Supporting Services and RBAC
Verify the operator is running:
kubectl get pods -n drupal-operator-system
kubectl logs deploy/drupal-operator-controller-manager -n drupal-operator-system
(Adjust the namespace if you use a different one.)
Warning Do not run
make uninstallon a live or shared cluster. It removes CRDs and will trigger garbage collection of all related resources (Drupal sites, databases, backups, etc.).
Project structure overview
Key directories and files:
-
watches.yamlMaps CRDs to Ansible roles/playbooks. This is how the Operator SDK knows which role to run when aDrupalresource changes. -
roles/setup/Main Ansible role responsible for: - Creating ConfigMaps, Secrets, PVCs
- Deploying MariaDB, Drupal, and optional Memcached
- Managing CronJobs and Jobs for cron, backups, imports, locale updates
-
Updating CR status fields
-
config/Kustomize-based deployment manifests: config/crd/– CRDs forDrupaland related resourcesconfig/rbac/– Roles and RoleBindingsconfig/manager/– Operator manager Deploymentconfig/testing/,config/kind-testing/– overlays for testing-
config/prometheus/– optional metrics/monitor configuration -
install/Static install manifests (CRDs, RBAC, operator Deployment) that can be used without Operator SDK, for environments where you preferkubectl applyovermake install/make deploy. -
molecule/Contains Molecule scenarios for automated testing of the operator.
Testing with Molecule
The repository includes Molecule scenarios such as:
molecule/defaultmolecule/kindmolecule/test-clustermolecule/test-local
Each scenario typically has:
create.yml/destroy.yml– cluster/namespace setup and teardownconverge.yml– applies test resources (e.g., a Drupal CR)verify.yml– checks that resources behave as expected
To run a scenario, for example the default one:
cd molecule/default
molecule test
This will:
- Prepare a test environment
- Deploy the operator
- Apply test
Drupalresources - Verify behavior (e.g., pods running, services created, status updated)
Development tips
- Use a local cluster (kind, Minikube, MicroK8s) to isolate your changes.
- Tag images uniquely (for example,
ozziio/drupal-operator:dev-<user>-<date>) to avoid clashing with production images. -
Watch the operator logs while reconciling:
kubectl logs -f deploy/drupal-operator-controller-manager -n drupal-operator-system
-
Test small changes incrementally:
- Adjust a variable or template.
- Rebuild and push the image.
- Redeploy with
make deploy IMG=$IMG. - Apply or update a
Drupalresource and observe behavior.
Cleanup
For a complete cleanup of your test environment:
- Delete any
Drupalresources you created:
kubectl delete drupal --all-namespaces --all
- Optionally delete the namespaces used for testing.
Avoid running make uninstall on any cluster that contains data you care
about, as it removes CRDs and triggers deletion of all associated resources.