Skip to content
dvrknPublic

About

No description, website, or topics provided.

Resources

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

kubepg

PostgreSQL objects as Kubernetes custom resources — declared once, kept in sync forever.

CI Go Reference

Getting started · Resource reference · Architecture · Full docs


kubectl apply a Database, a Role, a Schema, a Grant — kubepg turns each into real PostgreSQL DDL and then keeps watching. Someone drops a grant by hand at 2am? The next reconcile puts it back. That's the whole pitch: the same ground cyrilgdn/terraform-provider-postgresql covers, but as a live controller instead of a one-shot apply.

apiVersion: kubepg.dvrkn.com/v1
kind: Database
metadata:
  name: appdb
spec:
  instanceRef: { name: prod }
  owner: app
kubectl apply -f appdb.yaml
kubectl get database appdb
# NAME    INSTANCE   READY   AGE
# appdb   prod       True    4s

Why a controller instead of terraform apply

Terraform provider kubepg
Drift correction Only on the next apply a human remembers to run Automatic, every 5 minutes
Where state lives A .tfstate file you have to protect and share The Kubernetes API — kubectl get/describe is the state
Who can request a database Whoever can run terraform apply Any team, gated by ordinary Kubernetes RBAC, in its own namespace
Failure visibility A failed CI job A Ready=False condition with a SQLSTATE code, right on the object

How it works

  • Instance (cluster-scoped) is the only place connection info lives — host, port, credentials pulled from a Secret, SSL mode. A Postgres server is a cluster-wide fact, so any namespace can reference one by name. Its controller does one thing: probe with SELECT version() and report health.
  • Everything else — Database, Role, Schema, Grant, and more — is namespaced, points at one Instance, and describes one PostgreSQL object. Each reconcile runs idempotent CREATE/ALTER/DROP SQL and self-heals drift on a 5-minute resync. Deleting a CR drops the object through a finalizer (or leaves it alone with deletionPolicy: Orphan).

Read docs/architecture.md for the full reconcile loop, the SQL layer (internal/pg), and how Grant maps object types onto SQL ON <target> clauses.

Resources

Kind Status Notes
Instance ✅ implemented Connection target + health probe
Database ✅ implemented CREATE/ALTER/DROP DATABASE
Role ✅ implemented CREATE/ALTER/DROP ROLE, password from Secret, memberships
Schema ✅ implemented CREATE/ALTER/DROP SCHEMA
Grant ✅ implemented Revoke-then-grant transaction for exact convergence
Extension 🚧 scaffolded CRD installable; controller pending
GrantRole 🚧 scaffolded
DefaultPrivileges 🚧 scaffolded
Publication 🚧 scaffolded
Subscription 🚧 scaffolded
Function 🚧 scaffolded
Server (FDW) 🚧 scaffolded
UserMapping 🚧 scaffolded
ReplicationSlot 🚧 scaffolded
PhysicalReplicationSlot 🚧 scaffolded
SecurityLabel 🚧 scaffolded

Scaffolded kinds install as CRDs and accept resources, but report Ready=False, Reason=NotImplemented until their reconcile logic lands — full field shapes are in docs/resources.md.

Quick start

make install                    # install the CRDs into the current kube context
make run                        # run the controller locally against that context
kubectl apply -k config/samples # apply the samples (edit the Instance host/Secret first)

Deploying to a real cluster, Helm chart toggles, and a full worked example (Instance → Role → Database → Schema → Grant) are in docs/getting-started.md.

For a throwaway local try-it with k3d:

k3d cluster create pgop
docker build -t kubepg:dev .
k3d image import kubepg:dev -c pgop
helm install kubepg charts/kubepg -n kubepg --create-namespace \
  --set controllerManager.container.image.repository=kubepg \
  --set controllerManager.container.image.tag=dev

Security

Passwords and DSNs are supplied only via Secret references, resolved in-memory, and never written back into a CR's spec/status, events, or logs — log lines and status messages carry object names and PostgreSQL SQLSTATE codes, nothing that could embed a credential. Details, RBAC scoping advice, and the multi-tenancy model are in docs/security.md.

Testing

make test               # envtest: CRD install + CEL/enum/default validation (no Postgres)
make test-integration   # real disposable Postgres via testcontainers, exercises the SQL layer
make test-e2e-pg        # envtest + Postgres container + live controllers, full manifest lifecycle
make test-e2e-k3d       # deploys the real built image into a k3d cluster, black-box

Why four separate tiers instead of one suite, and what each one actually proves, is explained in docs/development.md.

Documentation

Built with

Kubebuilder · controller-runtime · jackc/pgx

License

Apache License 2.0 — see the license header in individual source files.

About

No description, website, or topics provided.

Resources

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages