feat: NebariApp spec.database provisions managed PostgreSQL via CloudNativePG#151
Open
tylerpotts wants to merge 7 commits into
Open
feat: NebariApp spec.database provisions managed PostgreSQL via CloudNativePG#151tylerpotts wants to merge 7 commits into
tylerpotts wants to merge 7 commits into
Conversation
Managed PostgreSQL request (provider cloudnativepg, instances, size), DatabaseReady condition, databaseSecretRef status field, and event reasons. The reconciler lands separately. Part of nebari-dev/nebari-infrastructure-core#303
Provisions a CloudNativePG Cluster per NebariApp with spec.database enabled, polls readiness (no informer: the CNPG CRDs are optional infrastructure and a watch on a missing CRD breaks manager startup), normalizes CNPG's generated app secret into <name>-db-credentials (host, port, username, password, database, uri), and scopes read access to the app's ServiceAccount. Validates the 50-char CNPG cluster-name cap up front. Missing CNPG degrades to a DatabaseReady=False/CNPGNotInstalled condition. Disabling never deletes the database; deleting the NebariApp cascades via owner references. Pinned to cloudnative-pg/api v1.28.0, the newest types-only release whose transitive deps stay on k8s.io 0.34 (v1.28.1+ forces 0.35+); go mod tidy incidentally bumps ginkgo/gomega test deps. Part of nebari-dev/nebari-infrastructure-core#303
Invoked after auth with the TLS-style poll-and-return pattern; scheme registration for CNPG types (client-side, safe when the CRD is absent); a Secrets watch mapping CNPG app secrets back to their NebariApp so password rotations refresh the normalized credentials copy; operator RBAC for postgresql.cnpg.io clusters without the delete verb. Part of nebari-dev/nebari-infrastructure-core#303
Verify the CNPG connection secret is owned by our Cluster before republishing it as app credentials; extract the db-app secret name mapping behind naming.NebariAppNameForDatabaseSecret with tests (the Secrets watch depends on it); document the CEL quantity() Kubernetes 1.29 floor and the instances guardrail; correct the immutable-name guidance; normalize the nolint directive. Part of nebari-dev/nebari-infrastructure-core#303
4 tasks
Docker Images BuiltImages pushed to Quay.io for branch
Test the operator: kubectl apply -k https://github.com/nebari-dev/nebari-operator.git/config/default?ref=feat/nebariapp-database
kubectl set image deployment/nebari-operator-controller-manager manager=quay.io/nebari/nebari-operator:feat-nebariapp-database -n nebari-operator-system |
…ggle NIC PR 455 was reworked per review to install the CloudNativePG operator as unconditional foundational infrastructure; the database.enabled config toggle no longer exists. Update the field doc, the CNPGNotInstalled condition message, its test, and the reconciler docs page accordingly. Regenerated CRD bases and api-reference.
Docker Images BuiltImages pushed to Quay.io for branch
Test the operator: kubectl apply -k https://github.com/nebari-dev/nebari-operator.git/config/default?ref=feat/nebariapp-database
kubectl set image deployment/nebari-operator-controller-manager manager=quay.io/nebari/nebari-operator:feat-nebariapp-database -n nebari-operator-system |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements the NebariApp side of nebari-dev/nebari-infrastructure-core#303: packs request a managed PostgreSQL database through the CRD, and the operator provisions it on CloudNativePG.
When enabled, the operator:
Clusternamed<name>-db(owner-referenced to the NebariApp) and polls readiness<name>-db-appSecret is owned by our Cluster, then normalizes it into<name>-db-credentialswith keyshost,port,username,password,database,urigeton that Secret to the app's ServiceAccount via Role/RoleBindingDatabaseReadycondition (DatabaseProvisioning/Available/CNPGNotInstalled/DatabaseDisabled/Failed) andstatus.databaseSecretRefDesign contracts (deliberate)
enabled: falsestops management and reportsDatabaseDisabled; the Cluster, data, and credentials remain. Only deleting the NebariApp cascades (standard owner-reference GC). Operator RBAC has nodeleteverb onpostgresql.cnpg.io/clusters.DatabaseReady=False/CNPGNotInstalledwhile the rest of the app reconciles normally.<app>-db-appsecrets back to their NebariApp, so password rotations propagate without waiting for the periodic requeue.github.com/cloudnative-pg/apiv1.28.0 (the newest tag whose transitive deps stay on k8s.io 0.34; v1.28.1+/v1.29+ force 0.35+; rationale recorded in go.mod).Cross-repo sequencing
The CloudNativePG operator itself is installed by NIC as unconditional foundational infrastructure in nebari-dev/nebari-infrastructure-core#455 (open; originally an opt-in toggle, reworked per review). Sequencing is naturally safe: this feature only reaches clusters once NIC bumps its pinned operator version, which happens after PR 455 merges.
Test Plan
make testgreen: database package 88.1% coverage (17 tests: provisioning, defaults, readiness poll, credentials normalization incl. missing-key and foreign-owner rejection, RBAC incl. custom ServiceAccount, disable-keeps-everything, foreign-cluster status cleanup, CNPG-absent degrade, name-cap preflight, steady-state idempotency without duplicate events); naming 96.6% (incl. the watch's name-mapping and the 50-char/253-char validators)make lint,go vet ./...,gofmtclean;make manifests generate docsproduces no drift (CI staleness checks pass)instances0/10 rejected,sizezero-quantity rejected via CEL, enum/pattern rejectionsdatabase.enabled: true, wait forDatabaseReady=Available,psqlvia the<name>-db-credentialssecretNotes for reviewers
sizecheck uses CEL'squantity()library); documented indocs/reconcilers/database.md.internal/controllerenvtest suite has a pre-existing failure onmain(HTTPRoute scheme registration), reproducible at the base commit; it is excluded frommake testby the Makefile. A controller-level database happy-path case is a follow-up once that suite is fixed.docs/reconcilers/README.mdwere already stale before this branch (missingtls/too); left for a separate docs cleanup.