diff --git a/controllers/module_reconciler.go b/controllers/module_reconciler.go index bc23ad32b..8229b466e 100644 --- a/controllers/module_reconciler.go +++ b/controllers/module_reconciler.go @@ -200,7 +200,7 @@ func (r *ModuleReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr func (r *ModuleReconciler) SetupWithManager(mgr ctrl.Manager, kernelLabel string) error { nmm := NewNodeModuleMapper( r.Client, - mgr.GetLogger().WithName("NodeModuleMapper"), + mgr.GetLogger().WithName("controller/module/node-module-mapper"), ) return ctrl.NewControllerManagedBy(mgr). @@ -214,6 +214,7 @@ func (r *ModuleReconciler) SetupWithManager(mgr ctrl.Manager, kernelLabel string ModuleReconcilerNodePredicate(kernelLabel), ), ). + Named("module"). Complete(r) } diff --git a/controllers/node_kernel_reconciler.go b/controllers/node_kernel_reconciler.go index 10672faf6..e97cb582a 100644 --- a/controllers/node_kernel_reconciler.go +++ b/controllers/node_kernel_reconciler.go @@ -62,7 +62,7 @@ func (r *NodeKernelReconciler) Reconcile(ctx context.Context, req ctrl.Request) func (r *NodeKernelReconciler) SetupWithManager(mgr ctrl.Manager) error { return ctrl. NewControllerManagedBy(mgr). - Named("NodeKernelReconciler"). + Named("node-kernel"). For(&v1.Node{}). WithEventFilter( NodeKernelReconcilerPredicate(r.labelName), diff --git a/go.mod b/go.mod index 3f8df9379..3e69b513b 100644 --- a/go.mod +++ b/go.mod @@ -13,6 +13,7 @@ require ( k8s.io/api v0.23.5 k8s.io/apimachinery v0.23.5 k8s.io/client-go v0.23.5 + k8s.io/klog/v2 v2.60.1 sigs.k8s.io/controller-runtime v0.11.2 ) @@ -34,7 +35,6 @@ require ( github.com/evanphx/json-patch v4.12.0+incompatible // indirect github.com/form3tech-oss/jwt-go v3.2.3+incompatible // indirect github.com/fsnotify/fsnotify v1.5.1 // indirect - github.com/go-logr/zapr v1.2.0 // indirect github.com/gogo/protobuf v1.3.2 // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect github.com/golang/protobuf v1.5.2 // indirect @@ -56,9 +56,6 @@ require ( github.com/prometheus/procfs v0.6.0 // indirect github.com/sirupsen/logrus v1.8.1 // indirect github.com/spf13/pflag v1.0.5 // indirect - go.uber.org/atomic v1.7.0 // indirect - go.uber.org/multierr v1.6.0 // indirect - go.uber.org/zap v1.19.1 // indirect golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 // indirect golang.org/x/net v0.0.0-20220225172249-27dd8689420f // indirect golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 // indirect @@ -75,7 +72,6 @@ require ( gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect k8s.io/apiextensions-apiserver v0.23.5 // indirect k8s.io/component-base v0.23.5 // indirect - k8s.io/klog/v2 v2.30.0 // indirect k8s.io/kube-openapi v0.0.0-20211115234752-e816edb12b65 // indirect k8s.io/utils v0.0.0-20211116205334-6203023598ed // indirect sigs.k8s.io/json v0.0.0-20211020170558-c049b76a60c6 // indirect diff --git a/go.sum b/go.sum index e3c4813b4..0ec35a4c4 100644 --- a/go.sum +++ b/go.sum @@ -118,7 +118,6 @@ github.com/armon/go-radix v1.0.0/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgI github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY= github.com/aws/aws-sdk-go v1.15.11/go.mod h1:mFuSZ37Z9YOHbQEwBWztmVzqXrEkub65tZoCYDt7FT0= github.com/benbjohnson/clock v1.0.3/go.mod h1:bGMdMPoPVvcYyt1gHDf4J2KE153Yf9BuiUKYMaxlTDM= -github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8= github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= github.com/beorn7/perks v0.0.0-20160804104726-4c0e84591b9a/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= @@ -920,7 +919,6 @@ go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw= go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/goleak v1.1.10/go.mod h1:8a7PlsEVH3e/a/GLqe5IIrQx6GzcnRmZEufDUTk4A7A= -go.uber.org/goleak v1.1.11-0.20210813005559-691160354723/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ= go.uber.org/goleak v1.1.12 h1:gZAh5/EyT/HQwlpkCy6wTpqfH9H8Lz8zbm3dZh+OyzA= go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= go.uber.org/multierr v1.6.0 h1:y6IPFStTAIT5Ytl7/XYmHvzXQ7S3g/IeZW9hyZ5thw4= @@ -929,7 +927,6 @@ go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= go.uber.org/zap v1.17.0/go.mod h1:MXVU+bhUf/A7Xi2HNOnopQOrmycQ5Ih87HtOu4q5SSo= go.uber.org/zap v1.19.0/go.mod h1:xg/QME4nWcxGxrpdeYfq7UvYrLh66cuVKdrbD1XF/NI= go.uber.org/zap v1.19.1 h1:ue41HOKd1vGURxrmeKIgELGb3jPW9DMUDGtsinblHwI= -go.uber.org/zap v1.19.1/go.mod h1:j3DNczoxDZroyBnOT1L/Q79cfUMGZxlv/9dzN7SM1rI= golang.org/x/crypto v0.0.0-20171113213409-9f005a07e0d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20181009213950-7c1a557ab941/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= @@ -1530,8 +1527,9 @@ k8s.io/gengo v0.0.0-20210813121822-485abfe95c7c/go.mod h1:FiNAH4ZV3gBg2Kwh89tzAE k8s.io/klog/v2 v2.0.0/go.mod h1:PBfzABfn139FHAV07az/IF9Wp1bkk3vpT2XSJ76fSDE= k8s.io/klog/v2 v2.2.0/go.mod h1:Od+F08eJP+W3HUb4pSrPpgp9DGU4GzlpG/TmITuYh/Y= k8s.io/klog/v2 v2.4.0/go.mod h1:Od+F08eJP+W3HUb4pSrPpgp9DGU4GzlpG/TmITuYh/Y= -k8s.io/klog/v2 v2.30.0 h1:bUO6drIvCIsvZ/XFgfxoGFQU/a4Qkh0iAlvUR7vlHJw= k8s.io/klog/v2 v2.30.0/go.mod h1:y1WjHnz7Dj687irZUWR/WLkLc5N1YHtjLdmgWjndZn0= +k8s.io/klog/v2 v2.60.1 h1:VW25q3bZx9uE3vvdL6M8ezOX79vA2Aq1nEWLqNQclHc= +k8s.io/klog/v2 v2.60.1/go.mod h1:y1WjHnz7Dj687irZUWR/WLkLc5N1YHtjLdmgWjndZn0= k8s.io/kube-openapi v0.0.0-20201113171705-d219536bb9fd/go.mod h1:WOJ3KddDSol4tAGcJo0Tvi+dK12EcqSLqcWsryKMpfM= k8s.io/kube-openapi v0.0.0-20211115234752-e816edb12b65 h1:E3J9oCLlaobFUqsjG9DfKbP2BmgwBL2p7pn0A3dG9W4= k8s.io/kube-openapi v0.0.0-20211115234752-e816edb12b65/go.mod h1:sX9MT8g7NVZM5lVL/j8QyCCJe8YSMW30QvGZWaCIDIk= diff --git a/main.go b/main.go index e9ff4d257..700ea0355 100644 --- a/main.go +++ b/main.go @@ -27,20 +27,19 @@ import ( "github.com/qbarrand/oot-operator/controllers/build/job" "github.com/qbarrand/oot-operator/controllers/module" "k8s.io/apimachinery/pkg/util/sets" - + "k8s.io/klog/v2/klogr" // Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.) // to ensure that exec-entrypoint and run can make use of them. _ "k8s.io/client-go/plugin/pkg/client/auth" + ootov1alpha1 "github.com/qbarrand/oot-operator/api/v1alpha1" + "github.com/qbarrand/oot-operator/controllers" "k8s.io/apimachinery/pkg/runtime" utilruntime "k8s.io/apimachinery/pkg/util/runtime" clientgoscheme "k8s.io/client-go/kubernetes/scheme" + "k8s.io/klog/v2" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/healthz" - "sigs.k8s.io/controller-runtime/pkg/log/zap" - - ootov1alpha1 "github.com/qbarrand/oot-operator/api/v1alpha1" - "github.com/qbarrand/oot-operator/controllers" //+kubebuilder:scaffold:imports ) @@ -53,7 +52,6 @@ const ( var ( scheme = runtime.NewScheme() - setupLog = ctrl.Log.WithName("setup") validLabelingMethods = sets.NewString(OOTOKernelLabelingMethod, NFDKernelLabelingMethod) ) @@ -80,22 +78,23 @@ func main() { flag.StringVar(&configFile, "config", "", "The path to the configuration file.") - opts := zap.Options{ - //Development: true, - } + klog.InitFlags(flag.CommandLine) - opts.BindFlags(flag.CommandLine) flag.Parse() - ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts))) + logger := klogr.New() + + ctrl.SetLogger(logger) + + setupLogger := logger.WithName("setup") commit, err := gitCommit() if err != nil { - setupLog.Error(err, "Could not get the git commit; using ") + setupLogger.Error(err, "Could not get the git commit; using ") commit = "" } - setupLog.Info("Creating manager", "git commit", commit) + setupLogger.Info("Creating manager", "git commit", commit) namespace := GetEnvWithDefault("OPERATOR_NAMESPACE", "default") @@ -109,7 +108,7 @@ func main() { LeaderElectionID: "c5baf8af.sigs.k8s.io", }) if err != nil { - setupLog.Error(err, "unable to start manager") + setupLogger.Error(err, "unable to start manager") os.Exit(1) } @@ -120,7 +119,7 @@ func main() { kernelLabelingMethod = GetEnvWithDefault(KernelLabelingMethodEnvVar, OOTOKernelLabelingMethod) ) - setupLog.V(1).Info("Determining kernel labeling method", KernelLabelingMethodEnvVar, kernelLabelingMethod) + setupLogger.V(1).Info("Determining kernel labeling method", KernelLabelingMethodEnvVar, kernelLabelingMethod) switch kernelLabelingMethod { case OOTOKernelLabelingMethod: @@ -129,13 +128,13 @@ func main() { nkr := controllers.NewNodeKernelReconciler(client, kernelLabel) if err = nkr.SetupWithManager(mgr); err != nil { - setupLog.Error(err, "unable to create controller", "controller", "NodeKernel") + setupLogger.Error(err, "unable to create controller", "controller", "NodeKernel") os.Exit(1) } case NFDKernelLabelingMethod: kernelLabel = "feature.node.kubernetes.io/kernel-version.full" default: - setupLog.Error( + setupLogger.Error( fmt.Errorf("%q is not in %v", kernelLabelingMethod, validLabelingMethods.List()), "Invalid kernel labeling method", ) @@ -143,7 +142,7 @@ func main() { os.Exit(1) } - setupLog.V(1).Info("Using kernel label", "label", kernelLabel) + setupLogger.V(1).Info("Using kernel label", "label", kernelLabel) bm := job.NewBuildManager(client, build.NewGetter(), job.NewMaker(build.NewModuleHelper(), namespace, scheme), namespace) dc := controllers.NewDaemonSetCreator(client, kernelLabel, namespace, scheme) @@ -153,24 +152,24 @@ func main() { mc := controllers.NewModuleReconciler(client, namespace, bm, dc, km, su) if err = mc.SetupWithManager(mgr, kernelLabel); err != nil { - setupLog.Error(err, "unable to create controller", "controller", "Module") + setupLogger.Error(err, "unable to create controller", "controller", "Module") os.Exit(1) } //+kubebuilder:scaffold:builder if err = mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil { - setupLog.Error(err, "unable to set up health check") + setupLogger.Error(err, "unable to set up health check") os.Exit(1) } if err = mgr.AddReadyzCheck("readyz", healthz.Ping); err != nil { - setupLog.Error(err, "unable to set up ready check") + setupLogger.Error(err, "unable to set up ready check") os.Exit(1) } - setupLog.Info("starting manager") + setupLogger.Info("starting manager") if err = mgr.Start(ctrl.SetupSignalHandler()); err != nil { - setupLog.Error(err, "problem running manager") + setupLogger.Error(err, "problem running manager") os.Exit(1) } }