Skip to content

feat: distributed_cli (dsvc) — service CLI + Atlas schema output#74

Merged
patrickleet merged 4 commits into
mainfrom
feat/atlas-schema-resource
Jun 6, 2026
Merged

feat: distributed_cli (dsvc) — service CLI + Atlas schema output#74
patrickleet merged 4 commits into
mainfrom
feat/atlas-schema-resource

Conversation

@patrickleet
Copy link
Copy Markdown
Collaborator

@patrickleet patrickleet commented Jun 6, 2026

Summary

Make Distributed's service tooling a single in-workspace crate, distributed_cli, that is both a dsvc binary and a library — removing the cross-repo release coordination that the hops-cli ↔ distributed_tooling split required.

What changed

  • Folded distributed_tooling into distributed_cli as internal generate/atlas modules (still pure, no I/O); the generation API is re-exported from the crate root.
  • Added the command surface (cli module): scaffold / describe / schema, ported from hops-cli's service adapter, with pub fn run(&ServiceArgs) as the dispatcher and dsvc as the binary.
  • dsvc schema --format atlas renders an AtlasSchema (db.atlasgo.io/v1alpha1) resource to stdout, flag-configured (--name/--namespace/--db-secret/--db-secret-key/--db-url/--dev-url). Default --format sql is unchanged. Nothing is written into .gitops/ — redirect it wherever (e.g. a separate schema repo).
  • Library-as-module: ServiceArgs + run are public so hops can mount the commands under hops service and dispatch — re-exporting, not reimplementing, so a new flag reaches hops on a plain cargo update.
  • Publish workflow: publish-toolingpublish-cli.

Migration note

distributed_tooling 1.5.0 stays on crates.io for the already-merged hops-cli until it migrates to depend on distributed_cli (the optional, lightweight tie-in).

Tests

26 tests pass (generation + Atlas renderer + CLI atlas-flag mapping). dsvc --help / schema --help verified. fmt + clippy clean; workspace resolves; root distributed unaffected.

Add distributed_tooling::render_atlas_schema — a pure producer that wraps
desired-state schema SQL (e.g. DistributedProjectManifest::sql_statements) into an
AtlasSchema (db.atlasgo.io/v1alpha1) custom resource. DB URL via a Secret
reference (GitOps) or inline (dev), optional devURL, SQL as a literal block
scalar. The caller prints/redirects the result anywhere (stdout → any file or a
separate schema repo); the crate deliberately does not pick a .gitops/ location.

Implements [[tasks/atlas-operator-schema-gitops]]

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 6, 2026

Review Change Stack

Warning

Review limit reached

@patrickleet, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 10 minutes and 41 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 402529c9-75fa-4795-aa36-e8a5d1a0a48e

📥 Commits

Reviewing files that changed from the base of the PR and between f56dd70 and 32c197f.

📒 Files selected for processing (20)
  • .github/workflows/integration-distributed-cli.yaml
  • .github/workflows/on-push-main-version-and-tag.yaml
  • .github/workflows/on-v-tag-publish.yaml
  • Cargo.toml
  • distributed_cli/Cargo.toml
  • distributed_cli/src/atlas.rs
  • distributed_cli/src/cli.rs
  • distributed_cli/src/generate/github.rs
  • distributed_cli/src/generate/gitops.rs
  • distributed_cli/src/generate/mod.rs
  • distributed_cli/src/generate/names.rs
  • distributed_cli/src/generate/service_crate.rs
  • distributed_cli/src/lib.rs
  • distributed_cli/src/main.rs
  • distributed_cli/tests/cli_manifest.rs
  • distributed_cli/tests/cli_scaffold.rs
  • distributed_cli/tests/fixtures/orders-service/.gitignore
  • distributed_cli/tests/fixtures/orders-service/Cargo.toml
  • distributed_cli/tests/fixtures/orders-service/src/lib.rs
  • distributed_tooling/Cargo.toml
📝 Walkthrough

Walkthrough

A new atlas module provides Kubernetes-compliant YAML generation for database schema resources. It defines database URL references and schema specification inputs, renders validated YAML output with proper quoting and indentation, and exposes the functionality through the crate's public API.

Changes

Atlas YAML generation module

