Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set cluster_name var in logs vars separately and not in init #2777

Merged
merged 2 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cmd/controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
3 changes: 3 additions & 0 deletions cmd/kanctl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package main

import (
"github.com/kanisterio/kanister/pkg/kanctl"
"github.com/kanisterio/kanister/pkg/log"
)

func init() {
Expand All @@ -25,5 +26,7 @@ func init() {
}

func main() {
log.SetupClusterNameInLogVars()

kanctl.Execute()
}
2 changes: 2 additions & 0 deletions cmd/reposervercontroller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down