Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add OS topology key to node segments map #1950

Merged
merged 1 commit into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions pkg/driver/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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)

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 @@ -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},
},
},
},
Expand All @@ -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},
},
},
},
Expand All @@ -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},
},
},
}
Expand Down Expand Up @@ -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"},
},
},
},
Expand All @@ -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},
},
},
},
Expand All @@ -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},
},
},
},
Expand Down Expand Up @@ -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,
Expand All @@ -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,
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 @@ -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()
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 @@ -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 {
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
Loading