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 logger for controller-runtime framework #2490

Merged
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
7 changes: 6 additions & 1 deletion cmd/spiderpool-agent/cmd/crd_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ package cmd
import (
"strconv"

"github.com/go-logr/logr"
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
kubevirtv1 "kubevirt.io/api/core/v1"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
controllerruntimelog "sigs.k8s.io/controller-runtime/pkg/log"
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"

spiderpoolv2beta1 "github.com/spidernet-io/spiderpool/pkg/k8s/apis/spiderpool.spidernet.io/v2beta1"
Expand All @@ -26,10 +28,13 @@ func init() {
}

func newCRDManager() (ctrl.Manager, error) {
// set logger for controller-runtime framework
// The controller-runtime would print debug stack if we do not init the log previously: https://github.com/kubernetes-sigs/controller-runtime/pull/2357
ctrl.SetLogger(logr.New(controllerruntimelog.NullLogSink{}))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment 可以记下 issue 链接

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


config := ctrl.GetConfigOrDie()
config.Burst = 100
config.QPS = 50

mgr, err := ctrl.NewManager(config, ctrl.Options{
Scheme: scheme,
Metrics: metricsserver.Options{
Expand Down
7 changes: 6 additions & 1 deletion cmd/spiderpool-controller/cmd/crd_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"path"
"strconv"

"github.com/go-logr/logr"
multusv1 "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1"
calicov1 "github.com/tigera/operator/pkg/apis/crd.projectcalico.org/v1"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
Expand All @@ -19,6 +20,7 @@ import (
kubevirtv1 "kubevirt.io/api/core/v1"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
controllerruntimelog "sigs.k8s.io/controller-runtime/pkg/log"
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
runtimeWebhook "sigs.k8s.io/controller-runtime/pkg/webhook"

Expand All @@ -37,6 +39,10 @@ func init() {
}

func newCRDManager() (ctrl.Manager, error) {
// set logger for controller-runtime framework
// The controller-runtime would print debug stack if we do not init the log previously: https://github.com/kubernetes-sigs/controller-runtime/pull/2357
ctrl.SetLogger(logr.New(controllerruntimelog.NullLogSink{}))

port, err := strconv.Atoi(controllerContext.Cfg.WebhookPort)
if err != nil {
return nil, err
Expand All @@ -45,7 +51,6 @@ func newCRDManager() (ctrl.Manager, error) {
config := ctrl.GetConfigOrDie()
config.Burst = 200
config.QPS = 100

mgr, err := ctrl.NewManager(config, ctrl.Options{
Scheme: scheme,
Metrics: metricsserver.Options{
Expand Down
7 changes: 5 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ require (
sigs.k8s.io/yaml v1.3.0
)

require (
github.com/go-logr/logr v1.2.4
k8s.io/klog/v2 v2.100.1 // indirect
)

require (
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/semver/v3 v3.1.1 // indirect
Expand All @@ -84,7 +89,6 @@ require (
github.com/fatih/color v1.13.0 // indirect
github.com/felixge/httpsnoop v1.0.3 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/go-openapi/analysis v0.21.4 // indirect
Expand Down Expand Up @@ -173,7 +177,6 @@ require (
gopkg.in/ini.v1 v1.67.0 // indirect
k8s.io/component-base v0.28.1 // indirect
k8s.io/gengo v0.0.0-20230306165830-ab3349d207d4 // indirect
k8s.io/klog/v2 v2.100.1 // indirect
k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9 // indirect
k8s.io/kubectl v0.26.3 // indirect
kubevirt.io/containerized-data-importer-api v1.57.0-alpha1 // indirect
Expand Down
Loading