Skip to content

Commit 8ce2bdf

Browse files
committed
Added topology to ValidateVolumeCapabilities, fixed spelling, added metadata comment
1 parent b04f766 commit 8ce2bdf

File tree

4 files changed

+33
-8
lines changed

4 files changed

+33
-8
lines changed

pkg/gce-cloud-provider/metadata/metadata.go

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import (
2222
"cloud.google.com/go/compute/metadata"
2323
)
2424

25+
// MetadataService is a fakeable interface exposing necessary data
26+
// from the GCE Metadata service
2527
type MetadataService interface {
2628
GetZone() string
2729
GetProject() string

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

+29-6
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ func (gceCS *GCEControllerServer) CreateVolume(ctx context.Context, req *csi.Cre
9898
}
9999

100100
// Topology overwrites Storage Class Params if specified
101-
// TODO: Support preferred toplogies.
101+
// TODO: Support preferred topologies.
102102
if req.GetAccessibilityRequirements() != nil {
103103
if len(configuredZone) != 0 {
104104
return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("CreateVolume only one of parameter zone or topology zone may be specified"))
@@ -369,11 +369,11 @@ func (gceCS *GCEControllerServer) ValidateVolumeCapabilities(ctx context.Context
369369
glog.V(5).Infof("Using default ValidateVolumeCapabilities")
370370
// Validate Arguments
371371
if req.GetVolumeCapabilities() == nil || len(req.GetVolumeCapabilities()) == 0 {
372-
return nil, status.Error(codes.InvalidArgument, "ControllerUnpublishVolume Volume Capabilities must be provided")
372+
return nil, status.Error(codes.InvalidArgument, "ValidateVolumeCapabilities Volume Capabilities must be provided")
373373
}
374374
volumeID := req.GetVolumeId()
375375
if len(volumeID) == 0 {
376-
return nil, status.Error(codes.InvalidArgument, "ControllerUnpublishVolume Volume ID must be provided")
376+
return nil, status.Error(codes.InvalidArgument, "ValidateVolumeCapabilities Volume ID must be provided")
377377
}
378378
z, n, err := common.SplitZoneNameId(volumeID)
379379
if err != nil {
@@ -403,6 +403,29 @@ func (gceCS *GCEControllerServer) ValidateVolumeCapabilities(ctx context.Context
403403
// TODO: Ignoring mount & block types for now.
404404
}
405405

406+
for _, top := range req.GetAccessibleTopology(){
407+
for k,v := range top.GetSegments(){
408+
switch k{
409+
case common.TopologyKeyZone:
410+
// take the zone from v and see if it matches with zone
411+
if v == z{
412+
// Accessible zone matches with storage zone
413+
return &csi.ValidateVolumeCapabilitiesResponse{
414+
Supported: true,
415+
}
416+
} else{
417+
// Accessible zone does not match
418+
return &csi.ValidateVolumeCapabilitiesResponse{
419+
Supported: false,
420+
Message: fmt.Sprintf("Volume %s is not accesible from topology %s:%s", volumeID, k,v)
421+
}
422+
}
423+
case default:
424+
return nil, status.Error(codes.InvalidArgument, "ValidateVolumeCapabilities unknown topology segment key")
425+
}
426+
}
427+
}
428+
406429
return &csi.ValidateVolumeCapabilitiesResponse{
407430
Supported: true,
408431
}, nil
@@ -501,10 +524,10 @@ func pickTopology(top *csi.TopologyRequirement) (string, error) {
501524
reqTop := top.GetRequisite()
502525
prefTop := top.GetPreferred()
503526

504-
// Pick the preferred toplogy in order
527+
// Pick the preferred topology in order
505528
if len(prefTop) != 0 {
506529
if prefTop[0].GetSegments() == nil {
507-
return "", fmt.Errorf("preferred toplogies specified specified but no segments")
530+
return "", fmt.Errorf("preferred topologies specified but no segments")
508531
}
509532

510533
// GCE PD cloud provider Create has no restrictions so just create in top preferred zone
@@ -516,7 +539,7 @@ func pickTopology(top *csi.TopologyRequirement) (string, error) {
516539
} else if len(reqTop) != 0 {
517540
r := rand.Intn(len(reqTop))
518541
if reqTop[r].GetSegments() == nil {
519-
return "", fmt.Errorf("requisite toplogies specified specified but no segments in requisite topology %v", r)
542+
return "", fmt.Errorf("requisite topologies specified but no segments in requisite topology %v", r)
520543
}
521544

522545
zone, err := getZoneFromSegment(reqTop[r].GetSegments())

test/e2e/tests/multi_zone_e2e_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ var _ = Describe("GCE PD CSI Driver Multi-Zone", func() {
2828
// I Think there should be a better way of guaranteeing this. Like a map from zone to instance for testInstances (?)
2929
})
3030

31-
It("Should get reasonable toplogy from nodes with NodeGetInfo", func() {
31+
It("Should get reasonable topology from nodes with NodeGetInfo", func() {
3232
for _, instance := range testInstances {
3333
testContext, err := testutils.SetupNewDriverAndClient(instance)
3434
Expect(err).To(BeNil(), "Set up new Driver and Client failed with error")

test/e2e/tests/single_zone_e2e_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ var _ = Describe("GCE PD CSI Driver", func() {
132132

133133
})
134134

135-
It("Should create disks in correct zones when toplogy is specified", func() {
135+
It("Should create disks in correct zones when topology is specified", func() {
136136
///
137137
Expect(testInstances).NotTo(BeEmpty())
138138
testContext, err := testutils.SetupNewDriverAndClient(testInstances[0])

0 commit comments

Comments
 (0)