Skip to content

Commit ab38a80

Browse files
authored
Merge pull request #88 from mucahitkurt/topology-support
enable topology support
2 parents 365a296 + 223f2d9 commit ab38a80

File tree

7 files changed

+32
-19
lines changed

7 files changed

+32
-19
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

examples/csi-app.yaml

-10
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,6 @@ apiVersion: v1
33
metadata:
44
name: my-csi-app
55
spec:
6-
affinity:
7-
podAffinity:
8-
requiredDuringSchedulingIgnoredDuringExecution:
9-
- labelSelector:
10-
matchExpressions:
11-
- key: app
12-
operator: In
13-
values:
14-
- csi-hostpathplugin
15-
topologyKey: kubernetes.io/hostname
166
containers:
177
- name: my-frontend
188
image: busybox

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(
@@ -65,6 +66,7 @@ func NewControllerServer(ephemeral bool) *controllerServer {
6566
csi.ControllerServiceCapability_RPC_CLONE_VOLUME,
6667
csi.ControllerServiceCapability_RPC_EXPAND_VOLUME,
6768
}),
69+
nodeID: nodeID,
6870
}
6971
}
7072

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

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

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 = "topology.hostpath.csi/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)