forked from moby/swarmkit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Ameya Gawde <agawde@mirantis.com>
- Loading branch information
Showing
3 changed files
with
109 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package csi | ||
|
||
import ( | ||
"github.com/container-storage-interface/spec/lib/go/csi" | ||
"github.com/docker/swarmkit/api" | ||
) | ||
|
||
// deserializeTopology transforms a CSI-type topology into the equivalent swarm | ||
// type. | ||
func deserializeTopology(topology *csi.Topology) *api.Topology { | ||
return &api.Topology{ | ||
Segments: topology.Segments, | ||
} | ||
} | ||
|
||
// makeNodeInfo converts a csi.NodeGetInfoResponse object into a swarmkit NodeCSIInfo | ||
// object. | ||
func makeNodeInfo(csiNodeInfo *csi.NodeGetInfoResponse) *api.NodeCSIInfo { | ||
return &api.NodeCSIInfo{ | ||
NodeID: csiNodeInfo.NodeId, | ||
MaxVolumesPerNode: csiNodeInfo.MaxVolumesPerNode, | ||
AccessibleTopology: deserializeTopology(csiNodeInfo.AccessibleTopology), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package csi | ||
|
||
import ( | ||
"context" | ||
|
||
"google.golang.org/grpc" | ||
|
||
"github.com/container-storage-interface/spec/lib/go/csi" | ||
"github.com/docker/swarmkit/api" | ||
) | ||
|
||
type NodePlugin interface { | ||
NodeGetInfo(ctx context.Context) (*api.NodeCSIInfo, error) | ||
} | ||
|
||
// plugin represents an individual CSI node plugin | ||
type nodePlugin struct { | ||
// name is the name of the plugin, which is also the name used as the | ||
// Driver.Name field | ||
name string | ||
|
||
// node ID is identifier for the node. | ||
nodeID string | ||
|
||
// socket is the unix socket to connect to this plugin at. | ||
socket string | ||
|
||
// cc is the grpc client connection | ||
cc *grpc.ClientConn | ||
// idClient is the identity service client | ||
idClient csi.IdentityClient | ||
|
||
// nodeClient is the node service client | ||
nodeClient csi.NodeClient | ||
} | ||
|
||
// NewNodePlugin creates a new NodePlugin object. | ||
func NewNodePlugin(nodeId string, name string) NodePlugin { | ||
return &nodePlugin{ | ||
name: name, | ||
nodeID: nodeId, | ||
} | ||
} | ||
|
||
func (np *nodePlugin) Client() csi.NodeClient { | ||
return np.nodeClient | ||
} | ||
|
||
// makeGetInfoRequest makes a csi.NodeGetInfoRequest. | ||
// Messsage is emoty in CSI specs - https://github.com/container-storage-interface/spec/blob/v1.2.0/csi.proto#L1292-L1293 | ||
func (np *nodePlugin) makeGetInfoRequest() *csi.NodeGetInfoRequest { | ||
return &csi.NodeGetInfoRequest{} | ||
} | ||
|
||
func (np *nodePlugin) NodeGetInfo(ctx context.Context) (*api.NodeCSIInfo, error) { | ||
resp := &csi.NodeGetInfoResponse{ | ||
NodeId: np.nodeID, | ||
} | ||
|
||
return makeNodeInfo(resp), nil | ||
} |