From 1a2b1cec34e3dd5a3e92f7fefd7d104326a4bb28 Mon Sep 17 00:00:00 2001 From: Mucahit Kurt Date: Wed, 21 Aug 2019 00:04:02 +0300 Subject: [PATCH] enable topology support Signed-off-by: Mucahit Kurt --- .../hostpath/csi-hostpath-provisioner.yaml | 1 + .../hostpath/csi-hostpath-provisioner.yaml | 1 + pkg/hostpath/controllerserver.go | 21 ++++++++++++------- pkg/hostpath/hostpath.go | 2 +- pkg/hostpath/identityserver.go | 7 +++++++ pkg/hostpath/nodeserver.go | 9 +++++++- 6 files changed, 32 insertions(+), 9 deletions(-) diff --git a/deploy/kubernetes-1.14/hostpath/csi-hostpath-provisioner.yaml b/deploy/kubernetes-1.14/hostpath/csi-hostpath-provisioner.yaml index 548e1361b..1035d254e 100644 --- a/deploy/kubernetes-1.14/hostpath/csi-hostpath-provisioner.yaml +++ b/deploy/kubernetes-1.14/hostpath/csi-hostpath-provisioner.yaml @@ -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 diff --git a/deploy/kubernetes-1.15/hostpath/csi-hostpath-provisioner.yaml b/deploy/kubernetes-1.15/hostpath/csi-hostpath-provisioner.yaml index ae1b770c8..9ff79e0bf 100644 --- a/deploy/kubernetes-1.15/hostpath/csi-hostpath-provisioner.yaml +++ b/deploy/kubernetes-1.15/hostpath/csi-hostpath-provisioner.yaml @@ -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 diff --git a/pkg/hostpath/controllerserver.go b/pkg/hostpath/controllerserver.go index 0744363d8..bf072ab34 100644 --- a/pkg/hostpath/controllerserver.go +++ b/pkg/hostpath/controllerserver.go @@ -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( @@ -64,6 +65,7 @@ func NewControllerServer(ephemeral bool) *controllerServer { csi.ControllerServiceCapability_RPC_LIST_SNAPSHOTS, csi.ControllerServiceCapability_RPC_CLONE_VOLUME, }), + nodeID: nodeID, } } @@ -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 } diff --git a/pkg/hostpath/hostpath.go b/pkg/hostpath/hostpath.go index da61dda37..3caa9b0f8 100644 --- a/pkg/hostpath/hostpath.go +++ b/pkg/hostpath/hostpath.go @@ -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) diff --git a/pkg/hostpath/identityserver.go b/pkg/hostpath/identityserver.go index 24da768b6..4fdd752a0 100644 --- a/pkg/hostpath/identityserver.go +++ b/pkg/hostpath/identityserver.go @@ -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 } diff --git a/pkg/hostpath/nodeserver.go b/pkg/hostpath/nodeserver.go index 2bc59add0..697a281f5 100644 --- a/pkg/hostpath/nodeserver.go +++ b/pkg/hostpath/nodeserver.go @@ -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 @@ -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 }