fix: invalidate services for systemd clusters#363
Conversation
We do not yet support services for systemd clusters. This commit adds API validation to return errors early.
📝 WalkthroughWalkthroughThe change modifies service validation in Changes
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Duplication | 0 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes. Give us feedback
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
server/internal/api/apiv1/validate.go (1)
137-145: Minor: skip port-owner seeding on SystemD path.
seedPostgresPortsand theportOwnermap are built unconditionally but unused when the orchestrator is SystemD (no per-service port validation runs). Consider moving the seed into thedefaultbranch to avoid the wasted allocation/iteration.Proposed tweak
- // Validate services — seed portOwner with Postgres ports so services can't collide with the database. - portOwner := make(servicePortOwnerMap) - seedPostgresPorts(spec, portOwner) - servicesPath := []string{"services"} switch orchestrator { case config.OrchestratorSystemD: if len(spec.Services) != 0 { errs = append(errs, newValidationError(errors.New("services are not yet supported for systemd clusters"), servicesPath)) } default: + // Seed portOwner with Postgres ports so services can't collide with the database. + portOwner := make(servicePortOwnerMap) + seedPostgresPorts(spec, portOwner) seenServiceIDs := make(ds.Set[string], len(spec.Services))🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@server/internal/api/apiv1/validate.go` around lines 137 - 145, The code currently allocates portOwner (servicePortOwnerMap) and calls seedPostgresPorts(spec, portOwner) unconditionally even when orchestrator == config.OrchestratorSystemD and those values are never used; move the portOwner creation and the seedPostgresPorts(spec, portOwner) call into the non-SystemD path (e.g., the default branch of the switch over orchestrator) so that seedPostgresPorts is only invoked when per-service validation runs, keeping the SystemD case untouched (reference: portOwner, servicePortOwnerMap, seedPostgresPorts, orchestrator, config.OrchestratorSystemD).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@server/internal/api/apiv1/validate.go`:
- Around line 140-162: validateDatabaseUpdate currently validates new.Services
without checking the orchestrator, allowing services to be added to systemd
clusters; thread the orchestrator (config.Orchestrator) into
validateDatabaseUpdate (and update its callers in convert.go) and add the same
SystemD guard used in validateDatabaseSpec: if orchestrator ==
config.OrchestratorSystemD then reject non-empty new.Services with a validation
error (same message as in validateDatabaseSpec), otherwise continue to iterate
new.Services and call validateServicePortConflicts and validateServiceSpec as
before; ensure parameter names (validateDatabaseUpdate, validateDatabaseSpec,
new.Services, validateServicePortConflicts, validateServiceSpec, and convert.go
callers) are updated accordingly.
---
Nitpick comments:
In `@server/internal/api/apiv1/validate.go`:
- Around line 137-145: The code currently allocates portOwner
(servicePortOwnerMap) and calls seedPostgresPorts(spec, portOwner)
unconditionally even when orchestrator == config.OrchestratorSystemD and those
values are never used; move the portOwner creation and the
seedPostgresPorts(spec, portOwner) call into the non-SystemD path (e.g., the
default branch of the switch over orchestrator) so that seedPostgresPorts is
only invoked when per-service validation runs, keeping the SystemD case
untouched (reference: portOwner, servicePortOwnerMap, seedPostgresPorts,
orchestrator, config.OrchestratorSystemD).
🪄 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: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 7029d778-7c83-4a8c-b165-08f8ee6954f3
📒 Files selected for processing (1)
server/internal/api/apiv1/validate.go
Summary
We do not yet support services for systemd clusters. This commit adds API validation to return errors early.
Testing