diff --git a/cmd/controller/main.go b/cmd/controller/main.go index 742ea39319..7ed9dcb24d 100644 --- a/cmd/controller/main.go +++ b/cmd/controller/main.go @@ -17,8 +17,11 @@ package main import ( "github.com/kanisterio/kanister/pkg/kancontroller" + "github.com/kanisterio/kanister/pkg/log" ) func main() { + log.SetupClusterNameInLogVars() + kancontroller.Execute() } diff --git a/cmd/kanctl/main.go b/cmd/kanctl/main.go index 81aef8fbeb..07f3cb2328 100644 --- a/cmd/kanctl/main.go +++ b/cmd/kanctl/main.go @@ -17,6 +17,7 @@ package main import ( "github.com/kanisterio/kanister/pkg/kanctl" + "github.com/kanisterio/kanister/pkg/log" ) func init() { @@ -25,5 +26,7 @@ func init() { } func main() { + log.SetupClusterNameInLogVars() + kanctl.Execute() } diff --git a/cmd/reposervercontroller/main.go b/cmd/reposervercontroller/main.go index a08bca184b..7ecd238aa6 100644 --- a/cmd/reposervercontroller/main.go +++ b/cmd/reposervercontroller/main.go @@ -68,6 +68,8 @@ func main() { flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.") logLevel := getLogLevel() + log.SetupClusterNameInLogVars() + opts := zap.Options{ Level: logLevel, } diff --git a/pkg/log/log.go b/pkg/log/log.go index a5155afb82..d40f22f4b4 100644 --- a/pkg/log/log.go +++ b/pkg/log/log.go @@ -93,7 +93,11 @@ func initEnvVarFields() { envVarFields = field.Add(envVarFields, strings.ToLower(e), ev) } } +} +// SetupClusterNameInLogVars sets up the `cluster_name` field in `envVarFields` +// so that it can be printed with the logs. +func SetupClusterNameInLogVars() { if clsName, err := config.GetClusterName(nil); err == nil { envVarFields = field.Add(envVarFields, "cluster_name", clsName) }