From 2733c2312106fb31a95ee62e129af58b4ea7409e Mon Sep 17 00:00:00 2001 From: Vatsal Parekh Date: Tue, 10 Sep 2024 11:51:57 +0530 Subject: [PATCH] Add debug flag for log level Signed-off-by: Vatsal Parekh --- main.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/main.go b/main.go index cbed4b8e..fc0ad0e6 100644 --- a/main.go +++ b/main.go @@ -19,11 +19,13 @@ import ( var ( masterURL string kubeconfigFile string + debug bool ) func init() { flag.StringVar(&kubeconfigFile, "kubeconfig", "", "Path to a kubeconfig. Only required if out-of-cluster.") flag.StringVar(&masterURL, "master", "", "The address of the Kubernetes API server. Overrides any value in kubeconfig. Only required if out-of-cluster.") + flag.BoolVar(&debug, "debug", false, "Variable to set log level to debug; default is false") flag.Parse() } @@ -31,6 +33,11 @@ func main() { // set up signals so we handle the first shutdown signal gracefully ctx := signals.SetupSignalContext() + if debug { + logrus.SetLevel(logrus.DebugLevel) + logrus.Debugf("Loglevel set to [%v]", logrus.DebugLevel) + } + // This will load the kubeconfig file in a style the same as kubectl cfg, err := kubeconfig.GetNonInteractiveClientConfig(kubeconfigFile).ClientConfig() if err != nil {