Skip to content

feat: resource type dependencies#291

Open
jason-lynch wants to merge 1 commit intomainfrom
feat/PLAT-417/resource-type-dependencies
Open

feat: resource type dependencies#291
jason-lynch wants to merge 1 commit intomainfrom
feat/PLAT-417/resource-type-dependencies

Conversation

@jason-lynch
Copy link
Member

Summary

Adds a new TypeDependencies method to the Resource interface that enables resources to declare a dependency on all resources of a given type without having to use specific IDs. This is useful for ensuring that a particular resource is only updated after all resources of a particular type have been updated, or that a particular resource should be updated any time a resource of a specific type is updated. This will be used for a pg_service.conf resource in a subsequent PR.

Testing

There are no functionality changes in this PR.

PLAT-417

@coderabbitai
Copy link

coderabbitai bot commented Mar 9, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f9b79f7c-387f-4b8d-acd4-ce0fd8653d5b

📥 Commits

Reviewing files that changed from the base of the PR and between 29af08f and 53394ff.

📒 Files selected for processing (36)
  • server/internal/database/instance_resource.go
  • server/internal/database/lag_tracker_commit_ts_resource.go
  • server/internal/database/node_resource.go
  • server/internal/database/operations/helpers_test.go
  • server/internal/database/replication_slot_advance_from_cts_resource.go
  • server/internal/database/replication_slot_create_resource.go
  • server/internal/database/replication_slot_resource.go
  • server/internal/database/subscription_resource.go
  • server/internal/database/switchover_resource.go
  • server/internal/database/sync_event_resource.go
  • server/internal/database/wait_for_sync_event_resource.go
  • server/internal/filesystem/dir_resource.go
  • server/internal/monitor/instance_monitor_resource.go
  • server/internal/monitor/service_instance_monitor_resource.go
  • server/internal/orchestrator/swarm/check_will_restart.go
  • server/internal/orchestrator/swarm/etcd_creds.go
  • server/internal/orchestrator/swarm/mcp_config_resource.go
  • server/internal/orchestrator/swarm/network.go
  • server/internal/orchestrator/swarm/patroni_cluster.go
  • server/internal/orchestrator/swarm/patroni_config.go
  • server/internal/orchestrator/swarm/patroni_member.go
  • server/internal/orchestrator/swarm/pgbackrest_config.go
  • server/internal/orchestrator/swarm/pgbackrest_restore.go
  • server/internal/orchestrator/swarm/pgbackrest_stanza.go
  • server/internal/orchestrator/swarm/postgres_certs.go
  • server/internal/orchestrator/swarm/postgres_service.go
  • server/internal/orchestrator/swarm/postgres_service_spec.go
  • server/internal/orchestrator/swarm/scale_service.go
  • server/internal/orchestrator/swarm/service_instance.go
  • server/internal/orchestrator/swarm/service_instance_spec.go
  • server/internal/orchestrator/swarm/service_user_role.go
  • server/internal/orchestrator/swarm/switchover.go
  • server/internal/resource/resource.go
  • server/internal/resource/state.go
  • server/internal/resource/state_test.go
  • server/internal/scheduler/scheduled_job_resource.go
🚧 Files skipped from review as they are similar to previous changes (18)
  • server/internal/database/node_resource.go
  • server/internal/filesystem/dir_resource.go
  • server/internal/database/replication_slot_create_resource.go
  • server/internal/orchestrator/swarm/switchover.go
  • server/internal/orchestrator/swarm/patroni_config.go
  • server/internal/database/operations/helpers_test.go
  • server/internal/orchestrator/swarm/postgres_service_spec.go
  • server/internal/database/lag_tracker_commit_ts_resource.go
  • server/internal/orchestrator/swarm/postgres_service.go
  • server/internal/orchestrator/swarm/scale_service.go
  • server/internal/orchestrator/swarm/pgbackrest_stanza.go
  • server/internal/database/instance_resource.go
  • server/internal/orchestrator/swarm/service_instance_spec.go
  • server/internal/resource/resource.go
  • server/internal/orchestrator/swarm/network.go
  • server/internal/orchestrator/swarm/postgres_certs.go
  • server/internal/database/sync_event_resource.go
  • server/internal/orchestrator/swarm/etcd_creds.go

📝 Walkthrough

Walkthrough

Adds type-level dependency support: a new Resource.TypeDependencies() method is added and implemented across resources; ResourceData and state graph logic updated to record and evaluate type-based dependencies; test helpers and tests updated accordingly.

Changes