Layer / File(s) Summary
Data model and core YAML rendering
distributed_tooling/src/atlas.rs
AtlasDatabaseUrl enum (secret or inline), AtlasSchemaSpec struct (name, namespace, database, dev_url, sql), and render_atlas_schema validate inputs, generate metadata/spec YAML, conditionally emit optional fields, render database URLs with quoting, and format SQL as indented literal blocks. Private helpers trim optional values and YAML-quote strings.
YAML rendering validation tests
distributed_tooling/src/atlas.rs
Unit tests verify secret and inline database URLs, optional namespace/devURL emission and quoting, SQL indentation for single/multi-statement blocks, and errors for empty name/sql or incomplete secrets.
Module exports
distributed_tooling/src/lib.rs
Module declaration and public re-exports of render_atlas_schema, AtlasDatabaseUrl, and AtlasSchemaSpec from the crate root.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A schema tool hops in so bright,
Atlas YAML rendered just right,
Secrets and URLs aligned,
Kubernetes resources refined!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Title check ⚠️ Warning The PR title mentions 'distributed_cli (dsvc) — service CLI + Atlas schema output' but the actual changes focus on the render_atlas_schema function and Atlas schema resource generation in distributed_tooling, not on a service CLI implementation. Revise the title to accurately reflect the main change: 'feat: add render_atlas_schema function for Atlas operator resource generation' or similar, removing the misleading 'distributed_cli' and 'service CLI' references.
✅ Passed checks (4 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/atlas-schema-resource

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 and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 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 `@distributed_tooling/src/atlas.rs`:
- Around line 51-69: Add Kubernetes name validation to render_atlas_schema:
implement a helper like validate_k8s_name(name: &str, field: &str) that trims
and enforces DNS subdomain rules (only lowercase a-z, digits, and '-' ; not
empty; not start or end with '-') and returns a ScaffoldError on violation, then
call validate_k8s_name for spec.name (and for spec.namespace when
trimmed_non_empty returns Some) at the start of render_atlas_schema to return
clear errors instead of emitting invalid YAML.
🪄 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: f601d2e9-4473-44f0-9293-aa4a26eb188f

📥 Commits

Reviewing files that changed from the base of the PR and between 77e6b17 and f56dd70.

📒 Files selected for processing (2)
  • distributed_tooling/src/atlas.rs
  • distributed_tooling/src/lib.rs

Comment thread distributed_cli/src/atlas.rs
…t atlas

Make Distributed's service tooling a single in-workspace crate that is both a
binary (`dsvc`) and a library, eliminating cross-repo release coordination:

- Fold the former `distributed_tooling` crate (pure scaffold + Atlas generation)
  into `distributed_cli` as internal `generate`/`atlas` modules; the public
  generation API is re-exported from the crate root.
- Add the command surface (`cli` module): scaffold / describe / schema, ported
  from hops-cli's service adapter, with `run(&ServiceArgs)` as the dispatcher.
- `dsvc schema --format atlas` renders an AtlasSchema resource to stdout
  (flag-configured: --name/--namespace/--db-secret/--db-secret-key/--db-url/
  --dev-url); default --format sql is unchanged.
- The library exposes `ServiceArgs` + `run` so another CLI (hops) can mount the
  commands under `hops service` and dispatch — re-exporting, not reimplementing,
  so a new flag here reaches hops on a plain `cargo update`.
- Publish workflow: replace publish-tooling with publish-cli.

distributed_tooling 1.5.0 stays on crates.io for the already-merged hops-cli until
it migrates to depend on distributed_cli.

Implements [[tasks/atlas-operator-schema-gitops]]

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@patrickleet patrickleet changed the title feat: render Atlas Operator AtlasSchema resources from desired-state SQL feat: distributed_cli (dsvc) — service CLI + Atlas schema output Jun 6, 2026
patrickleet and others added 2 commits June 6, 2026 15:51
Drive the real `dsvc` binary end-to-end:
- cli_scaffold.rs: `dsvc scaffold` to a temp dir, assert the generated tree
  (fast; pure generation + filesystem; runs in normal `cargo test`).
- cli_manifest.rs: `#[ignore]`d harness e2e — `dsvc describe`,
  `schema --dialect postgres`, and `schema --format atlas` against a committed
  `orders-service` fixture (a standalone crate with its own `[workspace]` and a
  `#[derive(ReadModel)]` registered in `distributed_manifest()`). Ignored by
  default because they compile the fixture via nested cargo.
- integration-distributed-cli.yaml: reusable workflow running
  `cargo test -p distributed_cli -- --include-ignored`; referenced from the
  push-to-main pipeline and gating version-and-tag.

Implements [[tasks/distributed-cli-integration-tests]]

Co-Authored-By: Claude Opus 4.8 <[email protected]>
render_atlas_schema now rejects names that aren't RFC-1123 labels (lowercase
letters, digits, hyphens; no leading/trailing hyphen) for both metadata.name and
metadata.namespace, instead of only checking non-empty. This fails at generation
with a clear message rather than emitting YAML the API server would reject — and
guards against characters (newlines, colons, quotes) that would break the
document itself. Addresses CodeRabbit review on PR #74.

Implements [[tasks/atlas-operator-schema-gitops]]

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@patrickleet patrickleet merged commit 732ddbf into main Jun 6, 2026
7 checks passed
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.

1 participant