Skip to content

cherry pick #1085 #1087 and #1094 to release-1.8 #1111

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

Merged
merged 3 commits into from
Jan 18, 2023
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
11 changes: 8 additions & 3 deletions cmd/gce-pd-csi-driver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,11 @@ var (
runNodeService = flag.Bool("run-node-service", true, "If set to false then the CSI driver does not activate its node service (default: true)")
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.")
metricsPath = flag.String("metrics-path", "/metrics", "The HTTP path where prometheus metrics will be exposed. Default is `/metrics`.")
grpcLogCharCap = flag.Int("grpc-log-char-cap", 10000, "The maximum amount of characters logged for every grpc responses")

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")
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.")
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).")
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")

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

gceDriver.Run(*endpoint)
gceDriver.Run(*endpoint, *grpcLogCharCap)
}
11 changes: 3 additions & 8 deletions pkg/gce-pd-csi-driver/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ import (
gce "sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/gce-cloud-provider/compute"
)

const (
errorBackoffInitialDuration = 200 * time.Millisecond
errorBackoffMaxDuration = 5 * time.Minute
)

type GCEControllerServer struct {
Driver *GCEDriver
CloudProvider gce.GCECompute
Expand Down Expand Up @@ -517,7 +512,7 @@ func (gceCS *GCEControllerServer) executeControllerPublishVolume(ctx context.Con

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

func newCsiErrorBackoff() *csiErrorBackoff {
return &csiErrorBackoff{flowcontrol.NewBackOff(errorBackoffInitialDuration, errorBackoffMaxDuration)}
func newCsiErrorBackoff(initialDuration, errorBackoffMaxDuration time.Duration) *csiErrorBackoff {
return &csiErrorBackoff{flowcontrol.NewBackOff(initialDuration, errorBackoffMaxDuration)}
}

func (_ *csiErrorBackoff) backoffId(nodeId, volumeId string) csiErrorBackoffId {
Expand Down
2 changes: 2 additions & 0 deletions pkg/gce-pd-csi-driver/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2149,6 +2149,8 @@ type backoffTesterConfig struct {
}

func newFakeCsiErrorBackoff(tc *clock.FakeClock) *csiErrorBackoff {
errorBackoffInitialDuration := 200 * time.Millisecond
errorBackoffMaxDuration := 5 * time.Minute
return &csiErrorBackoff{flowcontrol.NewFakeBackOff(errorBackoffInitialDuration, errorBackoffMaxDuration, tc)}
}

Expand Down
11 changes: 8 additions & 3 deletions pkg/gce-pd-csi-driver/gce-pd-driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package gceGCEDriver

import (
"fmt"
"time"

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

var maxLogChar int

type GCEDriver struct {
name string
vendorVersion string
Expand Down Expand Up @@ -148,17 +151,19 @@ func NewNodeServer(gceDriver *GCEDriver, mounter *mount.SafeFormatAndMount, devi
}
}

func NewControllerServer(gceDriver *GCEDriver, cloudProvider gce.GCECompute) *GCEControllerServer {
func NewControllerServer(gceDriver *GCEDriver, cloudProvider gce.GCECompute, errorBackoffInitialDuration, errorBackoffMaxDuration time.Duration) *GCEControllerServer {
return &GCEControllerServer{
Driver: gceDriver,
CloudProvider: cloudProvider,
seen: map[string]int{},
volumeLocks: common.NewVolumeLocks(),
errorBackoff: newCsiErrorBackoff(),
errorBackoff: newCsiErrorBackoff(errorBackoffInitialDuration, errorBackoffMaxDuration),
}
}

func (gceDriver *GCEDriver) Run(endpoint string) {
func (gceDriver *GCEDriver) Run(endpoint string, grpcLogCharCap int) {
maxLogChar = grpcLogCharCap

klog.V(4).Infof("Driver: %v", gceDriver.name)
//Start the nonblocking GRPC
s := NewNonBlockingGRPCServer()
Expand Down
6 changes: 5 additions & 1 deletion pkg/gce-pd-csi-driver/gce-pd-driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package gceGCEDriver

import (
"testing"
"time"

gce "sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/gce-cloud-provider/compute"
)
Expand Down Expand Up @@ -43,7 +44,10 @@ func initBlockingGCEDriver(t *testing.T, cloudDisks []*gce.CloudDisk, readyToExe
func initGCEDriverWithCloudProvider(t *testing.T, cloudProvider gce.GCECompute) *GCEDriver {
vendorVersion := "test-vendor"
gceDriver := GetGCEDriver()
controllerServer := NewControllerServer(gceDriver, cloudProvider)
errorBackoffInitialDuration := 200 * time.Millisecond
errorBackoffMaxDuration := 5 * time.Minute

controllerServer := NewControllerServer(gceDriver, cloudProvider, errorBackoffInitialDuration, errorBackoffMaxDuration)
err := gceDriver.SetupGCEDriver(driver, vendorVersion, nil, nil, controllerServer, nil)
if err != nil {
t.Fatalf("Failed to setup GCE Driver: %v", err)
Expand Down
6 changes: 5 additions & 1 deletion pkg/gce-pd-csi-driver/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ func logGRPC(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, h
if err != nil {
klog.Errorf("%s returned with error: %v", info.FullMethod, err)
} else {
klog.V(4).Infof("%s returned with response: %s", info.FullMethod, resp)
cappedStr := fmt.Sprintf("%v", resp)
if len(cappedStr) > maxLogChar {
cappedStr = cappedStr[:maxLogChar] + fmt.Sprintf(" [response body too large, log capped to %d chars]", maxLogChar)
}
klog.V(4).Infof("%s returned with response: %s", info.FullMethod, cappedStr)
}
return resp, err
}
Expand Down
5 changes: 3 additions & 2 deletions test/sanity/sanity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"path"
"strings"
"testing"
"time"

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

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

go func() {
gceDriver.Run(endpoint)
gceDriver.Run(endpoint, 10000)
}()

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