1
+ /*
2
+ Copyright 2019 The Kubernetes Authors.
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */
16
+
1
17
package connection
2
18
3
19
import (
4
20
"context"
5
- "net"
6
21
"strings"
7
22
"time"
8
23
@@ -16,22 +31,21 @@ const (
16
31
connectionLoggingInterval = 10 * time .Second
17
32
)
18
33
19
- // Connect opens insecure gRPC connection to a CSI driver. Address must be either absolute path to a socket file
20
- // or have format '<protocol>://', following gRPC name resolution mechanism at https://github.com/grpc/grpc/blob/master/doc/naming.md.
21
- // The function tries to connect indefinitely every second until it connects. The function automatically adds
22
- // interceptor for gRPC message logging.
23
- func Connect (address string , dialOptions ... grpc.DialOption ) (* grpc.ClientConn , error ) {
24
- dialOptions = append (dialOptions ,
34
+ // Connect opens insecure gRPC connection to a CSI driver. Address must be either absolute path to UNIX domain socket
35
+ // file or have format '<protocol>://', following gRPC name resolution mechanism at
36
+ // https://github.com/grpc/grpc/blob/master/doc/naming.md.
37
+ // The function tries to connect indefinitely every second until it connects. The function automatically disables TLS
38
+ // and adds interceptor for logging of all gRPC messages at level 5.
39
+ func Connect (address string ) (* grpc.ClientConn , error ) {
40
+ dialOptions := []grpc.DialOption {
25
41
grpc .WithInsecure (), // Don't use TLS, it's usually local Unix domain socket in a container.
26
42
grpc .WithBackoffMaxDelay (time .Second ), // Retry every second after failure.
27
43
grpc .WithBlock (), // Block until connection succeeds.
28
44
grpc .WithUnaryInterceptor (LogGRPC ), // Log all messages.
29
- )
45
+ }
30
46
if strings .HasPrefix (address , "/" ) {
31
47
// It looks like filesystem path.
32
- dialOptions = append (dialOptions , grpc .WithDialer (func (addr string , timeout time.Duration ) (net.Conn , error ) {
33
- return net .DialTimeout ("unix" , addr , timeout )
34
- }))
48
+ address = "unix://" + address
35
49
}
36
50
glog .Infof ("Connecting to %s" , address )
37
51
0 commit comments