Skip to content

Commit eeed144

Browse files
committed
sanity: optional gRPC keepalive
The gRPC defaults for a client do not work for a gRPC server that also uses the defaults (grpc/grpc-go#3171) which caused connection drops when a CSI driver is slow to respond and the client starts sending keepalive pings too quickly (#238). The sanity package no longer uses gRPC keepalive. Instead, custom test suites can enable that via some new configuration options if needed and when it is certain that the CSI driver under test can handle it.
1 parent fdb220c commit eeed144

35 files changed

+53
-9543
lines changed

driver/mock.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func (m *MockCSIDriver) Nexus() (*grpc.ClientConn, error) {
7575
}
7676

7777
// Create a client connection
78-
m.conn, err = utils.Connect(m.Address())
78+
m.conn, err = utils.Connect(m.Address(), grpc.WithInsecure())
7979
if err != nil {
8080
return nil, err
8181
}

pkg/sanity/sanity.go

+14-2
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,19 @@ type TestConfig struct {
7171
// is empty, it must provide both the controller and node service.
7272
Address string
7373

74+
// DialOptions specifies the options that are to be used
75+
// when connecting to Address. The default is grpc.WithInsecure().
76+
// A dialer will be added for Unix Domain Sockets.
77+
DialOptions []grpc.DialOption
78+
7479
// ControllerAddress optionally provides the gRPC endpoint of
7580
// the controller service.
7681
ControllerAddress string
7782

83+
// ControllerDialOptions specifies the options that are to be used
84+
// for ControllerAddress.
85+
ControllerDialOptions []grpc.DialOption
86+
7887
// SecretsFile is the filename of a .yaml file which is used
7988
// to populate CSISecrets which are then used for calls to the
8089
// CSI driver.
@@ -175,6 +184,9 @@ func NewTestConfig() TestConfig {
175184
RemovePathCmdTimeout: 10 * time.Second,
176185
TestVolumeSize: 10 * 1024 * 1024 * 1024, // 10 GiB
177186
IDGen: &DefaultIDGenerator{},
187+
188+
DialOptions: []grpc.DialOption{grpc.WithInsecure()},
189+
ControllerDialOptions: []grpc.DialOption{grpc.WithInsecure()},
178190
}
179191
}
180192

@@ -240,7 +252,7 @@ func (sc *TestContext) Setup() {
240252
sc.Conn.Close()
241253
}
242254
By("connecting to CSI driver")
243-
sc.Conn, err = utils.Connect(sc.Config.Address)
255+
sc.Conn, err = utils.Connect(sc.Config.Address, sc.Config.DialOptions...)
244256
Expect(err).NotTo(HaveOccurred())
245257
sc.connAddress = sc.Config.Address
246258
} else {
@@ -253,7 +265,7 @@ func (sc *TestContext) Setup() {
253265
sc.ControllerConn = sc.Conn
254266
sc.controllerConnAddress = sc.Config.Address
255267
} else {
256-
sc.ControllerConn, err = utils.Connect(sc.Config.ControllerAddress)
268+
sc.ControllerConn, err = utils.Connect(sc.Config.ControllerAddress, sc.Config.ControllerDialOptions...)
257269
Expect(err).NotTo(HaveOccurred())
258270
sc.controllerConnAddress = sc.Config.ControllerAddress
259271
}

test/driver_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func TestSimpleDriver(t *testing.T) {
106106
defer s.Stop()
107107

108108
// Setup a connection to the driver
109-
conn, err := utils.Connect(s.Address())
109+
conn, err := utils.Connect(s.Address(), grpc.WithInsecure())
110110
if err != nil {
111111
t.Errorf("Error: %s", err.Error())
112112
}

utils/grpcutil.go

+1-10
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,10 @@ import (
2525

2626
"google.golang.org/grpc"
2727
"google.golang.org/grpc/connectivity"
28-
"google.golang.org/grpc/keepalive"
2928
)
3029

3130
// Connect address by grpc
32-
func Connect(address string) (*grpc.ClientConn, error) {
33-
dialOptions := []grpc.DialOption{
34-
grpc.WithInsecure(),
35-
}
31+
func Connect(address string, dialOptions ...grpc.DialOption) (*grpc.ClientConn, error) {
3632
u, err := url.Parse(address)
3733
if err == nil && (!u.IsAbs() || u.Scheme == "unix") {
3834
dialOptions = append(dialOptions,
@@ -41,11 +37,6 @@ func Connect(address string) (*grpc.ClientConn, error) {
4137
return net.DialTimeout("unix", u.Path, timeout)
4238
}))
4339
}
44-
// This is necessary when connecting via TCP and does not hurt
45-
// when using Unix domain sockets. It ensures that gRPC detects a dead connection
46-
// in a timely manner.
47-
dialOptions = append(dialOptions,
48-
grpc.WithKeepaliveParams(keepalive.ClientParameters{PermitWithoutStream: true}))
4940

5041
conn, err := grpc.Dial(address, dialOptions...)
5142
if err != nil {

0 commit comments

Comments
 (0)