Skip to content

Make HAProxy configurable#240

Open
mclasmeier wants to merge 13 commits into
mainfrom
mc/haproxy-configurable
Open

Make HAProxy configurable#240
mclasmeier wants to merge 13 commits into
mainfrom
mc/haproxy-configurable

Conversation

@mclasmeier

@mclasmeier mclasmeier commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • New Features
    • Added a global --config/-c option to load YAML configuration, including reading from standard input.
    • Added support for configuring the HAProxy bind port via deployment settings.
    • Central connection details now show the forwarded HTTP URL when HAProxy is active.
  • Bug Fixes
    • Improved and unified configuration assembly across deploy and teardown commands (including consistent error handling).
    • Fixed shell/subshell command argument handling and corrected the deploy environment passed into subshell execution.
    • Refined HAProxy startup, banner output, and cleanup behavior for more reliable availability handling.
  • Tests
    • Added unit tests for rendered HAProxy configuration.

@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The change centralizes command configuration assembly, moves the config-file flag to the root command, adds configurable HAProxy bind ports, propagates Roxie settings through subshell execution, and records the active HAProxy port for Central connection output.

Changes

Configuration and HAProxy command flow

Layer / File(s) Summary
Centralized command configuration assembly
internal/deployer/config.go, cmd/config.go, cmd/main.go, cmd/flags.go, cmd/deploy.go, cmd/teardown.go, cmd/deploy_test.go
Configuration now combines defaults, optional user defaults, YAML file input, and command-line patches through shared merge behavior; the config flag is registered persistently and deploy flag tests use the root command path.
Configurable HAProxy subshell lifecycle
internal/types/central_deployment_info.go, internal/haproxy/*, cmd/subshell.go, cmd/deploy.go, cmd/shell.go
Roxie HAProxy settings propagate into subshell execution, rendered configuration uses the selected bind port, startup is conditional with deferred cleanup, and banners use the recorded HAProxy port.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Command
  participant runCommandOrSubshell
  participant tryStartHAProxy
  participant startHAProxy
  participant HAProxy
  Command->>runCommandOrSubshell: RoxieConfig
  runCommandOrSubshell->>tryStartHAProxy: CentralDeploymentInfo
  tryStartHAProxy->>startHAProxy: Validated startup request
  startHAProxy->>HAProxy: Start with rendered config and bind port
  HAProxy-->>runCommandOrSubshell: Active HAProxyPort
  runCommandOrSubshell-->>Command: Forwarded Central connection
Loading

Possibly related PRs

  • stackrox/roxie#201: Related subshell, HAProxy, banner, and Central deployment state changes.
  • stackrox/roxie#203: Related configuration assembly and YAML/user-default merging changes.

Suggested reviewers: alexvulaj, porridge

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 22.73% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: HAProxy settings are now configurable through deployer config and CLI wiring.
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.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch mc/haproxy-configurable

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.

cmd/flags.go, cmd/main.go:
  Enable flag inheritance for --config, so that it is available on
  subcommands.

cmd/deploy_test.go:
  Extract subcommand from root command so that they related a
  parent/child
  and therefore parsing of `--config` works as expected.
@mclasmeier mclasmeier force-pushed the mc/haproxy-configurable branch from 51d181c to 301552d Compare July 13, 2026 14:17

@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.

🧹 Nitpick comments (1)
cmd/subshell.go (1)

150-153: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Consider capturing HAProxy stderr for diagnostics.

cmd.Stderr = nil discards all HAProxy error output. If HAProxy fails to bind or encounters config errors, there's no diagnostic information. Since cmd.Start() only verifies the process launched (not that it runs successfully), a silent startup failure would leave the user with a banner advertising a URL that doesn't work.

♻️ Proposed refactor: capture stderr for error reporting
 cmd := exec.Command("haproxy", "-f", configPath)
 cmd.Stdin = nil
 cmd.Stdout = nil
-cmd.Stderr = nil
+var stderr bytes.Buffer
+cmd.Stderr = &stderr
 
 if err := cmd.Start(); err != nil {
 	os.Remove(configPath)
 	return nil, "", fmt.Errorf("failed to start haproxy: %w", err)
 }
+// Give HAProxy a moment to fail on config/bind errors.
+time.Sleep(200 * time.Millisecond)
+if cmd.ProcessState != nil && cmd.ProcessState.Exited() {
+	os.Remove(configPath)
+	return nil, "", fmt.Errorf("haproxy exited immediately: %s", stderr.String())
+}
 
 centralDeploymentInfo.HAProxyPort = roxieConfig.HAProxy.BindPort
🤖 Prompt for 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.

In `@cmd/subshell.go` around lines 150 - 153, Update the HAProxy command setup
around exec.Command to capture stderr instead of discarding it, and use the
captured diagnostic output when cmd.Start or subsequent startup handling reports
failure. Preserve the existing stdin/stdout behavior while ensuring bind and
configuration errors are surfaced to the user rather than leaving a misleading
success banner.
🤖 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.

Nitpick comments:
In `@cmd/subshell.go`:
- Around line 150-153: Update the HAProxy command setup around exec.Command to
capture stderr instead of discarding it, and use the captured diagnostic output
when cmd.Start or subsequent startup handling reports failure. Preserve the
existing stdin/stdout behavior while ensuring bind and configuration errors are
surfaced to the user rather than leaving a misleading success banner.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Enterprise

Run ID: 0abbd1c6-ac9a-4d12-bbff-21702a5b8f7c

📥 Commits

Reviewing files that changed from the base of the PR and between 51d181c and 301552d.

📒 Files selected for processing (9)
  • cmd/deploy.go
  • cmd/deploy_test.go
  • cmd/flags.go
  • cmd/main.go
  • cmd/shell.go
  • cmd/subshell.go
  • internal/deployer/config.go
  • internal/haproxy/config.go
  • internal/haproxy/config_test.go
🚧 Files skipped from review as they are similar to previous changes (4)
  • cmd/shell.go
  • internal/deployer/config.go
  • cmd/deploy.go
  • cmd/main.go

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