Skip to content

refactor(orchestrator): extract run() into pkg/factories for reuse#2219

Open
sitole wants to merge 3 commits intomainfrom
feat/orchestrator-factories-run
Open

refactor(orchestrator): extract run() into pkg/factories for reuse#2219
sitole wants to merge 3 commits intomainfrom
feat/orchestrator-factories-run

Conversation

@sitole
Copy link
Member

@sitole sitole commented Mar 24, 2026

Move the orchestrator lifecycle logic into an exported factories.Run() function with an Options struct that accepts Version, CommitSHA, and an EgressFactory callback. This allows orchestrator-ee to reuse the full init/shutdown flow while plugging in its own egress proxy implementation.

Move the orchestrator lifecycle logic into an exported factories.Run()
function with an Options struct that accepts Version, CommitSHA, and an
EgressFactory callback. This allows orchestrator-ee to reuse the full
init/shutdown flow while plugging in its own egress proxy implementation.
Guard against nil EgressFactory in Run() with a clear fatal message
instead of a cryptic panic. Also guard against EgressFactory returning
(nil, nil) before accessing EgressSetup fields.
@sitole sitole marked this pull request as ready for review March 24, 2026 15:37
@cursor
Copy link

cursor bot commented Mar 24, 2026

PR Summary

Medium Risk
Medium risk because it reshapes orchestrator bootstrap/shutdown wiring and service lifecycles (telemetry, servers, and egress proxy) even though the underlying logic is largely moved verbatim. Misconfigured EgressFactory/hooks or subtle init-order differences could change runtime behavior or shutdown sequencing.

Overview
Extracts the orchestrator’s full init/run/drain/shutdown flow into exported factories.Run(opts) so other editions can reuse it, with a new Options struct and an EgressFactory callback to supply the egress proxy plus optional start/close hooks. main.go is reduced to calling factories.Run and now provides the default egress implementation via tcpfirewall, which is started and closed through the new factory-driven lifecycle.

Written by Cursor Bugbot for commit 2c3938e. This will update automatically on new commits. Configure here.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2c3938eedb

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +140 to +142
if !success {
os.Exit(1)
}

Choose a reason for hiding this comment

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

P2 Badge Move process exit decision out of factories.Run

Run is now exported from pkg/factories for reuse, but it still calls os.Exit(1) internally on failure. That makes the bool return value effectively unusable for error handling and prevents callers (e.g., other binaries/tests reusing this package) from running their own cleanup/defer logic when startup/shutdown fails. Returning the failure and letting the top-level main decide whether to exit preserves reuse without forcing process termination from a library entrypoint.

Useful? React with 👍 / 👎.

Comment on lines +522 to +523
slotStorage, err := newStorage(ctx, nodeID, config.NetworkConfig, egressSetup.Proxy)
if err != nil {

Choose a reason for hiding this comment

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

P2 Badge Reject EgressSetup values with nil Proxy

The new callback path accepts EgressFactory output and only checks whether egressSetup itself is nil, then passes egressSetup.Proxy into network storage creation without validation. If a custom factory accidentally returns a nil proxy, slot lifecycle code later calls s.egressProxy.OnSlotCreate/OnSlotDelete (packages/orchestrator/pkg/sandbox/network/network.go), which will panic at runtime when a slot is created or removed. Add an explicit nil-proxy guard (or default to network.NoopEgressProxy) at construction time.

Useful? React with 👍 / 👎.

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