Skip to content

Commit

Permalink
Add implementation for NodeGetInfo
Browse files Browse the repository at this point in the history
Signed-off-by: Ameya Gawde <agawde@mirantis.com>
  • Loading branch information
ameyag committed Jul 28, 2020
1 parent 80c41f0 commit ce95bbd
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 6 deletions.
30 changes: 24 additions & 6 deletions agent/agent.go
Expand Up @@ -8,6 +8,7 @@ import (
"sync"
"time"

"github.com/docker/swarmkit/agent/csi"
"github.com/docker/swarmkit/agent/exec"
"github.com/docker/swarmkit/api"
"github.com/docker/swarmkit/log"
Expand All @@ -30,6 +31,8 @@ type Agent struct {
// for this node known to the agent.
node *api.Node

CSIPlugins []*api.NodeCSIInfo

keys []*api.EncryptionKey

sessionq chan sessionOperation
Expand Down Expand Up @@ -597,14 +600,29 @@ func (a *Agent) Publisher(ctx context.Context, subscriptionID string) (exec.LogP
func (a *Agent) nodeDescriptionWithHostname(ctx context.Context, tlsInfo *api.NodeTLSInfo) (*api.NodeDescription, error) {
desc, err := a.config.Executor.Describe(ctx)

// Override hostname and TLS info
if desc != nil {
if a.config.Hostname != "" {
desc.Hostname = a.config.Hostname
if desc == nil {
log.G(ctx).Debug("desc is nil")
return desc, err
}
// Fetch CSI node plugins
ind := 0
for _, plugin := range a.CSIPlugins {
a := csi.NewNodePlugin(plugin.NodeID, plugin.PluginName)
nodeCSIInfo, err := a.NodeGetInfo(ctx)
if err != nil {
return nil, err
}
desc.TLSInfo = tlsInfo
desc.FIPS = a.config.FIPS
desc.CSIInfo[ind] = nodeCSIInfo
ind++
}

// Override hostname and TLS info
if a.config.Hostname != "" {
desc.Hostname = a.config.Hostname
}
desc.TLSInfo = tlsInfo
desc.FIPS = a.config.FIPS

return desc, err
}

Expand Down
24 changes: 24 additions & 0 deletions agent/csi/convert.go
@@ -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.Volume 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),
}
}
61 changes: 61 additions & 0 deletions agent/csi/plugin.go
@@ -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
}

0 comments on commit ce95bbd

Please sign in to comment.