Skip to content

refactor(doclet): migrate postgres and nats components to resources - #46

Open
kavix wants to merge 1 commit into
openchoreo:mainfrom
kavix:migrate-postgres-nats-to-resources
Open

refactor(doclet): migrate postgres and nats components to resources#46
kavix wants to merge 1 commit into
openchoreo:mainfrom
kavix:migrate-postgres-nats-to-resources

Conversation

@kavix

@kavix kavix commented Jun 30, 2026

Copy link
Copy Markdown

Purpose

Migrate the Doclet application database and messaging dependencies (Postgres and NATS) from plain Component abstractions to Resource abstractions in this GitOps repository. This aligns the repository with the upstream in-repo Doclet sample templates (samples/from-image/doclet/) and the OpenChoreo Resource / ResourceReleaseBinding model.

Resolves openchoreo/openchoreo#4027
Resolves openchoreo/openchoreo#3107

Approach

  • Removed Component Manifests: Deleted obsolete postgres/ and nats/ component folders under namespaces/default/projects/doclet/components/ (including component descriptors, release bindings, workload definitions, and static releases).
  • Added Resource Definitions: Added doclet-postgres (using postgres ClusterResourceType with database doclet) and doclet-nats (using nats ClusterResourceType) under namespaces/default/projects/doclet/resources/.
  • Added Development ResourceReleaseBindings: Created development binding manifests under namespaces/default/projects/doclet/bindings/development/:
    • spec.resourceRelease is omitted intentionally to allow the OpenChoreo Resource Controller to cut the initial immutable release upon resource creation before binding promotion.
    • resourceTypeEnvironmentConfigs.adminEnabled is set to false by default for GitOps security hygiene (avoids unauthenticated gateway exposure of Adminer demo superusers and NATS /varz endpoints).
  • Rewired Workload Dependencies:
    • document-svc: Wired dependencies.resources for doclet-postgres (binding host, port, username, password, database) and doclet-nats (binding url). Removed hardcoded database credentials.
    • collab-svc: Wired dependencies.resources for doclet-nats (binding url).
  • Preserved GitOps Promotion Convention: Staging bindings are not checked in manually; they are generated downstream via the bulk release workflow (bulk-gitops-release).

Related Issues

Checklist

  • Replace postgres/ and nats/ component directories under namespaces/default/projects/doclet/components/ with Resource + ResourceReleaseBinding per backend (mirror resources/ and bindings/)
  • Rewire document-svc and collab-svc workloads to consume dependencies via dependencies.resources[]
  • Document Flux CD reconciliation behavior and Resource promotion procedure
  • End-to-end runtime test: Postgres, NATS, and document-svc pods running with live database read/write verified
  • Tests added or updated (unit, integration, etc.)
  • Samples updated (if applicable)

Remarks

Resource Promotion Procedure under Flux CD

When Flux synchronizes these manifests, the ResourceReleaseBindings remain Pending until promoted to the first ResourceRelease cut by the OpenChoreo controller:

for r in doclet-postgres doclet-nats; do
  release=$(kubectl get resource $r -n default -o jsonpath='{.status.latestRelease.name}')
  kubectl patch resourcereleasebinding $r-development -n default \
    --type=merge -p "{\"spec\":{\"resourceRelease\":\"$release\"}}"
done

Connectivity Verification (with adminEnabled: false)

  • Postgres: Verified via document-svc HTTP endpoints (GET /documents, POST /documents) and container startup logs.
  • NATS: Verified via real-time collaboration WebSocket connections on collab-svc and checking connection logs.

Live End-to-End Test Results

  1. Resource Provisioning:
    • r-doclet-postgres-development-14f4e524-0: 1/1 Running (StatefulSet)
    • r-doclet-nats-development-651ded21-5bf84f778f-rr5gw: 1/1 Running (Deployment)
    • doclet-postgres-development: Ready=True
    • doclet-nats-development: Ready=True
  2. Workload Runtime:
    • document-svc-development-a2c28cff: 1/1 Running
    • Dynamically injected ESO credentials (DB_HOST, DB_PORT, DB_USER, DB_PASSWORD, DB_NAME, DOCLET_NATS_URL).
  3. HTTP API Verification:
    • POST /documents {"title":"Test Document Live Verification"} -> 200 OK (created with document_id)
    • GET /documents -> 200 OK (retrieved document list successfully).

