Skip to content

Commit

Permalink
Merge pull request #773 from ayberk/ga_label
Browse files Browse the repository at this point in the history
Add well-known topology label
  • Loading branch information
k8s-ci-robot authored Mar 13, 2021
2 parents e3cf8c1 + 7460e68 commit 56ea42c
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 11 deletions.
15 changes: 12 additions & 3 deletions pkg/driver/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -569,13 +569,22 @@ func pickAvailabilityZone(requirement *csi.TopologyRequirement) string {
return ""
}
for _, topology := range requirement.GetPreferred() {
zone, exists := topology.GetSegments()[TopologyKey]
zone, exists := topology.GetSegments()[WellKnownTopologyKey]
if exists {
return zone
}

zone, exists = topology.GetSegments()[TopologyKey]
if exists {
return zone
}
}
for _, topology := range requirement.GetRequisite() {
zone, exists := topology.GetSegments()[TopologyKey]
zone, exists := topology.GetSegments()[WellKnownTopologyKey]
if exists {
return zone
}
zone, exists = topology.GetSegments()[TopologyKey]
if exists {
return zone
}
Expand Down Expand Up @@ -615,7 +624,7 @@ func newCreateVolumeResponse(disk *cloud.Disk) *csi.CreateVolumeResponse {
}
}

segments := map[string]string{TopologyKey: disk.AvailabilityZone}
segments := map[string]string{TopologyKey: disk.AvailabilityZone, WellKnownTopologyKey: disk.AvailabilityZone}

arn, err := arn.Parse(disk.OutpostArn)

Expand Down
40 changes: 34 additions & 6 deletions pkg/driver/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,12 @@ func TestCreateVolume(t *testing.T) {
AccessibleTopology: []*csi.Topology{
{
Segments: map[string]string{
TopologyKey: expZone,
AwsAccountIDKey: outpostArn.AccountID,
AwsOutpostIDKey: outpostArn.Resource,
AwsRegionKey: outpostArn.Region,
AwsPartitionKey: outpostArn.Partition,
TopologyKey: expZone,
WellKnownTopologyKey: expZone,
AwsAccountIDKey: outpostArn.AccountID,
AwsOutpostIDKey: outpostArn.Resource,
AwsRegionKey: outpostArn.Region,
AwsPartitionKey: outpostArn.Partition,
},
},
},
Expand Down Expand Up @@ -1230,7 +1231,7 @@ func TestCreateVolume(t *testing.T) {
VolumeContext: map[string]string{},
AccessibleTopology: []*csi.Topology{
{
Segments: map[string]string{TopologyKey: expZone},
Segments: map[string]string{TopologyKey: expZone, WellKnownTopologyKey: expZone},
},
},
}
Expand Down Expand Up @@ -1724,6 +1725,33 @@ func TestPickAvailabilityZone(t *testing.T) {
requirement *csi.TopologyRequirement
expZone string
}{
{
name: "Return WellKnownTopologyKey if present from preferred",
requirement: &csi.TopologyRequirement{
Requisite: []*csi.Topology{
{
Segments: map[string]string{TopologyKey: ""},
},
},
Preferred: []*csi.Topology{
{
Segments: map[string]string{TopologyKey: expZone, WellKnownTopologyKey: "foobar"},
},
},
},
expZone: "foobar",
},
{
name: "Return WellKnownTopologyKey if present from requisite",
requirement: &csi.TopologyRequirement{
Requisite: []*csi.Topology{
{
Segments: map[string]string{TopologyKey: expZone, WellKnownTopologyKey: "foobar"},
},
},
},
expZone: "foobar",
},
{
name: "Pick from preferred",
requirement: &csi.TopologyRequirement{
Expand Down
5 changes: 4 additions & 1 deletion pkg/driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,14 @@ const (

const (
DriverName = "ebs.csi.aws.com"
TopologyKey = "topology." + DriverName + "/zone"
AwsPartitionKey = "topology." + DriverName + "/partition"
AwsAccountIDKey = "topology." + DriverName + "/account-id"
AwsRegionKey = "topology." + DriverName + "/region"
AwsOutpostIDKey = "topology." + DriverName + "/outpost-id"

WellKnownTopologyKey = "topology.kubernetes.io/zone"
// DEPRECATED Use the WellKnownTopologyKey instead
TopologyKey = "topology." + DriverName + "/zone"
)

type Driver struct {
Expand Down
5 changes: 4 additions & 1 deletion pkg/driver/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -487,8 +487,11 @@ func (d *nodeService) NodeGetCapabilities(ctx context.Context, req *csi.NodeGetC
func (d *nodeService) NodeGetInfo(ctx context.Context, req *csi.NodeGetInfoRequest) (*csi.NodeGetInfoResponse, error) {
klog.V(4).Infof("NodeGetInfo: called with args %+v", *req)

zone := d.metadata.GetAvailabilityZone()

segments := map[string]string{
TopologyKey: d.metadata.GetAvailabilityZone(),
TopologyKey: zone,
WellKnownTopologyKey: zone,
}

outpostArn := d.metadata.GetOutpostArn()
Expand Down
3 changes: 3 additions & 0 deletions pkg/driver/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1470,6 +1470,9 @@ func TestNodeGetInfo(t *testing.T) {
if at.Segments[TopologyKey] != tc.availabilityZone {
t.Fatalf("Expected topology %q, got %q", tc.availabilityZone, at.Segments[TopologyKey])
}
if at.Segments[WellKnownTopologyKey] != tc.availabilityZone {
t.Fatalf("Expected well-known topology %q, got %q", tc.availabilityZone, at.Segments[WellKnownTopologyKey])
}

if at.Segments[AwsAccountIDKey] != tc.outpostArn.AccountID {
t.Fatalf("Expected AwsAccountId %q, got %q", tc.outpostArn.AccountID, at.Segments[AwsAccountIDKey])
Expand Down

0 comments on commit 56ea42c

Please sign in to comment.