From c216cfbf8f8a15f248b14e365ae7fe5408e11731 Mon Sep 17 00:00:00 2001 From: Eddie Torres Date: Thu, 29 Feb 2024 18:36:17 +0000 Subject: [PATCH] Add OS topology key to node segments map Signed-off-by: Eddie Torres --- pkg/driver/controller.go | 10 +++++----- pkg/driver/controller_test.go | 32 +++++++++++++++--------------- pkg/driver/driver.go | 7 ++++--- pkg/driver/node.go | 7 +++++-- pkg/driver/node_test.go | 12 +++++++---- tests/e2e/driver/ebs_csi_driver.go | 2 +- 6 files changed, 39 insertions(+), 31 deletions(-) diff --git a/pkg/driver/controller.go b/pkg/driver/controller.go index a003773cf1..9a6009d0e0 100644 --- a/pkg/driver/controller.go +++ b/pkg/driver/controller.go @@ -873,22 +873,22 @@ func pickAvailabilityZone(requirement *csi.TopologyRequirement) string { return "" } for _, topology := range requirement.GetPreferred() { - zone, exists := topology.GetSegments()[WellKnownTopologyKey] + zone, exists := topology.GetSegments()[WellKnownZoneTopologyKey] if exists { return zone } - zone, exists = topology.GetSegments()[TopologyKey] + zone, exists = topology.GetSegments()[ZoneTopologyKey] if exists { return zone } } for _, topology := range requirement.GetRequisite() { - zone, exists := topology.GetSegments()[WellKnownTopologyKey] + zone, exists := topology.GetSegments()[WellKnownZoneTopologyKey] if exists { return zone } - zone, exists = topology.GetSegments()[TopologyKey] + zone, exists = topology.GetSegments()[ZoneTopologyKey] if exists { return zone } @@ -928,7 +928,7 @@ func newCreateVolumeResponse(disk *cloud.Disk, ctx map[string]string) *csi.Creat } } - segments := map[string]string{TopologyKey: disk.AvailabilityZone} + segments := map[string]string{ZoneTopologyKey: disk.AvailabilityZone} arn, err := arn.Parse(disk.OutpostArn) diff --git a/pkg/driver/controller_test.go b/pkg/driver/controller_test.go index 6e91e0672f..9c9bd2bc5f 100644 --- a/pkg/driver/controller_test.go +++ b/pkg/driver/controller_test.go @@ -247,7 +247,7 @@ func TestCreateVolume(t *testing.T) { Requisite: []*csi.Topology{ { Segments: map[string]string{ - TopologyKey: expZone, + ZoneTopologyKey: expZone, AwsAccountIDKey: outpostArn.AccountID, AwsOutpostIDKey: outpostArn.Resource, AwsRegionKey: outpostArn.Region, @@ -264,7 +264,7 @@ func TestCreateVolume(t *testing.T) { AccessibleTopology: []*csi.Topology{ { Segments: map[string]string{ - TopologyKey: expZone, + ZoneTopologyKey: expZone, AwsAccountIDKey: outpostArn.AccountID, AwsOutpostIDKey: outpostArn.Resource, AwsRegionKey: outpostArn.Region, @@ -1283,7 +1283,7 @@ func TestCreateVolume(t *testing.T) { AccessibilityRequirements: &csi.TopologyRequirement{ Requisite: []*csi.Topology{ { - Segments: map[string]string{TopologyKey: expZone}, + Segments: map[string]string{ZoneTopologyKey: expZone}, }, }, }, @@ -1296,7 +1296,7 @@ func TestCreateVolume(t *testing.T) { AccessibilityRequirements: &csi.TopologyRequirement{ Requisite: []*csi.Topology{ { - Segments: map[string]string{TopologyKey: expZone}, + Segments: map[string]string{ZoneTopologyKey: expZone}, }, }, }, @@ -1307,7 +1307,7 @@ func TestCreateVolume(t *testing.T) { VolumeContext: map[string]string{}, AccessibleTopology: []*csi.Topology{ { - Segments: map[string]string{TopologyKey: expZone}, + Segments: map[string]string{ZoneTopologyKey: expZone}, }, }, } @@ -2043,27 +2043,27 @@ func TestPickAvailabilityZone(t *testing.T) { expZone string }{ { - name: "Return WellKnownTopologyKey if present from preferred", + name: "Return WellKnownZoneTopologyKey if present from preferred", requirement: &csi.TopologyRequirement{ Requisite: []*csi.Topology{ { - Segments: map[string]string{TopologyKey: ""}, + Segments: map[string]string{ZoneTopologyKey: ""}, }, }, Preferred: []*csi.Topology{ { - Segments: map[string]string{TopologyKey: expZone, WellKnownTopologyKey: "foobar"}, + Segments: map[string]string{ZoneTopologyKey: expZone, WellKnownZoneTopologyKey: "foobar"}, }, }, }, expZone: "foobar", }, { - name: "Return WellKnownTopologyKey if present from requisite", + name: "Return WellKnownZoneTopologyKey if present from requisite", requirement: &csi.TopologyRequirement{ Requisite: []*csi.Topology{ { - Segments: map[string]string{TopologyKey: expZone, WellKnownTopologyKey: "foobar"}, + Segments: map[string]string{ZoneTopologyKey: expZone, WellKnownZoneTopologyKey: "foobar"}, }, }, }, @@ -2074,12 +2074,12 @@ func TestPickAvailabilityZone(t *testing.T) { requirement: &csi.TopologyRequirement{ Requisite: []*csi.Topology{ { - Segments: map[string]string{TopologyKey: ""}, + Segments: map[string]string{ZoneTopologyKey: ""}, }, }, Preferred: []*csi.Topology{ { - Segments: map[string]string{TopologyKey: expZone}, + Segments: map[string]string{ZoneTopologyKey: expZone}, }, }, }, @@ -2090,7 +2090,7 @@ func TestPickAvailabilityZone(t *testing.T) { requirement: &csi.TopologyRequirement{ Requisite: []*csi.Topology{ { - Segments: map[string]string{TopologyKey: expZone}, + Segments: map[string]string{ZoneTopologyKey: expZone}, }, }, }, @@ -2135,13 +2135,13 @@ func TestGetOutpostArn(t *testing.T) { requirement: &csi.TopologyRequirement{ Requisite: []*csi.Topology{ { - Segments: map[string]string{TopologyKey: expZone}, + Segments: map[string]string{ZoneTopologyKey: expZone}, }, }, Preferred: []*csi.Topology{ { Segments: map[string]string{ - TopologyKey: expZone, + ZoneTopologyKey: expZone, AwsAccountIDKey: outpostArn.AccountID, AwsOutpostIDKey: outpostArn.Resource, AwsRegionKey: outpostArn.Region, @@ -2159,7 +2159,7 @@ func TestGetOutpostArn(t *testing.T) { Requisite: []*csi.Topology{ { Segments: map[string]string{ - TopologyKey: expZone, + ZoneTopologyKey: expZone, AwsAccountIDKey: outpostArn.AccountID, AwsOutpostIDKey: outpostArn.Resource, AwsRegionKey: outpostArn.Region, diff --git a/pkg/driver/driver.go b/pkg/driver/driver.go index 626e31c259..04756406aa 100644 --- a/pkg/driver/driver.go +++ b/pkg/driver/driver.go @@ -51,9 +51,10 @@ const ( AwsRegionKey = "topology." + DriverName + "/region" AwsOutpostIDKey = "topology." + DriverName + "/outpost-id" - WellKnownTopologyKey = "topology.kubernetes.io/zone" - // DEPRECATED Use the WellKnownTopologyKey instead - TopologyKey = "topology." + DriverName + "/zone" + WellKnownZoneTopologyKey = "topology.kubernetes.io/zone" + // DEPRECATED Use the WellKnownZoneTopologyKey instead + ZoneTopologyKey = "topology." + DriverName + "/zone" + OSTopologyKey = "kubernetes.io/os" ) type Driver struct { diff --git a/pkg/driver/node.go b/pkg/driver/node.go index b5f50ef0cd..1089d93187 100644 --- a/pkg/driver/node.go +++ b/pkg/driver/node.go @@ -22,6 +22,7 @@ import ( "fmt" "os" "path/filepath" + "runtime" "strings" "time" @@ -587,10 +588,12 @@ func (d *nodeService) NodeGetInfo(ctx context.Context, req *csi.NodeGetInfoReque klog.V(4).InfoS("NodeGetInfo: called", "args", *req) zone := d.metadata.GetAvailabilityZone() + osType := runtime.GOOS segments := map[string]string{ - TopologyKey: zone, - WellKnownTopologyKey: zone, + ZoneTopologyKey: zone, + WellKnownZoneTopologyKey: zone, + OSTopologyKey: osType, } outpostArn := d.metadata.GetOutpostArn() diff --git a/pkg/driver/node_test.go b/pkg/driver/node_test.go index 0fcf67b504..d21e0f0767 100644 --- a/pkg/driver/node_test.go +++ b/pkg/driver/node_test.go @@ -26,6 +26,7 @@ import ( "io/fs" "os" "reflect" + "runtime" "strings" "testing" @@ -2328,11 +2329,14 @@ func TestNodeGetInfo(t *testing.T) { } at := resp.GetAccessibleTopology() - if at.Segments[TopologyKey] != tc.availabilityZone { - t.Fatalf("Expected topology %q, got %q", tc.availabilityZone, at.Segments[TopologyKey]) + if at.Segments[ZoneTopologyKey] != tc.availabilityZone { + t.Fatalf("Expected topology %q, got %q", tc.availabilityZone, at.Segments[ZoneTopologyKey]) } - if at.Segments[WellKnownTopologyKey] != tc.availabilityZone { - t.Fatalf("Expected (well-known) topology %q, got %q", tc.availabilityZone, at.Segments[WellKnownTopologyKey]) + if at.Segments[WellKnownZoneTopologyKey] != tc.availabilityZone { + t.Fatalf("Expected (well-known) topology %q, got %q", tc.availabilityZone, at.Segments[WellKnownZoneTopologyKey]) + } + if at.Segments[OSTopologyKey] != runtime.GOOS { + t.Fatalf("Expected os topology %q, got %q", runtime.GOOS, at.Segments[OSTopologyKey]) } if at.Segments[AwsAccountIDKey] != tc.outpostArn.AccountID { diff --git a/tests/e2e/driver/ebs_csi_driver.go b/tests/e2e/driver/ebs_csi_driver.go index 5f65ef27d1..078b248a7b 100644 --- a/tests/e2e/driver/ebs_csi_driver.go +++ b/tests/e2e/driver/ebs_csi_driver.go @@ -52,7 +52,7 @@ func (d *ebsCSIDriver) GetDynamicProvisionStorageClass(parameters map[string]str MatchLabelExpressions: []v1.TopologySelectorLabelRequirement{ { // TODO we should use the new topology key eventually - Key: ebscsidriver.TopologyKey, + Key: ebscsidriver.ZoneTopologyKey, Values: allowedTopologyValues, }, },