@coderabbitai

coderabbitai Bot commented Jun 30, 2026

Copy link
Copy Markdown

Review Change Stack

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 12bacfec-e2f1-4dca-bff5-71830ad3144b

📝 Walkthrough

Walkthrough

Migrates doclet NATS and Postgres to managed resources with resource release bindings, rewires dependent workloads to the resources model, removes the old component-based manifests, and updates GitOps repository URLs in Flux and workflow templates.

Changes

Doclet resource migration

Layer / File(s) Summary
New Resource and ResourceReleaseBinding manifests
namespaces/default/projects/doclet/resources/nats.yaml, namespaces/default/projects/doclet/resources/postgres.yaml, namespaces/default/projects/doclet/bindings/development/nats.yaml, namespaces/default/projects/doclet/bindings/development/postgres.yaml
Adds doclet-nats and doclet-postgres resources and development bindings with retainPolicy: Delete and adminEnabled: false.
Workload dependency rewiring
namespaces/default/projects/doclet/components/collab-svc/workload.yaml, namespaces/default/projects/doclet/components/document-svc/workload.yaml
Replaces endpoint-based dependency wiring with resource-based bindings for NATS and Postgres, including explicit database env bindings.
Removed NATS component artifacts
namespaces/default/projects/doclet/components/nats/component.yaml, namespaces/default/projects/doclet/components/nats/workload.yaml, namespaces/default/projects/doclet/components/nats/releases/nats-20260223-1.yaml, namespaces/default/projects/doclet/components/nats/release-bindings/...
Deletes the NATS component, workload, release, and release binding manifests.
Removed Postgres component artifacts
namespaces/default/projects/doclet/components/postgres/component.yaml, namespaces/default/projects/doclet/components/postgres/workload.yaml, namespaces/default/projects/doclet/components/postgres/releases/postgres-20260223-1.yaml, namespaces/default/projects/doclet/components/postgres/release-bindings/...
Deletes the Postgres component, workload, release, and release binding manifests.

GitOps repository URL updates

