Skip to content

Commit

Permalink
Merge pull request #1950 from torredil/add-os-t
Browse files Browse the repository at this point in the history
Add OS topology key to node segments map
  • Loading branch information
k8s-ci-robot authored Mar 1, 2024
2 parents 916729b + c216cfb commit 68aea20
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 31 deletions.
10 changes: 5 additions & 5 deletions pkg/driver/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -907,22 +907,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
}
Expand Down Expand Up @@ -962,7 +962,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)

Expand Down
32 changes: 16 additions & 16 deletions pkg/driver/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -1332,7 +1332,7 @@ func TestCreateVolume(t *testing.T) {
AccessibilityRequirements: &csi.TopologyRequirement{
Requisite: []*csi.Topology{
{
Segments: map[string]string{TopologyKey: expZone},
Segments: map[string]string{ZoneTopologyKey: expZone},
},
},
},
Expand All @@ -1345,7 +1345,7 @@ func TestCreateVolume(t *testing.T) {
AccessibilityRequirements: &csi.TopologyRequirement{
Requisite: []*csi.Topology{
{
Segments: map[string]string{TopologyKey: expZone},
Segments: map[string]string{ZoneTopologyKey: expZone},
},
},
},
Expand All @@ -1356,7 +1356,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},
},
},
}
Expand Down Expand Up @@ -2092,27 +2092,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"},
},
},
},
Expand All @@ -2123,12 +2123,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},
},
},
},
Expand All @@ -2139,7 +2139,7 @@ func TestPickAvailabilityZone(t *testing.T) {
requirement: &csi.TopologyRequirement{
Requisite: []*csi.Topology{
{
Segments: map[string]string{TopologyKey: expZone},
Segments: map[string]string{ZoneTopologyKey: expZone},
},
},
},
Expand Down Expand Up @@ -2184,13 +2184,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,
Expand All @@ -2208,7 +2208,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,
Expand Down
7 changes: 4 additions & 3 deletions pkg/driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 5 additions & 2 deletions pkg/driver/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"fmt"
"os"
"path/filepath"
"runtime"
"strings"
"time"

Expand Down Expand Up @@ -592,10 +593,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()
Expand Down
12 changes: 8 additions & 4 deletions pkg/driver/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"io/fs"
"os"
"reflect"
"runtime"
"strings"
"testing"

Expand Down Expand Up @@ -2330,11 +2331,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 {
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/driver/ebs_csi_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
Expand Down

0 comments on commit 68aea20

Please sign in to comment.