Skip to content

Commit

Permalink
Merge pull request #1849 from carlosrodfern/main
Browse files Browse the repository at this point in the history
feat(operator): allow to set log level
  • Loading branch information
DelusionalOptimist authored Aug 21, 2024
2 parents 63534ca + 5cedaca commit bed86b5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
11 changes: 10 additions & 1 deletion pkg/KubeArmorOperator/cmd/operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/kubearmor/KubeArmor/pkg/KubeArmorOperator/k8s"
"github.com/spf13/cobra"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
apiextensionsclientset "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/util/homedir"
Expand All @@ -28,11 +29,18 @@ var DeploymentName string
var ExtClient *apiextensionsclientset.Clientset
var Opv1Client *opv1client.Clientset
var InitDeploy bool
var LogLevel string

// Cmd represents the base command when called without any subcommands
var Cmd = &cobra.Command{
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
log, _ := zap.NewProduction()
level, err := zapcore.ParseLevel(LogLevel)
if err != nil {
return errors.New("unable to parse log level")
}
config := zap.NewProductionConfig()
config.Level.SetLevel(level)
log, _ := config.Build()
Logger = log.Sugar()
K8sClient = k8s.NewClient(*Logger, KubeConfig)
ExtClient = k8s.NewExtClient(*Logger, KubeConfig)
Expand Down Expand Up @@ -72,6 +80,7 @@ func init() {
Cmd.PersistentFlags().StringVar(&DeploymentName, "deploymentName", "kubearmor-operator", "operator deployment name")
// TODO:- set initDeploy to false by default once this change is added to stable
Cmd.PersistentFlags().BoolVar(&InitDeploy, "initDeploy", true, "Init container deployment")
Cmd.PersistentFlags().StringVar(&LogLevel, "loglevel", "info", "log level, e.g., debug, info, warn, error")
}

// Execute adds all child commands to the root command and sets flags appropriately.
Expand Down
11 changes: 10 additions & 1 deletion pkg/KubeArmorOperator/cmd/snitch-cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
runtimepkg "github.com/kubearmor/KubeArmor/pkg/KubeArmorOperator/runtime"
"github.com/spf13/cobra"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/rand"
Expand All @@ -43,11 +44,18 @@ var LsmOrder string
var PathPrefix string = "/rootfs"
var NodeName string
var Runtime string
var LogLevel string

// Cmd represents the base command when called without any subcommands
var Cmd = &cobra.Command{
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
log, _ := zap.NewProduction()
level, err := zapcore.ParseLevel(LogLevel)
if err != nil {
return errors.New("unable to parse log level")
}
config := zap.NewProductionConfig()
config.Level.SetLevel(level)
log, _ := config.Build()
Logger = log.Sugar()
K8sClient = k8s.NewClient(*Logger, KubeConfig)
//Initialise k8sClient for all child commands to inherit
Expand Down Expand Up @@ -87,6 +95,7 @@ func init() {
Cmd.PersistentFlags().StringVar(&NodeName, "nodename", "", "node name to label")
Cmd.PersistentFlags().StringVar(&PathPrefix, "pathprefix", "/rootfs", "path prefix for runtime search")
Cmd.PersistentFlags().StringVar(&Runtime, "runtime", "", "runtime detected by k8s")
Cmd.PersistentFlags().StringVar(&LogLevel, "loglevel", "info", "log level, e.g., debug, info, warn, error")
}

// Execute adds all child commands to the root command and sets flags appropriately.
Expand Down

0 comments on commit bed86b5

Please sign in to comment.