Skip to content

Commit f4f0f7a

Browse files
authored
Merge pull request kubernetes-csi#200 from alexanderKhaustov/create-volumes-with-topology
CreateVolume respects the topology requirements of the node
2 parents bd0bf72 + 119b8c5 commit f4f0f7a

File tree

2 files changed

+72
-39
lines changed

2 files changed

+72
-39
lines changed

pkg/sanity/controller.go

+48-26
Original file line numberDiff line numberDiff line change
@@ -1119,8 +1119,26 @@ var _ = DescribeSanity("Controller Service", func(sc *SanityContext) {
11191119
Expect(serverError.Code()).To(Equal(codes.InvalidArgument))
11201120
})
11211121

1122+
// CSI spec poses no specific requirements for the cluster/storage setups that a SP MUST support. To perform
1123+
// meaningful checks the following test assumes that topology-aware provisioning on a single node setup is supported
11221124
It("should return appropriate values (no optional values added)", func() {
11231125

1126+
By("getting node information")
1127+
ni, err := n.NodeGetInfo(
1128+
context.Background(),
1129+
&csi.NodeGetInfoRequest{})
1130+
Expect(err).NotTo(HaveOccurred())
1131+
Expect(ni).NotTo(BeNil())
1132+
Expect(ni.GetNodeId()).NotTo(BeEmpty())
1133+
1134+
var accReqs *csi.TopologyRequirement
1135+
if ni.AccessibleTopology != nil {
1136+
// Topology requirements are honored if provided by the driver
1137+
accReqs = &csi.TopologyRequirement{
1138+
Requisite: []*csi.Topology{ni.AccessibleTopology},
1139+
}
1140+
}
1141+
11241142
// Create Volume First
11251143
By("creating a single node writer volume")
11261144
name := UniqueString("sanity-controller-publish")
@@ -1139,8 +1157,9 @@ var _ = DescribeSanity("Controller Service", func(sc *SanityContext) {
11391157
},
11401158
},
11411159
},
1142-
Secrets: sc.Secrets.CreateVolumeSecret,
1143-
Parameters: sc.Config.TestVolumeParameters,
1160+
Secrets: sc.Secrets.CreateVolumeSecret,
1161+
Parameters: sc.Config.TestVolumeParameters,
1162+
AccessibilityRequirements: accReqs,
11441163
},
11451164
)
11461165
Expect(err).NotTo(HaveOccurred())
@@ -1149,22 +1168,14 @@ var _ = DescribeSanity("Controller Service", func(sc *SanityContext) {
11491168
Expect(vol.GetVolume().GetVolumeId()).NotTo(BeEmpty())
11501169
cl.RegisterVolume(name, VolumeInfo{VolumeID: vol.GetVolume().GetVolumeId()})
11511170

1152-
By("getting a node id")
1153-
nid, err := n.NodeGetInfo(
1154-
context.Background(),
1155-
&csi.NodeGetInfoRequest{})
1156-
Expect(err).NotTo(HaveOccurred())
1157-
Expect(nid).NotTo(BeNil())
1158-
Expect(nid.GetNodeId()).NotTo(BeEmpty())
1159-
11601171
// ControllerPublishVolume
11611172
By("calling controllerpublish on that volume")
11621173

11631174
conpubvol, err := c.ControllerPublishVolume(
11641175
context.Background(),
11651176
&csi.ControllerPublishVolumeRequest{
11661177
VolumeId: vol.GetVolume().GetVolumeId(),
1167-
NodeId: nid.GetNodeId(),
1178+
NodeId: ni.GetNodeId(),
11681179
VolumeCapability: &csi.VolumeCapability{
11691180
AccessType: &csi.VolumeCapability_Mount{
11701181
Mount: &csi.VolumeCapability_MountVolume{},
@@ -1178,7 +1189,7 @@ var _ = DescribeSanity("Controller Service", func(sc *SanityContext) {
11781189
},
11791190
)
11801191
Expect(err).NotTo(HaveOccurred())
1181-
cl.RegisterVolume(name, VolumeInfo{VolumeID: vol.GetVolume().GetVolumeId(), NodeID: nid.GetNodeId()})
1192+
cl.RegisterVolume(name, VolumeInfo{VolumeID: vol.GetVolume().GetVolumeId(), NodeID: ni.GetNodeId()})
11821193
Expect(conpubvol).NotTo(BeNil())
11831194

11841195
By("cleaning up unpublishing the volume")
@@ -1188,7 +1199,7 @@ var _ = DescribeSanity("Controller Service", func(sc *SanityContext) {
11881199
&csi.ControllerUnpublishVolumeRequest{
11891200
VolumeId: vol.GetVolume().GetVolumeId(),
11901201
// NodeID is optional in ControllerUnpublishVolume
1191-
NodeId: nid.GetNodeId(),
1202+
NodeId: ni.GetNodeId(),
11921203
Secrets: sc.Secrets.ControllerUnpublishVolumeSecret,
11931204
},
11941205
)
@@ -1474,12 +1485,30 @@ var _ = DescribeSanity("Controller Service", func(sc *SanityContext) {
14741485
Expect(serverError.Code()).To(Equal(codes.InvalidArgument))
14751486
})
14761487

1488+
// CSI spec poses no specific requirements for the cluster/storage setups that a SP MUST support. To perform
1489+
// meaningful checks the following test assumes that topology-aware provisioning on a single node setup is supported
14771490
It("should return appropriate values (no optional values added)", func() {
14781491

14791492
// Create Volume First
14801493
By("creating a single node writer volume")
14811494
name := UniqueString("sanity-controller-unpublish")
14821495

1496+
By("getting node information")
1497+
ni, err := n.NodeGetInfo(
1498+
context.Background(),
1499+
&csi.NodeGetInfoRequest{})
1500+
Expect(err).NotTo(HaveOccurred())
1501+
Expect(ni).NotTo(BeNil())
1502+
Expect(ni.GetNodeId()).NotTo(BeEmpty())
1503+
1504+
var accReqs *csi.TopologyRequirement
1505+
if ni.AccessibleTopology != nil {
1506+
// Topology requirements are honored if provided by the driver
1507+
accReqs = &csi.TopologyRequirement{
1508+
Requisite: []*csi.Topology{ni.AccessibleTopology},
1509+
}
1510+
}
1511+
14831512
vol, err := c.CreateVolume(
14841513
context.Background(),
14851514
&csi.CreateVolumeRequest{
@@ -1494,8 +1523,9 @@ var _ = DescribeSanity("Controller Service", func(sc *SanityContext) {
14941523
},
14951524
},
14961525
},
1497-
Secrets: sc.Secrets.CreateVolumeSecret,
1498-
Parameters: sc.Config.TestVolumeParameters,
1526+
Secrets: sc.Secrets.CreateVolumeSecret,
1527+
Parameters: sc.Config.TestVolumeParameters,
1528+
AccessibilityRequirements: accReqs,
14991529
},
15001530
)
15011531
Expect(err).NotTo(HaveOccurred())
@@ -1504,22 +1534,14 @@ var _ = DescribeSanity("Controller Service", func(sc *SanityContext) {
15041534
Expect(vol.GetVolume().GetVolumeId()).NotTo(BeEmpty())
15051535
cl.RegisterVolume(name, VolumeInfo{VolumeID: vol.GetVolume().GetVolumeId()})
15061536

1507-
By("getting a node id")
1508-
nid, err := n.NodeGetInfo(
1509-
context.Background(),
1510-
&csi.NodeGetInfoRequest{})
1511-
Expect(err).NotTo(HaveOccurred())
1512-
Expect(nid).NotTo(BeNil())
1513-
Expect(nid.GetNodeId()).NotTo(BeEmpty())
1514-
15151537
// ControllerPublishVolume
15161538
By("calling controllerpublish on that volume")
15171539

15181540
conpubvol, err := c.ControllerPublishVolume(
15191541
context.Background(),
15201542
&csi.ControllerPublishVolumeRequest{
15211543
VolumeId: vol.GetVolume().GetVolumeId(),
1522-
NodeId: nid.GetNodeId(),
1544+
NodeId: ni.GetNodeId(),
15231545
VolumeCapability: &csi.VolumeCapability{
15241546
AccessType: &csi.VolumeCapability_Mount{
15251547
Mount: &csi.VolumeCapability_MountVolume{},
@@ -1533,7 +1555,7 @@ var _ = DescribeSanity("Controller Service", func(sc *SanityContext) {
15331555
},
15341556
)
15351557
Expect(err).NotTo(HaveOccurred())
1536-
cl.RegisterVolume(name, VolumeInfo{VolumeID: vol.GetVolume().GetVolumeId(), NodeID: nid.GetNodeId()})
1558+
cl.RegisterVolume(name, VolumeInfo{VolumeID: vol.GetVolume().GetVolumeId(), NodeID: ni.GetNodeId()})
15371559
Expect(conpubvol).NotTo(BeNil())
15381560

15391561
// ControllerUnpublishVolume
@@ -1544,7 +1566,7 @@ var _ = DescribeSanity("Controller Service", func(sc *SanityContext) {
15441566
&csi.ControllerUnpublishVolumeRequest{
15451567
VolumeId: vol.GetVolume().GetVolumeId(),
15461568
// NodeID is optional in ControllerUnpublishVolume
1547-
NodeId: nid.GetNodeId(),
1569+
NodeId: ni.GetNodeId(),
15481570
Secrets: sc.Secrets.ControllerUnpublishVolumeSecret,
15491571
},
15501572
)

pkg/sanity/node.go

+24-13
Original file line numberDiff line numberDiff line change
@@ -622,9 +622,27 @@ var _ = DescribeSanity("Node Service", func(sc *SanityContext) {
622622

623623
})
624624

625+
// CSI spec poses no specific requirements for the cluster/storage setups that a SP MUST support. To perform
626+
// meaningful checks the following test assumes that topology-aware provisioning on a single node setup is supported
625627
It("should work", func() {
626628
name := UniqueString("sanity-node-full")
627629

630+
By("getting node information")
631+
ni, err := c.NodeGetInfo(
632+
context.Background(),
633+
&csi.NodeGetInfoRequest{})
634+
Expect(err).NotTo(HaveOccurred())
635+
Expect(ni).NotTo(BeNil())
636+
Expect(ni.GetNodeId()).NotTo(BeEmpty())
637+
638+
var accReqs *csi.TopologyRequirement
639+
if ni.AccessibleTopology != nil {
640+
// Topology requirements are honored if provided by the driver
641+
accReqs = &csi.TopologyRequirement{
642+
Requisite: []*csi.Topology{ni.AccessibleTopology},
643+
}
644+
}
645+
628646
// Create Volume First
629647
By("creating a single node writer volume")
630648
vol, err := s.CreateVolume(
@@ -641,8 +659,9 @@ var _ = DescribeSanity("Node Service", func(sc *SanityContext) {
641659
},
642660
},
643661
},
644-
Secrets: sc.Secrets.CreateVolumeSecret,
645-
Parameters: sc.Config.TestVolumeParameters,
662+
Secrets: sc.Secrets.CreateVolumeSecret,
663+
Parameters: sc.Config.TestVolumeParameters,
664+
AccessibilityRequirements: accReqs,
646665
},
647666
)
648667
Expect(err).NotTo(HaveOccurred())
@@ -651,14 +670,6 @@ var _ = DescribeSanity("Node Service", func(sc *SanityContext) {
651670
Expect(vol.GetVolume().GetVolumeId()).NotTo(BeEmpty())
652671
cl.RegisterVolume(name, VolumeInfo{VolumeID: vol.GetVolume().GetVolumeId()})
653672

654-
By("getting a node id")
655-
nid, err := c.NodeGetInfo(
656-
context.Background(),
657-
&csi.NodeGetInfoRequest{})
658-
Expect(err).NotTo(HaveOccurred())
659-
Expect(nid).NotTo(BeNil())
660-
Expect(nid.GetNodeId()).NotTo(BeEmpty())
661-
662673
var conpubvol *csi.ControllerPublishVolumeResponse
663674
if controllerPublishSupported {
664675
By("controller publishing volume")
@@ -667,7 +678,7 @@ var _ = DescribeSanity("Node Service", func(sc *SanityContext) {
667678
context.Background(),
668679
&csi.ControllerPublishVolumeRequest{
669680
VolumeId: vol.GetVolume().GetVolumeId(),
670-
NodeId: nid.GetNodeId(),
681+
NodeId: ni.GetNodeId(),
671682
VolumeCapability: &csi.VolumeCapability{
672683
AccessType: &csi.VolumeCapability_Mount{
673684
Mount: &csi.VolumeCapability_MountVolume{},
@@ -682,7 +693,7 @@ var _ = DescribeSanity("Node Service", func(sc *SanityContext) {
682693
},
683694
)
684695
Expect(err).NotTo(HaveOccurred())
685-
cl.RegisterVolume(name, VolumeInfo{VolumeID: vol.GetVolume().GetVolumeId(), NodeID: nid.GetNodeId()})
696+
cl.RegisterVolume(name, VolumeInfo{VolumeID: vol.GetVolume().GetVolumeId(), NodeID: ni.GetNodeId()})
686697
Expect(conpubvol).NotTo(BeNil())
687698
}
688699
// NodeStageVolume
@@ -782,7 +793,7 @@ var _ = DescribeSanity("Node Service", func(sc *SanityContext) {
782793
context.Background(),
783794
&csi.ControllerUnpublishVolumeRequest{
784795
VolumeId: vol.GetVolume().GetVolumeId(),
785-
NodeId: nid.GetNodeId(),
796+
NodeId: ni.GetNodeId(),
786797
Secrets: sc.Secrets.ControllerUnpublishVolumeSecret,
787798
},
788799
)

0 commit comments

Comments
 (0)