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+
117package connection
218
319import (
420 "context"
5- "net"
621 "strings"
722 "time"
823
@@ -16,22 +31,21 @@ const (
1631 connectionLoggingInterval = 10 * time .Second
1732)
1833
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 {
2541 grpc .WithInsecure (), // Don't use TLS, it's usually local Unix domain socket in a container.
2642 grpc .WithBackoffMaxDelay (time .Second ), // Retry every second after failure.
2743 grpc .WithBlock (), // Block until connection succeeds.
2844 grpc .WithUnaryInterceptor (LogGRPC ), // Log all messages.
29- )
45+ }
3046 if strings .HasPrefix (address , "/" ) {
3147 // 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
3549 }
3650 glog .Infof ("Connecting to %s" , address )
3751
0 commit comments