Skip to content

Commit 1751513

Browse files
authored
Merge pull request kubernetes-sigs#1111 from leiyiz/release-1.8
cherry pick kubernetes-sigs#1085 kubernetes-sigs#1087 and kubernetes-sigs#1094 to release-1.8
2 parents 59ffcdc + 6c67b76 commit 1751513

File tree

7 files changed

+34
-18
lines changed

7 files changed

+34
-18
lines changed

cmd/gce-pd-csi-driver/main.go

+8-3
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,11 @@ var (
4040
runNodeService = flag.Bool("run-node-service", true, "If set to false then the CSI driver does not activate its node service (default: true)")
4141
httpEndpoint = flag.String("http-endpoint", "", "The TCP network address where the prometheus metrics endpoint will listen (example: `:8080`). The default is empty string, which means metrics endpoint is disabled.")
4242
metricsPath = flag.String("metrics-path", "/metrics", "The HTTP path where prometheus metrics will be exposed. Default is `/metrics`.")
43+
grpcLogCharCap = flag.Int("grpc-log-char-cap", 10000, "The maximum amount of characters logged for every grpc responses")
4344

44-
extraVolumeLabelsStr = flag.String("extra-labels", "", "Extra labels to attach to each PD created. It is a comma separated list of key value pairs like '<key1>=<value1>,<key2>=<value2>'. See https://cloud.google.com/compute/docs/labeling-resources for details")
45+
errorBackoffInitialDurationMs = flag.Int("backoff-initial-duration-ms", 200, "The amount of ms for the initial duration of the backoff condition for controller publish/unpublish CSI operations. Default is 200.")
46+
errorBackoffMaxDurationMs = flag.Int("backoff-max-duration-ms", 300000, "The amount of ms for the max duration of the backoff condition for controller publish/unpublish CSI operations. Default is 300000 (5m).")
47+
extraVolumeLabelsStr = flag.String("extra-labels", "", "Extra labels to attach to each PD created. It is a comma separated list of key value pairs like '<key1>=<value1>,<key2>=<value2>'. See https://cloud.google.com/compute/docs/labeling-resources for details")
4548

4649
attachDiskBackoffDuration = flag.Duration("attach-disk-backoff-duration", 5*time.Second, "Duration for attachDisk backoff")
4750
attachDiskBackoffFactor = flag.Float64("attach-disk-backoff-factor", 0.0, "Factor for attachDisk backoff")
@@ -121,7 +124,9 @@ func handle() {
121124
if err != nil {
122125
klog.Fatalf("Failed to get cloud provider: %v", err)
123126
}
124-
controllerServer = driver.NewControllerServer(gceDriver, cloudProvider)
127+
initialBackoffDuration := time.Duration(*errorBackoffInitialDurationMs) * time.Millisecond
128+
maxBackoffDuration := time.Duration(*errorBackoffMaxDurationMs) * time.Microsecond
129+
controllerServer = driver.NewControllerServer(gceDriver, cloudProvider, initialBackoffDuration, maxBackoffDuration)
125130
} else if *cloudConfigFilePath != "" {
126131
klog.Warningf("controller service is disabled but cloud config given - it has no effect")
127132
}
@@ -159,5 +164,5 @@ func handle() {
159164
gce.WaitForOpBackoff.Steps = *waitForOpBackoffSteps
160165
gce.WaitForOpBackoff.Cap = *waitForOpBackoffCap
161166

162-
gceDriver.Run(*endpoint)
167+
gceDriver.Run(*endpoint, *grpcLogCharCap)
163168
}

pkg/gce-pd-csi-driver/controller.go

+3-8
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,6 @@ import (
3737
gce "sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/gce-cloud-provider/compute"
3838
)
3939

40-
const (
41-
errorBackoffInitialDuration = 200 * time.Millisecond
42-
errorBackoffMaxDuration = 5 * time.Minute
43-
)
44-
4540
type GCEControllerServer struct {
4641
Driver *GCEDriver
4742
CloudProvider gce.GCECompute
@@ -517,7 +512,7 @@ func (gceCS *GCEControllerServer) executeControllerPublishVolume(ctx context.Con
517512

518513
attached, err := diskIsAttachedAndCompatible(deviceName, instance, volumeCapability, readWrite)
519514
if err != nil {
520-
return nil, status.Error(codes.AlreadyExists, fmt.Sprintf("Disk %v already published to node %v but incompatbile: %v", volKey.Name, nodeID, err))
515+
return nil, status.Error(codes.AlreadyExists, fmt.Sprintf("Disk %v already published to node %v but incompatible: %v", volKey.Name, nodeID, err))
521516
}
522517
if attached {
523518
// Volume is attached to node. Success!
@@ -1597,8 +1592,8 @@ func pickRandAndConsecutive(slice []string, n int) ([]string, error) {
15971592
return ret, nil
15981593
}
15991594

1600-
func newCsiErrorBackoff() *csiErrorBackoff {
1601-
return &csiErrorBackoff{flowcontrol.NewBackOff(errorBackoffInitialDuration, errorBackoffMaxDuration)}
1595+
func newCsiErrorBackoff(initialDuration, errorBackoffMaxDuration time.Duration) *csiErrorBackoff {
1596+
return &csiErrorBackoff{flowcontrol.NewBackOff(initialDuration, errorBackoffMaxDuration)}
16021597
}
16031598

16041599
func (_ *csiErrorBackoff) backoffId(nodeId, volumeId string) csiErrorBackoffId {

pkg/gce-pd-csi-driver/controller_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -2149,6 +2149,8 @@ type backoffTesterConfig struct {
21492149
}
21502150

21512151
func newFakeCsiErrorBackoff(tc *clock.FakeClock) *csiErrorBackoff {
2152+
errorBackoffInitialDuration := 200 * time.Millisecond
2153+
errorBackoffMaxDuration := 5 * time.Minute
21522154
return &csiErrorBackoff{flowcontrol.NewFakeBackOff(errorBackoffInitialDuration, errorBackoffMaxDuration, tc)}
21532155
}
21542156

pkg/gce-pd-csi-driver/gce-pd-driver.go

+8-3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package gceGCEDriver
1616

1717
import (
1818
"fmt"
19+
"time"
1920

2021
csi "github.com/container-storage-interface/spec/lib/go/csi"
2122
"google.golang.org/grpc/codes"
@@ -28,6 +29,8 @@ import (
2829
mountmanager "sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/mount-manager"
2930
)
3031

32+
var maxLogChar int
33+
3134
type GCEDriver struct {
3235
name string
3336
vendorVersion string
@@ -148,17 +151,19 @@ func NewNodeServer(gceDriver *GCEDriver, mounter *mount.SafeFormatAndMount, devi
148151
}
149152
}
150153

151-
func NewControllerServer(gceDriver *GCEDriver, cloudProvider gce.GCECompute) *GCEControllerServer {
154+
func NewControllerServer(gceDriver *GCEDriver, cloudProvider gce.GCECompute, errorBackoffInitialDuration, errorBackoffMaxDuration time.Duration) *GCEControllerServer {
152155
return &GCEControllerServer{
153156
Driver: gceDriver,
154157
CloudProvider: cloudProvider,
155158
seen: map[string]int{},
156159
volumeLocks: common.NewVolumeLocks(),
157-
errorBackoff: newCsiErrorBackoff(),
160+
errorBackoff: newCsiErrorBackoff(errorBackoffInitialDuration, errorBackoffMaxDuration),
158161
}
159162
}
160163

161-
func (gceDriver *GCEDriver) Run(endpoint string) {
164+
func (gceDriver *GCEDriver) Run(endpoint string, grpcLogCharCap int) {
165+
maxLogChar = grpcLogCharCap
166+
162167
klog.V(4).Infof("Driver: %v", gceDriver.name)
163168
//Start the nonblocking GRPC
164169
s := NewNonBlockingGRPCServer()

pkg/gce-pd-csi-driver/gce-pd-driver_test.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package gceGCEDriver
1616

1717
import (
1818
"testing"
19+
"time"
1920

2021
gce "sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/gce-cloud-provider/compute"
2122
)
@@ -43,7 +44,10 @@ func initBlockingGCEDriver(t *testing.T, cloudDisks []*gce.CloudDisk, readyToExe
4344
func initGCEDriverWithCloudProvider(t *testing.T, cloudProvider gce.GCECompute) *GCEDriver {
4445
vendorVersion := "test-vendor"
4546
gceDriver := GetGCEDriver()
46-
controllerServer := NewControllerServer(gceDriver, cloudProvider)
47+
errorBackoffInitialDuration := 200 * time.Millisecond
48+
errorBackoffMaxDuration := 5 * time.Minute
49+
50+
controllerServer := NewControllerServer(gceDriver, cloudProvider, errorBackoffInitialDuration, errorBackoffMaxDuration)
4751
err := gceDriver.SetupGCEDriver(driver, vendorVersion, nil, nil, controllerServer, nil)
4852
if err != nil {
4953
t.Fatalf("Failed to setup GCE Driver: %v", err)

pkg/gce-pd-csi-driver/utils.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,11 @@ func logGRPC(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, h
6969
if err != nil {
7070
klog.Errorf("%s returned with error: %v", info.FullMethod, err)
7171
} else {
72-
klog.V(4).Infof("%s returned with response: %s", info.FullMethod, resp)
72+
cappedStr := fmt.Sprintf("%v", resp)
73+
if len(cappedStr) > maxLogChar {
74+
cappedStr = cappedStr[:maxLogChar] + fmt.Sprintf(" [response body too large, log capped to %d chars]", maxLogChar)
75+
}
76+
klog.V(4).Infof("%s returned with response: %s", info.FullMethod, cappedStr)
7377
}
7478
return resp, err
7579
}

test/sanity/sanity_test.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"path"
2222
"strings"
2323
"testing"
24+
"time"
2425

2526
"github.com/google/uuid"
2627
"google.golang.org/grpc"
@@ -64,7 +65,7 @@ func TestSanity(t *testing.T) {
6465

6566
//Initialize GCE Driver
6667
identityServer := driver.NewIdentityServer(gceDriver)
67-
controllerServer := driver.NewControllerServer(gceDriver, cloudProvider)
68+
controllerServer := driver.NewControllerServer(gceDriver, cloudProvider, 0, 5*time.Minute)
6869
nodeServer := driver.NewNodeServer(gceDriver, mounter, deviceUtils, metadataservice.NewFakeService(), mountmanager.NewFakeStatter(mounter))
6970
err = gceDriver.SetupGCEDriver(driverName, vendorVersion, extraLabels, identityServer, controllerServer, nodeServer)
7071
if err != nil {
@@ -90,7 +91,7 @@ func TestSanity(t *testing.T) {
9091
}()
9192

9293
go func() {
93-
gceDriver.Run(endpoint)
94+
gceDriver.Run(endpoint, 10000)
9495
}()
9596

9697
// TODO(#818): Fix failing tests and remove test skip flag.

0 commit comments

Comments
 (0)