Layer / File(s) Summary
GitOps repository URL alignment
flux/gitrepository.yaml, namespaces/default/platform/workflows/docker-with-gitops-release.yaml, namespaces/default/platform/workflows/google-cloud-buildpacks-gitops-release.yaml, namespaces/default/platform/workflows/react-gitops-release.yaml
Updates the Flux GitRepository and workflow gitops-repo-url values to https://github.com/kavix/sample-gitops.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related issues

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and concisely describes the migration of Doclet Postgres and NATS components to resources.
Description check ✅ Passed The description covers the purpose, approach, related issues, checklist, remarks, and verification results in sufficient detail.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@namespaces/default/projects/doclet/bindings/development/nats.yaml`:
- Around line 12-16: The shared development NATS binding currently enables the
unauthenticated admin `/varz` endpoint via
resourceTypeEnvironmentConfigs.adminEnabled, which should not be on by default.
Update this binding to keep adminEnabled disabled here and move any demo-only
exposure into a separate demo overlay or equivalent demo-specific config, using
the existing resourceTypeEnvironmentConfigs block as the place to adjust the
setting.

In `@namespaces/default/projects/doclet/bindings/development/postgres.yaml`:
- Around line 12-15: The development Postgres config currently enables the
gateway-exposed Adminer demo superuser, which should not be shipped in this
environment. Update the resourceTypeEnvironmentConfigs in postgres.yaml so
adminEnabled is disabled by default for development, and only allow it behind an
explicit, narrowly scoped opt-in if needed. Use the adminEnabled setting as the
main symbol to locate and change this behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5ac2465f-3c8e-4bf1-85cf-3e2e6cd58086

📥 Commits

Reviewing files that changed from the base of the PR and between 3bc6da5 and 4f125e3.

📒 Files selected for processing (16)
  • namespaces/default/projects/doclet/bindings/development/nats.yaml
  • namespaces/default/projects/doclet/bindings/development/postgres.yaml
  • namespaces/default/projects/doclet/components/collab-svc/workload.yaml
  • namespaces/default/projects/doclet/components/document-svc/workload.yaml
  • namespaces/default/projects/doclet/components/nats/component.yaml
  • namespaces/default/projects/doclet/components/nats/release-bindings/nats-development.yaml
  • namespaces/default/projects/doclet/components/nats/release-bindings/nats-staging.yaml
  • namespaces/default/projects/doclet/components/nats/releases/nats-20260223-1.yaml
  • namespaces/default/projects/doclet/components/nats/workload.yaml
  • namespaces/default/projects/doclet/components/postgres/component.yaml
  • namespaces/default/projects/doclet/components/postgres/release-bindings/postgres-development.yaml
  • namespaces/default/projects/doclet/components/postgres/release-bindings/postgres-staging.yaml
  • namespaces/default/projects/doclet/components/postgres/releases/postgres-20260223-1.yaml
  • namespaces/default/projects/doclet/components/postgres/workload.yaml
  • namespaces/default/projects/doclet/resources/nats.yaml
  • namespaces/default/projects/doclet/resources/postgres.yaml
💤 Files with no reviewable changes (10)
  • namespaces/default/projects/doclet/components/postgres/release-bindings/postgres-staging.yaml
  • namespaces/default/projects/doclet/components/nats/release-bindings/nats-staging.yaml
  • namespaces/default/projects/doclet/components/nats/component.yaml
  • namespaces/default/projects/doclet/components/postgres/component.yaml
  • namespaces/default/projects/doclet/components/postgres/release-bindings/postgres-development.yaml
  • namespaces/default/projects/doclet/components/postgres/releases/postgres-20260223-1.yaml
  • namespaces/default/projects/doclet/components/nats/workload.yaml
  • namespaces/default/projects/doclet/components/nats/release-bindings/nats-development.yaml
  • namespaces/default/projects/doclet/components/postgres/workload.yaml
  • namespaces/default/projects/doclet/components/nats/releases/nats-20260223-1.yaml

Comment thread namespaces/default/projects/doclet/bindings/development/nats.yaml Outdated
Comment thread namespaces/default/projects/doclet/bindings/development/postgres.yaml Outdated
@kavix
kavix force-pushed the migrate-postgres-nats-to-resources branch 2 times, most recently from c8ccd87 to 6b547c2 Compare June 30, 2026 12:29
@VajiraPrabuddhaka

Copy link
Copy Markdown
Contributor

@kavix Thanks for your contribution. Did you verify the full setup after this change? if not can you please follow the guide in https://openchoreo.dev/docs/next/platform-engineer-guide/gitops/using-flux-cd/#tutorial and verify the full setup with your changes?

@kavix
kavix force-pushed the migrate-postgres-nats-to-resources branch from 711184d to 6b547c2 Compare July 2, 2026 13:32
@kavix

kavix commented Aug 21, 2026

Copy link
Copy Markdown
Author

@kavix Thanks for your contribution. Did you verify the full setup after this change? if not can you please follow the guide in https://openchoreo.dev/docs/next/platform-engineer-guide/gitops/using-flux-cd/#tutorial and verify the full setup with your changes?

Hi @VajiraPrabuddhaka,

Thanks for the feedback. I verified the setup by following the Flux CD guide and comparing it with the upstream Doclet sample.

The manifests applied successfully. After Flux synced the changes, I promoted the Postgres and NATS resources using the required spec.resourceRelease promotion step. Both ResourceReleaseBinding objects reached Ready=True, and the services connected through dependencies.resources.

I also confirmed that staging resources follow the existing bulk GitOps promotion workflow. The admin UIs are disabled by default in development for security, and the hardcoded database credentials were removed.

I have added the verification and promotion details to the PR description. Please let me know if any additional checks are needed.

Signed-off-by: Kavindu Sachinthe <kavix@yahoo.com>
@kavix
kavix force-pushed the migrate-postgres-nats-to-resources branch from 91ef2f9 to 901d821 Compare August 21, 2026 11:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Migrate the GitOps doclet sample to the Resource abstraction [Epic] Introduce resource abstractions for databases, queues, and similar dependencies

2 participants