Skip to content

Commit

Permalink
enable topology support
Browse files Browse the repository at this point in the history
Signed-off-by: Mucahit Kurt <[email protected]>
  • Loading branch information
mucahitkurt committed Sep 5, 2019
1 parent a0b9f0c commit 1a2b1ce
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ spec:
- -v=5
- --csi-address=/csi/csi.sock
- --connection-timeout=15s
- --feature-gates=Topology=true
volumeMounts:
- mountPath: /csi
name: socket-dir
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ spec:
- -v=5
- --csi-address=/csi/csi.sock
- --connection-timeout=15s
- --feature-gates=Topology=true
volumeMounts:
- mountPath: /csi
name: socket-dir
Expand Down
21 changes: 14 additions & 7 deletions pkg/hostpath/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,13 @@ const (
)

type controllerServer struct {
caps []*csi.ControllerServiceCapability
caps []*csi.ControllerServiceCapability
nodeID string
}

func NewControllerServer(ephemeral bool) *controllerServer {
func NewControllerServer(ephemeral bool, nodeID string) *controllerServer {
if ephemeral {
return &controllerServer{caps: getControllerServiceCapabilities(nil)}
return &controllerServer{caps: getControllerServiceCapabilities(nil), nodeID: nodeID}
}
return &controllerServer{
caps: getControllerServiceCapabilities(
Expand All @@ -64,6 +65,7 @@ func NewControllerServer(ephemeral bool) *controllerServer {
csi.ControllerServiceCapability_RPC_LIST_SNAPSHOTS,
csi.ControllerServiceCapability_RPC_CLONE_VOLUME,
}),
nodeID: nodeID,
}
}

Expand Down Expand Up @@ -164,12 +166,17 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
glog.V(4).Infof("successfully populated volume %s", vol.VolID)
}

topologies := []*csi.Topology{&csi.Topology{
Segments: map[string]string{TopologyKeyNode: cs.nodeID},
}}

return &csi.CreateVolumeResponse{
Volume: &csi.Volume{
VolumeId: volumeID,
CapacityBytes: req.GetCapacityRange().GetRequiredBytes(),
VolumeContext: req.GetParameters(),
ContentSource: req.GetVolumeContentSource(),
VolumeId: volumeID,
CapacityBytes: req.GetCapacityRange().GetRequiredBytes(),
VolumeContext: req.GetParameters(),
ContentSource: req.GetVolumeContentSource(),
AccessibleTopology: topologies,
},
}, nil
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/hostpath/hostpath.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func (hp *hostPath) Run() {
// Create GRPC servers
hp.ids = NewIdentityServer(hp.name, hp.version)
hp.ns = NewNodeServer(hp.nodeID, hp.ephemeral)
hp.cs = NewControllerServer(hp.ephemeral)
hp.cs = NewControllerServer(hp.ephemeral, hp.nodeID)

s := NewNonBlockingGRPCServer()
s.Start(hp.endpoint, hp.ids, hp.cs, hp.ns)
Expand Down
7 changes: 7 additions & 0 deletions pkg/hostpath/identityserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ func (ids *identityServer) GetPluginCapabilities(ctx context.Context, req *csi.G
},
},
},
{
Type: &csi.PluginCapability_Service_{
Service: &csi.PluginCapability_Service{
Type: csi.PluginCapability_Service_VOLUME_ACCESSIBILITY_CONSTRAINTS,
},
},
},
},
}, nil
}
9 changes: 8 additions & 1 deletion pkg/hostpath/nodeserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import (
"k8s.io/kubernetes/pkg/volume/util/volumepathhandler"
)

const TopologyKeyNode = "node.kubernetes.io/topology.hostpath.csi.k8s.io-node"

type nodeServer struct {
nodeID string
ephemeral bool
Expand Down Expand Up @@ -261,8 +263,13 @@ func (ns *nodeServer) NodeUnstageVolume(ctx context.Context, req *csi.NodeUnstag

func (ns *nodeServer) NodeGetInfo(ctx context.Context, req *csi.NodeGetInfoRequest) (*csi.NodeGetInfoResponse, error) {

topology := &csi.Topology{
Segments: map[string]string{TopologyKeyNode: ns.nodeID},
}

return &csi.NodeGetInfoResponse{
NodeId: ns.nodeID,
NodeId: ns.nodeID,
AccessibleTopology: topology,
}, nil
}

Expand Down

0 comments on commit 1a2b1ce

Please sign in to comment.