From e7cdcedcc4ae1465bad7f1e95164509f2a798ef4 Mon Sep 17 00:00:00 2001 From: andyzhangx Date: Wed, 20 Jan 2021 06:53:19 +0000 Subject: [PATCH 1/2] fix: reduce driver logs --- .github/workflows/darwin.yaml | 2 +- .github/workflows/linux.yaml | 2 +- hack/verify-examples.sh | 3 +++ pkg/nfs/indentityserver.go | 5 ----- pkg/nfs/utils.go | 17 ++++++++++++++--- pkg/nfs/utils_test.go | 35 +++++++++++++++++++++++++++++++++++ 6 files changed, 54 insertions(+), 10 deletions(-) diff --git a/.github/workflows/darwin.yaml b/.github/workflows/darwin.yaml index 9be5a98e..84fc5423 100644 --- a/.github/workflows/darwin.yaml +++ b/.github/workflows/darwin.yaml @@ -10,7 +10,7 @@ jobs: - name: Set up Go 1.x uses: actions/setup-go@v2 with: - go-version: ^1.13 + go-version: ^1.15 id: go - name: Check out code into the Go module directory uses: actions/checkout@v2 diff --git a/.github/workflows/linux.yaml b/.github/workflows/linux.yaml index f90f73ab..43567a68 100644 --- a/.github/workflows/linux.yaml +++ b/.github/workflows/linux.yaml @@ -13,7 +13,7 @@ jobs: - name: Set up Go 1.x uses: actions/setup-go@v2 with: - go-version: ^1.13 + go-version: ^1.15 id: go - name: Check out code into the Go module directory diff --git a/hack/verify-examples.sh b/hack/verify-examples.sh index 1c248d43..bd071110 100755 --- a/hack/verify-examples.sh +++ b/hack/verify-examples.sh @@ -24,6 +24,9 @@ kubectl apply -f ./deploy/example/statefulset.yaml echo "sleep 60s ..." sleep 60 +echo "begin to check pod status ..." +kubectl get pods -o wide + kubectl get pods --field-selector status.phase=Running | grep deployment-nfs kubectl get pods --field-selector status.phase=Running | grep statefulset-nfs-0 diff --git a/pkg/nfs/indentityserver.go b/pkg/nfs/indentityserver.go index f7f1db3c..52d6943a 100644 --- a/pkg/nfs/indentityserver.go +++ b/pkg/nfs/indentityserver.go @@ -22,8 +22,6 @@ import ( "golang.org/x/net/context" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" - - "k8s.io/klog/v2" ) type IdentityServer struct { @@ -31,8 +29,6 @@ type IdentityServer struct { } func (ids *IdentityServer) GetPluginInfo(ctx context.Context, req *csi.GetPluginInfoRequest) (*csi.GetPluginInfoResponse, error) { - klog.V(5).Infof("Using default GetPluginInfo") - if ids.Driver.name == "" { return nil, status.Error(codes.Unavailable, "Driver name not configured") } @@ -56,7 +52,6 @@ func (ids *IdentityServer) Probe(ctx context.Context, req *csi.ProbeRequest) (*c } func (ids *IdentityServer) GetPluginCapabilities(ctx context.Context, req *csi.GetPluginCapabilitiesRequest) (*csi.GetPluginCapabilitiesResponse, error) { - klog.V(5).Infof("Using default capabilities") return &csi.GetPluginCapabilitiesResponse{ Capabilities: []*csi.PluginCapability{ { diff --git a/pkg/nfs/utils.go b/pkg/nfs/utils.go index d89204ab..97eb83b3 100644 --- a/pkg/nfs/utils.go +++ b/pkg/nfs/utils.go @@ -70,14 +70,25 @@ func ParseEndpoint(ep string) (string, string, error) { return "", "", fmt.Errorf("Invalid endpoint: %v", ep) } +func getLogLevel(method string) int32 { + if method == "/csi.v1.Identity/Probe" || + method == "/csi.v1.Node/NodeGetCapabilities" || + method == "/csi.v1.Node/NodeGetVolumeStats" { + return 10 + } + return 2 +} + func logGRPC(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) { - klog.V(3).Infof("GRPC call: %s", info.FullMethod) - klog.V(5).Infof("GRPC request: %s", protosanitizer.StripSecrets(req)) + level := klog.Level(getLogLevel(info.FullMethod)) + klog.V(level).Infof("GRPC call: %s", info.FullMethod) + klog.V(level).Infof("GRPC request: %s", protosanitizer.StripSecrets(req)) + resp, err := handler(ctx, req) if err != nil { klog.Errorf("GRPC error: %v", err) } else { - klog.V(5).Infof("GRPC response: %s", protosanitizer.StripSecrets(resp)) + klog.V(level).Infof("GRPC response: %s", protosanitizer.StripSecrets(resp)) } return resp, err } diff --git a/pkg/nfs/utils_test.go b/pkg/nfs/utils_test.go index 536f8065..1177373d 100644 --- a/pkg/nfs/utils_test.go +++ b/pkg/nfs/utils_test.go @@ -83,3 +83,38 @@ func TestParseEndpoint(t *testing.T) { }) } } + +func TestGetLogLevel(t *testing.T) { + tests := []struct { + method string + level int32 + }{ + { + method: "/csi.v1.Identity/Probe", + level: 10, + }, + { + method: "/csi.v1.Node/NodeGetCapabilities", + level: 10, + }, + { + method: "/csi.v1.Node/NodeGetVolumeStats", + level: 10, + }, + { + method: "", + level: 2, + }, + { + method: "unknown", + level: 2, + }, + } + + for _, test := range tests { + level := getLogLevel(test.method) + if level != test.level { + t.Errorf("returned level: (%v), expected level: (%v)", level, test.level) + } + } +} From 45fa96612c42669af6c6fc3135d3b82a938c3411 Mon Sep 17 00:00:00 2001 From: andyzhangx Date: Wed, 20 Jan 2021 06:57:52 +0000 Subject: [PATCH 2/2] chore: reduce csi sidecar container logs --- .../latest/csi-driver-nfs/templates/csi-nfs-controller.yaml | 4 ++-- charts/latest/csi-driver-nfs/templates/csi-nfs-node.yaml | 4 ++-- deploy/csi-nfs-controller.yaml | 4 ++-- deploy/csi-nfs-node.yaml | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/charts/latest/csi-driver-nfs/templates/csi-nfs-controller.yaml b/charts/latest/csi-driver-nfs/templates/csi-nfs-controller.yaml index e3dcfa95..4bb90875 100644 --- a/charts/latest/csi-driver-nfs/templates/csi-nfs-controller.yaml +++ b/charts/latest/csi-driver-nfs/templates/csi-nfs-controller.yaml @@ -28,7 +28,7 @@ spec: - name: csi-provisioner image: "{{ .Values.image.csiProvisioner.repository }}:{{ .Values.image.csiProvisioner.tag }}" args: - - "-v=5" + - "-v=2" - "--csi-address=$(ADDRESS)" - "--leader-election" env: @@ -51,7 +51,7 @@ spec: - --csi-address=/csi/csi.sock - --probe-timeout=3s - --health-port=29652 - - --v=5 + - --v=2 imagePullPolicy: {{ .Values.image.livenessProbe.pullPolicy }} volumeMounts: - name: socket-dir diff --git a/charts/latest/csi-driver-nfs/templates/csi-nfs-node.yaml b/charts/latest/csi-driver-nfs/templates/csi-nfs-node.yaml index bc23f7d7..6c621af1 100644 --- a/charts/latest/csi-driver-nfs/templates/csi-nfs-node.yaml +++ b/charts/latest/csi-driver-nfs/templates/csi-nfs-node.yaml @@ -26,7 +26,7 @@ spec: - --csi-address=/csi/csi.sock - --probe-timeout=3s - --health-port=29653 - - --v=5 + - --v=2 imagePullPolicy: {{ .Values.image.livenessProbe.pullPolicy }} volumeMounts: - name: socket-dir @@ -45,7 +45,7 @@ spec: exec: command: ["/bin/sh", "-c", "rm -rf /registration/csi-nfsplugin /registration/csi-nfsplugin-reg.sock"] args: - - --v=5 + - --v=2 - --csi-address=/csi/csi.sock - --kubelet-registration-path=/var/lib/kubelet/plugins/csi-nfsplugin/csi.sock env: diff --git a/deploy/csi-nfs-controller.yaml b/deploy/csi-nfs-controller.yaml index d7f44bec..67b3184c 100644 --- a/deploy/csi-nfs-controller.yaml +++ b/deploy/csi-nfs-controller.yaml @@ -27,7 +27,7 @@ spec: - name: csi-provisioner image: k8s.gcr.io/sig-storage/csi-provisioner:v2.0.4 args: - - "-v=5" + - "-v=2" - "--csi-address=$(ADDRESS)" - "--leader-election" env: @@ -49,7 +49,7 @@ spec: - --csi-address=/csi/csi.sock - --probe-timeout=3s - --health-port=29652 - - --v=5 + - --v=2 volumeMounts: - name: socket-dir mountPath: /csi diff --git a/deploy/csi-nfs-node.yaml b/deploy/csi-nfs-node.yaml index dd66fa8d..5f4184c7 100644 --- a/deploy/csi-nfs-node.yaml +++ b/deploy/csi-nfs-node.yaml @@ -26,7 +26,7 @@ spec: - --csi-address=/csi/csi.sock - --probe-timeout=3s - --health-port=29653 - - --v=5 + - --v=2 volumeMounts: - name: socket-dir mountPath: /csi @@ -44,7 +44,7 @@ spec: exec: command: ["/bin/sh", "-c", "rm -rf /registration/csi-nfsplugin /registration/csi-nfsplugin-reg.sock"] args: - - --v=5 + - --v=2 - --csi-address=/csi/csi.sock - --kubelet-registration-path=/var/lib/kubelet/plugins/csi-nfsplugin/csi.sock env: