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/examples/csi-app.yaml b/examples/csi-app.yaml index 51afa2910..d18819451 100644 --- a/examples/csi-app.yaml +++ b/examples/csi-app.yaml @@ -3,16 +3,6 @@ apiVersion: v1 metadata: name: my-csi-app spec: - affinity: - podAffinity: - requiredDuringSchedulingIgnoredDuringExecution: - - labelSelector: - matchExpressions: - - key: app - operator: In - values: - - csi-hostpathplugin - topologyKey: kubernetes.io/hostname containers: - name: my-frontend image: busybox 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..860303294 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 = "topology.hostpath.csi/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 }