Skip to content

Commit 5d7e92b

Browse files
committed
Added basic topology support to driver
1 parent 40fb7f7 commit 5d7e92b

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

pkg/gce-pd-csi-driver/controller.go

+21
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,27 @@ func (gceCS *GCEControllerServer) CreateVolume(ctx context.Context, req *csi.Cre
9595
}
9696
}
9797

98+
// Topology overwrites Storage Class Params if specified
99+
// TODO: Support preferred toplogies.
100+
if req.GetAccessibilityRequirements() != nil {
101+
reqTop := req.GetAccessibilityRequirements().GetRequisite()
102+
if reqTop == nil || len(reqTop) == 0 {
103+
return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("CreateVolume accessibility requirements specified but no requisite topologies"))
104+
}
105+
if reqTop[0].GetSegments() == nil {
106+
return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("CreateVolume requisite toplogies specified specified but no segments"))
107+
}
108+
// Currently just pick the 0th requisite toplogy. This is a valid strategy but
109+
// we may want to randomly cycle in the future (?)
110+
zoneSeg, ok := reqTop[0].GetSegments()["zone"]
111+
if ok {
112+
configuredZone = zoneSeg
113+
} else {
114+
return nil, status.Error(codes.InvalidArgument,
115+
fmt.Sprintf("CreateVolume requisite topology specified but could not find zone in segment: %v", reqTop[0].GetSegments()))
116+
}
117+
}
118+
98119
createResp := &csi.CreateVolumeResponse{
99120
Volume: &csi.Volume{
100121
CapacityBytes: capBytes,

pkg/gce-pd-csi-driver/identity.go

+7
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ func (gceIdentity *GCEIdentityServer) GetPluginCapabilities(ctx context.Context,
5151
},
5252
},
5353
},
54+
{
55+
Type: &csi.PluginCapability_Service_{
56+
Service: &csi.PluginCapability_Service{
57+
Type: csi.PluginCapability_Service_ACCESSIBILITY_CONSTRAINTS,
58+
},
59+
},
60+
},
5461
},
5562
}, nil
5663
}

pkg/gce-pd-csi-driver/node.go

+13-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import (
1919
"os"
2020
"sync"
2121

22+
"cloud.google.com/go/compute/metadata"
23+
2224
csi "github.com/container-storage-interface/spec/lib/go/csi/v0"
2325
"github.com/golang/glog"
2426
"golang.org/x/net/context"
@@ -270,12 +272,22 @@ func (ns *GCENodeServer) NodeGetCapabilities(ctx context.Context, req *csi.NodeG
270272
func (ns *GCENodeServer) NodeGetInfo(ctx context.Context, req *csi.NodeGetInfoRequest) (*csi.NodeGetInfoResponse, error) {
271273
glog.Infof("NodeGetInfo called with req: %#v", req)
272274

275+
zone, err := metadata.Zone()
276+
if err != nil {
277+
return nil, status.Error(codes.Internal, fmt.Sprintf("NodeGetInfo failed to get zone from instance metadata: %v", err))
278+
}
279+
280+
top := &csi.Topology{
281+
Segments: map[string]string{"zone": zone},
282+
}
283+
273284
resp := &csi.NodeGetInfoResponse{
274285
NodeId: ns.Driver.nodeID,
275286
// TODO: Set MaxVolumesPerNode based on Node Type
276287
// Default of 0 means that CO Decides how many nodes can be published
288+
// Can get from metadata server "machine-type"
277289
MaxVolumesPerNode: 0,
278-
AccessibleTopology: nil,
290+
AccessibleTopology: top,
279291
}
280292
return resp, nil
281293
}

0 commit comments

Comments
 (0)