|
| 1 | +# AGENTS.md - barbican-operator |
| 2 | + |
| 3 | +## Project overview |
| 4 | + |
| 5 | +barbican-operator is a Kubernetes operator that manages |
| 6 | +[OpenStack Barbican](https://docs.openstack.org/barbican/latest/) (the key |
| 7 | +management service: secret storage, encryption keys, certificates, and |
| 8 | +PKCS#11 HSM integration) on OpenShift/Kubernetes. It is part of the |
| 9 | +[openstack-k8s-operators](https://github.com/openstack-k8s-operators) project. |
| 10 | + |
| 11 | +Key Barbican domain concepts: **secret stores** (software-backed, PKCS#11 HSM), |
| 12 | +**secrets** (symmetric keys, certificates, passphrases, opaque data), |
| 13 | +**certificate authorities**, **encryption keys** (for Cinder/Nova/Glance |
| 14 | +volume/disk/image encryption). |
| 15 | +## Tech stack |
| 16 | + |
| 17 | +| Layer | Technology | |
| 18 | +|-------|------------| |
| 19 | +| Language | Go (modules, multi-module workspace via `go.work`) | |
| 20 | +| Scaffolding | [Kubebuilder v4](https://book.kubebuilder.io/) + [Operator SDK](https://sdk.operatorframework.io/) | |
| 21 | +| CRD generation | controller-gen (DeepCopy, CRDs, RBAC, webhooks) | |
| 22 | +| Config management | Kustomize | |
| 23 | +| Packaging | OLM bundle | |
| 24 | +| Testing | Ginkgo/Gomega + envtest (functional), KUTTL (integration) | |
| 25 | +| Linting | golangci-lint (`.golangci.yaml`) | |
| 26 | +| CI | Zuul (`zuul.d/`), Prow (`.ci-operator.yaml`), GitHub Actions | |
| 27 | + |
| 28 | +## Custom Resources |
| 29 | + |
| 30 | +| Kind | Purpose | |
| 31 | +|------|---------| |
| 32 | +| `Barbican` | Top-level CR. Owns the database, keystone service, transport URL, and spawns sub-CRs for each service component. | |
| 33 | +| `BarbicanAPI` | Manages the Barbican API deployment (httpd/WSGI). | |
| 34 | +| `BarbicanWorker` | Manages the worker service deployment (async secret operations). | |
| 35 | +| `BarbicanKeystoneListener` | Manages the Keystone notification listener (reacts to Keystone events). | |
| 36 | + |
| 37 | +The `Barbican` CR has defaulting and validating admission webhooks. |
| 38 | +Sub-CRs are created and owned by the `Barbican` controller -- not intended to |
| 39 | +be created directly by users. |
| 40 | + |
| 41 | +## Directory structure |
| 42 | + |
| 43 | +**Maintenance rule:** when directories are added, removed, or renamed, or when |
| 44 | +their purpose changes, update this table to match. |
| 45 | + |
| 46 | +| Directory | Contents | |
| 47 | +|-----------|----------| |
| 48 | +| `api/v1beta1/` | CRD types (`barbican_types.go`, `barbicanapi_types.go`, `barbicanworker_types.go`), conditions, webhook markers | |
| 49 | +| `cmd/` | `main.go` entry point | |
| 50 | +| `internal/controller/` | Reconcilers: `barbican_controller.go`, `barbicanapi_controller.go`, `barbicankeystonelistener_controller.go`, `barbicanworker_controller.go` | |
| 51 | +| `internal/barbican/` | Barbican-level resource builders (db-sync, common helpers) | |
| 52 | +| `internal/barbicanapi/` | BarbicanAPI resource builders | |
| 53 | +| `internal/barbicankeystonelistener/` | BarbicanKeystoneListener resource builders | |
| 54 | +| `internal/barbicanworker/` | BarbicanWorker resource builders | |
| 55 | +| `internal/webhook/` | Webhook implementation | |
| 56 | +| `templates/` | Config files and scripts mounted into pods via `OPERATOR_TEMPLATES` env var | |
| 57 | +| `config/crd,rbac,manager,webhook/` | Generated Kubernetes manifests (CRDs, RBAC, deployment, webhooks) | |
| 58 | +| `config/samples/` | Example CRs (Kustomize overlays). Includes PKCS#11 Luna HSM and TLS variants. | |
| 59 | +| `test/functional/` | envtest-based Ginkgo/Gomega tests | |
| 60 | +| `test/kuttl/` | KUTTL integration tests | |
| 61 | +| `hack/` | Helper scripts (CRD schema checker, local webhook runner) | |
| 62 | +| `docs/` | Documentation | |
| 63 | + |
| 64 | +## Build commands |
| 65 | + |
| 66 | +After modifying Go code, always run: `make generate manifests fmt vet`. |
| 67 | + |
| 68 | +## Code style guidelines |
| 69 | + |
| 70 | +- Follow standard openstack-k8s-operators conventions and lib-common patterns. |
| 71 | +- Use `lib-common` modules for conditions, endpoints, TLS, storage, and other |
| 72 | + cross-cutting concerns rather than re-implementing them. |
| 73 | +- CRD types go in `api/v1beta1/`. Controller logic goes in |
| 74 | + `internal/controller/`. Resource-building helpers go in `internal/barbican*` |
| 75 | + packages matching the CR they support. |
| 76 | +- Config templates are plain files in `templates/` -- they are mounted at |
| 77 | + runtime via the `OPERATOR_TEMPLATES` environment variable. |
| 78 | +- Webhook logic is split between the kubebuilder markers in `api/v1beta1/` and |
| 79 | + the implementation in `internal/webhook/`. |
| 80 | + |
| 81 | +## Testing |
| 82 | + |
| 83 | +- Functional tests use the envtest framework with Ginkgo/Gomega and live in |
| 84 | + `test/functional/`. |
| 85 | +- KUTTL integration tests live in `test/kuttl/`. |
| 86 | +- Run all functional tests: `make test`. |
| 87 | +- When adding a new field or feature, add corresponding test cases in |
| 88 | + `test/functional/` and update fixture data accordingly. |
| 89 | + |
| 90 | +## Key dependencies |
| 91 | + |
| 92 | +- [lib-common](https://github.com/openstack-k8s-operators/lib-common): shared modules for conditions, endpoints, database, TLS, secrets, etc. |
| 93 | +- [infra-operator](https://github.com/openstack-k8s-operators/infra-operator): RabbitMQ and topology APIs. |
| 94 | +- [mariadb-operator](https://github.com/openstack-k8s-operators/mariadb-operator): database provisioning. |
| 95 | +- [keystone-operator](https://github.com/openstack-k8s-operators/keystone-operator): identity service registration. |
| 96 | +- [dev-docs/developer.md](https://github.com/openstack-k8s-operators/dev-docs/blob/main/developer.md): developer guide and coding conventions. |
0 commit comments