From 631f2c38e2b8ed832b2298548c85b566b6dc6ae9 Mon Sep 17 00:00:00 2001 From: Serguei Bezverkhi Date: Thu, 1 Nov 2018 18:23:39 -0400 Subject: [PATCH 1/3] Make probe universal Signed-off-by: Serguei Bezverkhi --- cmd/main.go | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/cmd/main.go b/cmd/main.go index cc5eb319..5a967285 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -42,23 +42,6 @@ var ( ) func runProbe(ctx context.Context, csiConn connection.CSIConnection) error { - - // Get CSI driver name. - glog.Infof("Calling CSI driver to discover driver name.") - csiDriverName, err := csiConn.GetDriverName(ctx) - if err != nil { - return err - } - glog.Infof("CSI driver name: %q", csiDriverName) - - // Get CSI Driver Node ID - glog.Infof("Calling CSI driver to discover node ID.") - csiDriverNodeID, err := csiConn.NodeGetId(ctx) - if err != nil { - return err - } - glog.Infof("CSI driver node ID: %q", csiDriverNodeID) - // Sending Probe request glog.Infof("Sending probe request to CSI driver.") if err := csiConn.LivenessProbe(ctx); err != nil { From 7a0c618c3e824f8809f3f7775c649bb80bdc7c04 Mon Sep 17 00:00:00 2001 From: Serguei Bezverkhi Date: Thu, 1 Nov 2018 18:45:43 -0400 Subject: [PATCH 2/3] Fix unit test Signed-off-by: Serguei Bezverkhi --- cmd/livenessprobe_test.go | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/cmd/livenessprobe_test.go b/cmd/livenessprobe_test.go index 0153137e..5c5d6251 100644 --- a/cmd/livenessprobe_test.go +++ b/cmd/livenessprobe_test.go @@ -62,7 +62,7 @@ func createMockServer(t *testing.T) ( } func TestProbe(t *testing.T) { - mockController, driver, idServer, _, nodeServer, csiConn, err := createMockServer(t) + mockController, driver, idServer, _, _, csiConn, err := createMockServer(t) if err != nil { t.Fatal(err) } @@ -70,19 +70,7 @@ func TestProbe(t *testing.T) { defer driver.Stop() defer csiConn.Close() - // Setting up expected calls' responses - inPlugin := &csi.GetPluginInfoRequest{} - outPlugin := &csi.GetPluginInfoResponse{ - Name: "foo/bar", - } var injectedErr error - idServer.EXPECT().GetPluginInfo(gomock.Any(), inPlugin).Return(outPlugin, injectedErr).Times(1) - - inNode := &csi.NodeGetIdRequest{} - outNode := &csi.NodeGetIdResponse{ - NodeId: "test_node_id", - } - nodeServer.EXPECT().NodeGetId(gomock.Any(), inNode).Return(outNode, injectedErr).Times(1) inProbe := &csi.ProbeRequest{} outProbe := &csi.ProbeResponse{} idServer.EXPECT().Probe(gomock.Any(), inProbe).Return(outProbe, injectedErr).Times(1) From 9c4086313a546fa4b383f99a16eb4bcdbe79d119 Mon Sep 17 00:00:00 2001 From: Serguei Bezverkhi Date: Thu, 1 Nov 2018 19:18:16 -0400 Subject: [PATCH 3/3] Address comments Signed-off-by: Serguei Bezverkhi --- cmd/livenessprobe_test.go | 8 ++++++++ cmd/main.go | 7 +++++++ pkg/connection/connection.go | 19 ------------------- 3 files changed, 15 insertions(+), 19 deletions(-) diff --git a/cmd/livenessprobe_test.go b/cmd/livenessprobe_test.go index 5c5d6251..bc17e898 100644 --- a/cmd/livenessprobe_test.go +++ b/cmd/livenessprobe_test.go @@ -71,6 +71,14 @@ func TestProbe(t *testing.T) { defer csiConn.Close() var injectedErr error + + // Setting up expected calls' responses + inPlugin := &csi.GetPluginInfoRequest{} + outPlugin := &csi.GetPluginInfoResponse{ + Name: "foo/bar", + } + idServer.EXPECT().GetPluginInfo(gomock.Any(), inPlugin).Return(outPlugin, injectedErr).Times(1) + inProbe := &csi.ProbeRequest{} outProbe := &csi.ProbeResponse{} idServer.EXPECT().Probe(gomock.Any(), inProbe).Return(outProbe, injectedErr).Times(1) diff --git a/cmd/main.go b/cmd/main.go index 5a967285..696b64d8 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -42,6 +42,13 @@ var ( ) func runProbe(ctx context.Context, csiConn connection.CSIConnection) error { + // Get CSI driver name. + glog.Infof("Calling CSI driver to discover driver name.") + csiDriverName, err := csiConn.GetDriverName(ctx) + if err != nil { + return err + } + glog.Infof("CSI driver name: %q", csiDriverName) // Sending Probe request glog.Infof("Sending probe request to CSI driver.") if err := csiConn.LivenessProbe(ctx); err != nil { diff --git a/pkg/connection/connection.go b/pkg/connection/connection.go index f91c5232..3f2b5216 100644 --- a/pkg/connection/connection.go +++ b/pkg/connection/connection.go @@ -36,9 +36,6 @@ type CSIConnection interface { // call. GetDriverName(ctx context.Context) (string, error) - // NodeGetId returns node ID of the current according to the CSI driver. - NodeGetId(ctx context.Context) (string, error) - // Liveness Probe LivenessProbe(ctx context.Context) error @@ -126,22 +123,6 @@ func (c *csiConnection) LivenessProbe(ctx context.Context) error { return nil } -func (c *csiConnection) NodeGetId(ctx context.Context) (string, error) { - client := csi.NewNodeClient(c.conn) - - req := csi.NodeGetIdRequest{} - - rsp, err := client.NodeGetId(ctx, &req) - if err != nil { - return "", err - } - nodeID := rsp.GetNodeId() - if nodeID == "" { - return "", fmt.Errorf("node ID is empty") - } - return nodeID, nil -} - func (c *csiConnection) Close() error { return c.conn.Close() }