Skip to content

Commit 1a2b1ce

Browse files
committed
enable topology support
Signed-off-by: Mucahit Kurt <[email protected]>
1 parent a0b9f0c commit 1a2b1ce

File tree

6 files changed

+32
-9
lines changed

6 files changed

+32
-9
lines changed

deploy/kubernetes-1.14/hostpath/csi-hostpath-provisioner.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ spec:
4545
- -v=5
4646
- --csi-address=/csi/csi.sock
4747
- --connection-timeout=15s
48+
- --feature-gates=Topology=true
4849
volumeMounts:
4950
- mountPath: /csi
5051
name: socket-dir

deploy/kubernetes-1.15/hostpath/csi-hostpath-provisioner.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ spec:
4545
- -v=5
4646
- --csi-address=/csi/csi.sock
4747
- --connection-timeout=15s
48+
- --feature-gates=Topology=true
4849
volumeMounts:
4950
- mountPath: /csi
5051
name: socket-dir

pkg/hostpath/controllerserver.go

+14-7
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,13 @@ const (
4949
)
5050

5151
type controllerServer struct {
52-
caps []*csi.ControllerServiceCapability
52+
caps []*csi.ControllerServiceCapability
53+
nodeID string
5354
}
5455

55-
func NewControllerServer(ephemeral bool) *controllerServer {
56+
func NewControllerServer(ephemeral bool, nodeID string) *controllerServer {
5657
if ephemeral {
57-
return &controllerServer{caps: getControllerServiceCapabilities(nil)}
58+
return &controllerServer{caps: getControllerServiceCapabilities(nil), nodeID: nodeID}
5859
}
5960
return &controllerServer{
6061
caps: getControllerServiceCapabilities(
@@ -64,6 +65,7 @@ func NewControllerServer(ephemeral bool) *controllerServer {
6465
csi.ControllerServiceCapability_RPC_LIST_SNAPSHOTS,
6566
csi.ControllerServiceCapability_RPC_CLONE_VOLUME,
6667
}),
68+
nodeID: nodeID,
6769
}
6870
}
6971

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

169+
topologies := []*csi.Topology{&csi.Topology{
170+
Segments: map[string]string{TopologyKeyNode: cs.nodeID},
171+
}}
172+
167173
return &csi.CreateVolumeResponse{
168174
Volume: &csi.Volume{
169-
VolumeId: volumeID,
170-
CapacityBytes: req.GetCapacityRange().GetRequiredBytes(),
171-
VolumeContext: req.GetParameters(),
172-
ContentSource: req.GetVolumeContentSource(),
175+
VolumeId: volumeID,
176+
CapacityBytes: req.GetCapacityRange().GetRequiredBytes(),
177+
VolumeContext: req.GetParameters(),
178+
ContentSource: req.GetVolumeContentSource(),
179+
AccessibleTopology: topologies,
173180
},
174181
}, nil
175182
}

pkg/hostpath/hostpath.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ func (hp *hostPath) Run() {
126126
// Create GRPC servers
127127
hp.ids = NewIdentityServer(hp.name, hp.version)
128128
hp.ns = NewNodeServer(hp.nodeID, hp.ephemeral)
129-
hp.cs = NewControllerServer(hp.ephemeral)
129+
hp.cs = NewControllerServer(hp.ephemeral, hp.nodeID)
130130

131131
s := NewNonBlockingGRPCServer()
132132
s.Start(hp.endpoint, hp.ids, hp.cs, hp.ns)

pkg/hostpath/identityserver.go

+7
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,13 @@ func (ids *identityServer) GetPluginCapabilities(ctx context.Context, req *csi.G
6868
},
6969
},
7070
},
71+
{
72+
Type: &csi.PluginCapability_Service_{
73+
Service: &csi.PluginCapability_Service{
74+
Type: csi.PluginCapability_Service_VOLUME_ACCESSIBILITY_CONSTRAINTS,
75+
},
76+
},
77+
},
7178
},
7279
}, nil
7380
}

pkg/hostpath/nodeserver.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ import (
3131
"k8s.io/kubernetes/pkg/volume/util/volumepathhandler"
3232
)
3333

34+
const TopologyKeyNode = "node.kubernetes.io/topology.hostpath.csi.k8s.io-node"
35+
3436
type nodeServer struct {
3537
nodeID string
3638
ephemeral bool
@@ -261,8 +263,13 @@ func (ns *nodeServer) NodeUnstageVolume(ctx context.Context, req *csi.NodeUnstag
261263

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

266+
topology := &csi.Topology{
267+
Segments: map[string]string{TopologyKeyNode: ns.nodeID},
268+
}
269+
264270
return &csi.NodeGetInfoResponse{
265-
NodeId: ns.nodeID,
271+
NodeId: ns.nodeID,
272+
AccessibleTopology: topology,
266273
}, nil
267274
}
268275

0 commit comments

Comments
 (0)