-
Notifications
You must be signed in to change notification settings - Fork 141
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
node driver registrar should use CSI connection lib #29
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,7 +43,7 @@ const ( | |
|
||
// Command line flags | ||
var ( | ||
connectionTimeout = flag.Duration("connection-timeout", 1*time.Minute, "Timeout for waiting for CSI driver socket.") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there anyone knows why disable timeout here? |
||
connectionTimeout = flag.Duration("connection-timeout", 0, "The --connection-timeout flag is deprecated") | ||
csiAddress = flag.String("csi-address", "/run/csi/socket", "Path of the CSI driver socket that the node-driver-registrar will connect to.") | ||
kubeletRegistrationPath = flag.String("kubelet-registration-path", "", "Path of the CSI driver socket on the Kubernetes host machine.") | ||
showVersion = flag.Bool("version", false, "Show version.") | ||
|
@@ -108,13 +108,17 @@ func main() { | |
} | ||
klog.Infof("Version: %s", version) | ||
|
||
if *connectionTimeout != 0 { | ||
klog.Warning("--connection-timeout is deprecated and will have no effect") | ||
} | ||
|
||
// Once https://github.com/container-storage-interface/spec/issues/159 is | ||
// resolved, if plugin does not support PUBLISH_UNPUBLISH_VOLUME, then we | ||
// can skip adding mapping to "csi.volume.kubernetes.io/nodeid" annotation. | ||
|
||
// Connect to CSI. | ||
klog.V(1).Infof("Attempting to open a gRPC connection with: %q", *csiAddress) | ||
csiConn, err := connection.NewConnection(*csiAddress, *connectionTimeout) | ||
csiConn, err := connection.NewConnection(*csiAddress) | ||
if err != nil { | ||
klog.Error(err.Error()) | ||
os.Exit(1) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,15 +19,12 @@ package connection | |
import ( | ||
"context" | ||
"fmt" | ||
"net" | ||
"strings" | ||
"time" | ||
|
||
"github.com/container-storage-interface/spec/lib/go/csi" | ||
"github.com/kubernetes-csi/csi-lib-utils/connection" | ||
"github.com/kubernetes-csi/csi-lib-utils/protosanitizer" | ||
"google.golang.org/grpc" | ||
"google.golang.org/grpc/codes" | ||
"google.golang.org/grpc/connectivity" | ||
"google.golang.org/grpc/status" | ||
"k8s.io/klog" | ||
) | ||
|
@@ -56,8 +53,8 @@ var ( | |
|
||
//NewConnection return a grpc connection object to a remote CSI driver. | ||
func NewConnection( | ||
address string, timeout time.Duration) (CSIConnection, error) { | ||
conn, err := connect(address, timeout) | ||
address string) (CSIConnection, error) { | ||
conn, err := connection.Connect(address) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
@@ -66,38 +63,6 @@ func NewConnection( | |
}, nil | ||
} | ||
|
||
func connect(address string, timeout time.Duration) (*grpc.ClientConn, error) { | ||
klog.V(2).Infof("Connecting to %s", address) | ||
dialOptions := []grpc.DialOption{ | ||
grpc.WithInsecure(), | ||
grpc.WithBackoffMaxDelay(time.Second), | ||
grpc.WithUnaryInterceptor(logGRPC), | ||
} | ||
if strings.HasPrefix(address, "/") { | ||
dialOptions = append(dialOptions, grpc.WithDialer(func(addr string, timeout time.Duration) (net.Conn, error) { | ||
return net.DialTimeout("unix", addr, timeout) | ||
})) | ||
} | ||
conn, err := grpc.Dial(address, dialOptions...) | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
ctx, cancel := context.WithTimeout(context.Background(), timeout) | ||
defer cancel() | ||
for { | ||
if !conn.WaitForStateChange(ctx, conn.GetState()) { | ||
klog.V(4).Infof("Connection timed out") | ||
return conn, nil // return nil, subsequent GetPluginInfo will show the real connection error | ||
} | ||
if conn.GetState() == connectivity.Ready { | ||
klog.V(3).Infof("Connected") | ||
return conn, nil | ||
} | ||
klog.V(4).Infof("Still trying, connection is %s", conn.GetState()) | ||
} | ||
} | ||
|
||
func (c *csiConnection) GetDriverName(ctx context.Context) (string, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jsafrane a lot of these rpc wrappers are also shared between sidecars. Do you think we should extract these out into csi-lib-utils too? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd clean up the wrappers first, is seems to me they are copied but only GetDriverName is really used. |
||
client := csi.NewIdentityClient(c.conn) | ||
|
||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we want to constrain the version here or just use the latest?