Skip to content

Commit

Permalink
enabling k8s compliant logging
Browse files Browse the repository at this point in the history
  • Loading branch information
NilanjanDaw committed Feb 16, 2022
1 parent 471d56b commit 41df339
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
13 changes: 12 additions & 1 deletion agent/help_flag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,18 @@ var _ = Describe("Help flag for host agent", func() {
"-namespace string",
"-skip-installation",
"-version",
"-log-level int",
"-add_dir_header",
"-alsologtostderr",
"-log_backtrace_at value",
"-log_dir string",
"-log_file string",
"-log_file_max_size uint",
"-logtostderr",
"-skip_headers",
"-skip_log_headers",
"-stderrthreshold value",
"-v value",
"-vmodule value",
}
)

Expand Down
21 changes: 18 additions & 3 deletions agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,16 @@ func (l *labelFlags) Set(value string) error {
}
}

func isFlagPassed(name string) bool {
found := false
flag.Visit(func(f *flag.Flag) {
if f.Name == name {
found = true
}
})
return found
}

var (
namespace string
scheme *runtime.Scheme
Expand All @@ -80,7 +90,6 @@ var (
downloadpath string
skipInstallation bool
printVersion bool
logLevel int
)

// TODO - fix logging
Expand All @@ -93,7 +102,6 @@ func main() {
flag.StringVar(&downloadpath, "downloadpath", "/var/lib/byoh/bundles", "File System path to keep the downloads")
flag.BoolVar(&skipInstallation, "skip-installation", false, "If you want to skip installation of the kubernetes component binaries")
flag.BoolVar(&printVersion, "version", false, "Print the version of the agent")
flag.IntVar(&logLevel, "log-level", 0, "Determines the verbosity of the system logs (Default: 0)")
flag.Parse()

if printVersion {
Expand All @@ -106,7 +114,14 @@ func main() {
_ = corev1.AddToScheme(scheme)
_ = clusterv1.AddToScheme(scheme)

logger := klogr.New().V(logLevel)
// checking if log level flag has been explicitly set
// else setting the flag at 1
if !isFlagPassed("v") {
flag.Set("v", "1")
}

// setting info log verbosity level at 1
logger := klogr.New().V(1)
ctrl.SetLogger(logger)
config, err := ctrl.GetConfig()
if err != nil {
Expand Down

0 comments on commit 41df339

Please sign in to comment.