You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Use a production-format logger for controller-runtime in every binary #1145
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.
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.
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.
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.
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.
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.
Activity
privateip commentedon Oct 27, 2026
Verdict: valid. Reproduced on
mainat 0e028cf.Four binaries enable development mode unconditionally:
cmd/galactic-router/root.go#L87cmd/galactic-gateway/root.go#L55cmd/galactic-nat/root.go#L54cmd/galactic-vrf/root.go#L46fabric-router-controllerbuilds 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 kubeconfigerror and exits:galactic-vrfandgalactic-natwrite zap console text (tab-separated fields, a JSON fragment and a multi-line stack trace), not JSON.fabric-router-controllerwrites one zap JSON line.galactic-controllerwritesYYYY/MM/DD hh:mm:ss ERROR unable to get kubeconfig logger=controller-runtime/client/config err="...".Beyond the issue text:
galactic-controller,galactic-edgeandfabric-api gatewayroute controller-runtime throughslog.Default(). Onlyfabric-apiinstalls a JSON handler on it. Ingalactic-controllerandgalactic-edgethe 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-routerandgalactic-vrfalso log through the standardlogpackage. Once a JSON slog handler is the default, those lines go through it too.privateip commentedon Oct 27, 2026
Approved fix plan
Root cause. Four binaries hard-code
zap.New(zap.UseDevMode(true))(galactic-router,galactic-gateway,galactic-nat,galactic-vrf), andfabric-router-controllerbuilds its own zap logger.galactic-controllerandgalactic-edgebridge controller-runtime toslog.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.
internal/loggingpackage, based on fabric-api'ssetupLogging.BindFlagsadds--log-level(defaultinfo) and--log-format(jsonby default, ortext), which default fromLOG_LEVELandLOG_FORMAT.Setupinstalls one slog handler on stderr and uses it for slog's default, the standardlogpackage, controller-runtime and klog.galactic-router,galactic-gateway,galactic-nat,galactic-vrf,fabric-router-controller,galactic-controller,galactic-edgeandfabric-api. It replaces eachctrl.SetLoggercall and fabric-api's local copy.--log-format=text --log-level=debug. It goes through the same handler, so the fields match the binary's own lines.Tests. A
Setuptest checks that a controller-runtime line and a slog line are both JSON at info level with the same keys. A guard test parsescmd/and fails on any import ofcontroller-runtime/pkg/log/zapor any directSetLoggercall.Risk. Output becomes JSON at info level in eight binaries. Debug lines that development mode emitted disappear unless
LOG_LEVEL=debugis set. klog becomes a direct dependency. Each binary's configuration doc gains the two variables.Out of scope. The CNI plugins, the
galactic-cniinstaller andfabric-config-agentdon't use controller-runtime's logger. Their formats belong to #1146.fix(logging): Log controller-runtime as JSON at info in every binary