Cohort / File(s) Summary
Database Resources
server/internal/database/instance_resource.go, server/internal/database/lag_tracker_commit_ts_resource.go, server/internal/database/node_resource.go, server/internal/database/replication_slot_advance_from_cts_resource.go, server/internal/database/replication_slot_create_resource.go, server/internal/database/replication_slot_resource.go, server/internal/database/subscription_resource.go, server/internal/database/switchover_resource.go, server/internal/database/sync_event_resource.go, server/internal/database/wait_for_sync_event_resource.go
Added TypeDependencies() []resource.Type to multiple DB resource types (all return nil).
Filesystem
server/internal/filesystem/dir_resource.go
Added TypeDependencies() []resource.Type returning nil.
Monitor
server/internal/monitor/instance_monitor_resource.go, server/internal/monitor/service_instance_monitor_resource.go
Added TypeDependencies() []resource.Type returning nil.
Orchestrator / Swarm
server/internal/orchestrator/swarm/check_will_restart.go, server/internal/orchestrator/swarm/etcd_creds.go, server/internal/orchestrator/swarm/mcp_config_resource.go, server/internal/orchestrator/swarm/network.go, server/internal/orchestrator/swarm/patroni_cluster.go, server/internal/orchestrator/swarm/patroni_config.go, server/internal/orchestrator/swarm/patroni_member.go, server/internal/orchestrator/swarm/pgbackrest_config.go, server/internal/orchestrator/swarm/pgbackrest_restore.go, server/internal/orchestrator/swarm/pgbackrest_stanza.go, server/internal/orchestrator/swarm/postgres_certs.go, server/internal/orchestrator/swarm/postgres_service.go, server/internal/orchestrator/swarm/postgres_service_spec.go, server/internal/orchestrator/swarm/scale_service.go, server/internal/orchestrator/swarm/service_instance.go, server/internal/orchestrator/swarm/service_instance_spec.go, server/internal/orchestrator/swarm/service_user_role.go, server/internal/orchestrator/swarm/switchover.go
Added TypeDependencies() []resource.Type across swarm resources (return nil).
Scheduler
server/internal/scheduler/scheduled_job_resource.go
Added compile-time interface assertion and TypeDependencies() []resource.Type returning nil.
Test helpers (db/orchestrator)
server/internal/database/operations/helpers_test.go
Added TypeDependencies() []resource.Type on test helper type, returning nil.
Core Resource API
server/internal/resource/resource.go
Extended Resource interface with TypeDependencies() []Type; added TypeDependencies []Type to ResourceData; updated ToResourceData and Clone to propagate the new field.
Resource State & Graph
server/internal/resource/state.go
Reworked graph construction to track nodes by Type, create edges for type-level dependencies, introduced addEdge helper, track modified types, and added AllFromState / AllFromContext utilities.
State Tests
server/internal/resource/state_test.go
Updated test helpers/types for type-aware IDs and dependencies: added TestType/TestTypeDependencies, changed testResourceID signature, added TypeDependencies() on testResource, and added/updated tests covering type-based and self-referential cases.

Poem

🐇 I nibble edges and weave the threads,
Types now link where hopping leads,
Small methods added, quiet and bright,
The graph can follow type by type,
A carrot cheer for mapped-out deeds!

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive The PR description covers the essential sections: Summary explains the feature, Testing confirms no functionality changes. However, the Checklist section from the template is completely missing, and Changes section is absent. Add the missing Checklist items (Tests added/updated, Documentation updated, Issue linked, Changelog entry, Breaking changes callout) and expand Changes section with a high-level bulleted list of modifications.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat: resource type dependencies' clearly and concisely summarizes the main change: adding a new TypeDependencies feature to the Resource interface.

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

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/PLAT-417/resource-type-dependencies
📝 Coding Plan
  • Generate coding plan for human review comments

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.

@jason-lynch jason-lynch force-pushed the feat/PLAT-417/stable-random-ports branch from f7bc019 to aaf891b Compare March 9, 2026 22:37
@jason-lynch jason-lynch force-pushed the feat/PLAT-417/resource-type-dependencies branch 3 times, most recently from 9df990e to ae1a213 Compare March 10, 2026 14:30
@jason-lynch jason-lynch force-pushed the feat/PLAT-417/stable-random-ports branch from 46a8e09 to 924237c Compare March 10, 2026 14:30
@jason-lynch jason-lynch force-pushed the feat/PLAT-417/resource-type-dependencies branch 3 times, most recently from 31a709a to f647f73 Compare March 10, 2026 16:39
@jason-lynch jason-lynch force-pushed the feat/PLAT-417/stable-random-ports branch 2 times, most recently from f0c226e to 13e6ece Compare March 10, 2026 19:42
@jason-lynch jason-lynch force-pushed the feat/PLAT-417/resource-type-dependencies branch from f647f73 to 29af08f Compare March 10, 2026 21:01
@jason-lynch
Copy link
Member Author

@coderabbitai review

@coderabbitai
Copy link

coderabbitai bot commented Mar 10, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

@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 the current code and only fix it if needed.

Inline comments:
In `@server/internal/resource/state_test.go`:
- Around line 310-311: Update the incorrect inline comment: replace the phrase
"type dependency on resource 1" with "type dependency on testResourceType" so it
correctly explains that resource1 is marked for update because it has a type
dependency on the testResourceType that resource2 belongs to (referencing
resource1, resource2, and testResourceType in the test).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1fb24061-cd74-4244-8cd9-d2f10ecd3881

📥 Commits

Reviewing files that changed from the base of the PR and between 13e6ece and 29af08f.

📒 Files selected for processing (36)
  • server/internal/database/instance_resource.go
  • server/internal/database/lag_tracker_commit_ts_resource.go
  • server/internal/database/node_resource.go
  • server/internal/database/operations/helpers_test.go
  • server/internal/database/replication_slot_advance_from_cts_resource.go
  • server/internal/database/replication_slot_create_resource.go
  • server/internal/database/replication_slot_resource.go
  • server/internal/database/subscription_resource.go
  • server/internal/database/switchover_resource.go
  • server/internal/database/sync_event_resource.go
  • server/internal/database/wait_for_sync_event_resource.go
  • server/internal/filesystem/dir_resource.go
  • server/internal/monitor/instance_monitor_resource.go
  • server/internal/monitor/service_instance_monitor_resource.go
  • server/internal/orchestrator/swarm/check_will_restart.go
  • server/internal/orchestrator/swarm/etcd_creds.go
  • server/internal/orchestrator/swarm/mcp_config_resource.go
  • server/internal/orchestrator/swarm/network.go
  • server/internal/orchestrator/swarm/patroni_cluster.go
  • server/internal/orchestrator/swarm/patroni_config.go
  • server/internal/orchestrator/swarm/patroni_member.go
  • server/internal/orchestrator/swarm/pgbackrest_config.go
  • server/internal/orchestrator/swarm/pgbackrest_restore.go
  • server/internal/orchestrator/swarm/pgbackrest_stanza.go
  • server/internal/orchestrator/swarm/postgres_certs.go
  • server/internal/orchestrator/swarm/postgres_service.go
  • server/internal/orchestrator/swarm/postgres_service_spec.go
  • server/internal/orchestrator/swarm/scale_service.go
  • server/internal/orchestrator/swarm/service_instance.go
  • server/internal/orchestrator/swarm/service_instance_spec.go
  • server/internal/orchestrator/swarm/service_user_role.go
  • server/internal/orchestrator/swarm/switchover.go
  • server/internal/resource/resource.go
  • server/internal/resource/state.go
  • server/internal/resource/state_test.go
  • server/internal/scheduler/scheduled_job_resource.go

@jason-lynch jason-lynch force-pushed the feat/PLAT-417/stable-random-ports branch from 13e6ece to c3bdad2 Compare March 11, 2026 12:58
@jason-lynch jason-lynch force-pushed the feat/PLAT-417/resource-type-dependencies branch from 29af08f to bf3dd8b Compare March 11, 2026 12:58
@jason-lynch jason-lynch force-pushed the feat/PLAT-417/stable-random-ports branch from c3bdad2 to 40aab30 Compare March 11, 2026 13:25
@jason-lynch jason-lynch force-pushed the feat/PLAT-417/resource-type-dependencies branch from bf3dd8b to 0508e04 Compare March 11, 2026 13:25
@jason-lynch jason-lynch force-pushed the feat/PLAT-417/stable-random-ports branch from 40aab30 to 7a71fcb Compare March 11, 2026 13:43
@jason-lynch jason-lynch force-pushed the feat/PLAT-417/resource-type-dependencies branch from 0508e04 to 7f89e1e Compare March 11, 2026 13:43
@jason-lynch jason-lynch force-pushed the feat/PLAT-417/resource-type-dependencies branch from 7f89e1e to b6a8fb4 Compare March 11, 2026 13:49
@rshoemaker rshoemaker self-assigned this Mar 11, 2026
Copy link
Contributor

@rshoemaker rshoemaker left a comment

Choose a reason for hiding this comment

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

Looks good - return nil 👍

one edge-case question below (pun-intended)...

})
addEdge(opts, g, from, to)
}
for _, ty := range resource.TypeDependencies {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this inner-loop may allow a self-referential edge to be added - is that something you think we'll ever need? I'm not sure it would cause an issue for the graph library, but I think it could happen if a resource declared itself as a typedep (again, no idea why anyone would do that...)

Copy link
Member Author

Choose a reason for hiding this comment

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

That's a good call-out! There's no good reason to do that, and the graph library panics if you try. I'll add a check and return a nicer error for that. We already return an error in our topological sort for any cycle, so it's just the self-reference case that's missing a friendly error right now.

@jason-lynch jason-lynch force-pushed the feat/PLAT-417/stable-random-ports branch from 7a71fcb to 30edbed Compare March 12, 2026 19:28
@jason-lynch jason-lynch force-pushed the feat/PLAT-417/resource-type-dependencies branch from b6a8fb4 to 53593e9 Compare March 12, 2026 19:28
Base automatically changed from feat/PLAT-417/stable-random-ports to main March 12, 2026 21:16
Adds a new `TypeDependencies` method to the `Resource` interface that
enables resources to declare a dependency on all resources of a given
type without having to use specific IDs. This is useful for ensuring
that a particular resource is only updated after all resources of a
particular type have been updated, or that a particular resource should
be updated any time a resource of a specific type is updated. This will
be used for a pg_service.conf resource in a subsequent PR.

PLAT-417
@jason-lynch jason-lynch force-pushed the feat/PLAT-417/resource-type-dependencies branch from 53593e9 to 53394ff Compare March 12, 2026 21:17
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.

2 participants