Skip to content

Use a production-format logger for controller-runtime in every binary #1145

Closed

Description

@privateip

Parent: #1144

Deliverable: No Galactic binary runs controller-runtime's logger in development mode in production.

Several long-running binaries hand controller-runtime a development-mode logger unconditionally. As a result, controller-runtime's own lines (reconciler errors, cache and leader-election messages) are written as console text at debug level instead of structured JSON at info level. The log pipeline can't parse them into fields, and development mode also turns some recoverable conditions into panics. One more binary builds controller-runtime's logger separately from the rest of its logging.

This fix is independent of the library adoption and doesn't need to wait for it.

Work items:

  • Route controller-runtime's logger through each binary's existing structured logger, the same way the binaries that already do this are wired.
  • Keep development mode available only behind an explicit opt-in for local runs.
  • Add a test, or extend an existing one, that fails if a binary turns development mode on unconditionally.

Dependencies: none.

Acceptance: In the lab, controller-runtime's lines from every affected binary are JSON at info level, with the same fields as the binary's own lines. No binary enables development mode without an explicit opt-in.

Activity

  1. added
    tech-debt
    on Oct 27, 2026
  2. added theissue type on Oct 27, 2026
  3. self-assigned this
    on Oct 27, 2026
  4. privateip commented on Oct 27, 2026

    @privateip
    ContributorAuthor

    Verdict: valid. Reproduced on main at 0e028cf.

    Four binaries enable development mode unconditionally:

    fabric-router-controller builds a separate zap logger (cmd/fabric-router-controller/run.go#L60). Its controller-runtime lines are JSON, but they're built apart from the rest of its logging.

    Reproduction. I built each binary and ran it with no kubeconfig, so controller-runtime logs its unable to get kubeconfig error and exits:

    • galactic-vrf and galactic-nat write zap console text (tab-separated fields, a JSON fragment and a multi-line stack trace), not JSON.
    • fabric-router-controller writes one zap JSON line.
    • galactic-controller writes YYYY/MM/DD hh:mm:ss ERROR unable to get kubeconfig logger=controller-runtime/client/config err="...".

    Beyond the issue text:

    • galactic-controller, galactic-edge and fabric-api gateway route controller-runtime through slog.Default(). Only fabric-api installs a JSON handler on it. In galactic-controller and galactic-edge the default is still Go's built-in text handler, so their controller-runtime lines are text, not JSON, even though they're wired the way the issue describes. Routing the four dev-mode binaries the same way wouldn't meet the acceptance criterion on its own. Each binary has to install a JSON handler first.
    • galactic-router and galactic-vrf also log through the standard log package. Once a JSON slog handler is the default, those lines go through it too.
    • client-go's leader election logs through klog, which controller-runtime's logger doesn't cover. Without separate wiring, its lines stay klog text.
  5. privateip commented on Oct 27, 2026

    @privateip
    ContributorAuthor

    Approved fix plan

    Root cause. Four binaries hard-code zap.New(zap.UseDevMode(true)) (galactic-router, galactic-gateway, galactic-nat, galactic-vrf), and fabric-router-controller builds its own zap logger. galactic-controller and galactic-edge bridge controller-runtime to slog.Default(), but nothing installs a JSON handler on it, so their lines are Go's default text. client-go's leader election logs through klog, which nothing wires.

    Fix.

    1. Add an internal/logging package, based on fabric-api's setupLogging. BindFlags adds --log-level (default info) and --log-format (json by default, or text), which default from LOG_LEVEL and LOG_FORMAT. Setup installs one slog handler on stderr and uses it for slog's default, the standard log package, controller-runtime and klog.
    2. Call it in every binary that runs controller-runtime: galactic-router, galactic-gateway, galactic-nat, galactic-vrf, fabric-router-controller, galactic-controller, galactic-edge and fabric-api. It replaces each ctrl.SetLogger call and fabric-api's local copy.
    3. Development output is opt-in: --log-format=text --log-level=debug. It goes through the same handler, so the fields match the binary's own lines.

    Tests. A Setup test checks that a controller-runtime line and a slog line are both JSON at info level with the same keys. A guard test parses cmd/ and fails on any import of controller-runtime/pkg/log/zap or any direct SetLogger call.

    Risk. Output becomes JSON at info level in eight binaries. Debug lines that development mode emitted disappear unless LOG_LEVEL=debug is set. klog becomes a direct dependency. Each binary's configuration doc gains the two variables.

    Out of scope. The CNI plugins, the galactic-cni installer and fabric-config-agent don't use controller-runtime's logger. Their formats belong to #1146.

  6. added a commit that references this issue on Oct 27, 2026
    765f671
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

tech-debt

Type

Fields

Priority

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions