Skip to content

Commit

Permalink
backport of commit 642e33a
Browse files Browse the repository at this point in the history
  • Loading branch information
thefallentree authored Nov 22, 2024
1 parent b36261d commit 83ed6ed
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .changelog/24522.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
csi: Fixed a bug where drivers that emit multiple topology segments would cause placements to fail
```
2 changes: 1 addition & 1 deletion e2e/csi/input/plugin-aws-ebs-controller.nomad
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ job "plugin-aws-ebs-controller" {
driver = "docker"

config {
image = "public.ecr.aws/ebs-csi-driver/aws-ebs-csi-driver:v1.5.1"
image = "public.ecr.aws/ebs-csi-driver/aws-ebs-csi-driver:v1.33.0"

args = [
"controller",
Expand Down
2 changes: 1 addition & 1 deletion e2e/csi/input/plugin-aws-ebs-nodes.nomad
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ job "plugin-aws-ebs-nodes" {
driver = "docker"

config {
image = "public.ecr.aws/ebs-csi-driver/aws-ebs-csi-driver:v1.5.1"
image = "public.ecr.aws/ebs-csi-driver/aws-ebs-csi-driver:v1.33.0"

args = [
"node",
Expand Down
16 changes: 15 additions & 1 deletion nomad/structs/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,27 @@ func (t *CSITopology) Equal(o *CSITopology) bool {
return maps.Equal(t.Segments, o.Segments)
}

func (t *CSITopology) Contains(o *CSITopology) bool {
if t == nil || o == nil {
return t == o
}

for k, ov := range o.Segments {
if tv, ok := t.Segments[k]; !ok || tv != ov {
return false
}
}

return true
}

func (t *CSITopology) MatchFound(o []*CSITopology) bool {
if t == nil || o == nil || len(o) == 0 {
return false
}

for _, other := range o {
if t.Equal(other) {
if t.Contains(other) {
return true
}
}
Expand Down
91 changes: 91 additions & 0 deletions nomad/structs/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,94 @@ func TestNodeMeta_Validate(t *testing.T) {
})
}
}

func TestCSITopology_Contains(t *testing.T) {
ci.Parallel(t)

cases := []struct {
name string
this *CSITopology
other *CSITopology
expected bool
}{
{
name: "AWS EBS pre 1.27 behavior",
this: &CSITopology{
Segments: map[string]string{
"topology.ebs.csi.aws.com/zone": "us-east-1a",
},
},
other: &CSITopology{
Segments: map[string]string{
"topology.ebs.csi.aws.com/zone": "us-east-1a",
},
},
expected: true,
},
{
name: "AWS EBS post 1.27 behavior",
this: &CSITopology{
Segments: map[string]string{
"topology.kubernetes.io/zone": "us-east-1a",
"topology.ebs.csi.aws.com/zone": "us-east-1a",
"kubernetes.io/os": "linux",
},
},
other: &CSITopology{
Segments: map[string]string{
"topology.kubernetes.io/zone": "us-east-1a",
},
},
expected: true,
},
{
name: "other contains invalid segment value for matched key",
this: &CSITopology{
Segments: map[string]string{
"topology.kubernetes.io/zone": "us-east-1a",
"topology.ebs.csi.aws.com/zone": "us-east-1a",
"kubernetes.io/os": "linux",
},
},
other: &CSITopology{
Segments: map[string]string{
"topology.kubernetes.io/zone": "us-east-1a",
"kubernetes.io/os": "windows",
},
},
expected: false,
},
{
name: "other contains invalid segment key",
this: &CSITopology{
Segments: map[string]string{
"topology.kubernetes.io/zone": "us-east-1a",
},
},
other: &CSITopology{
Segments: map[string]string{
"topology.kubernetes.io/zone": "us-east-1a",
"kubernetes.io/os": "linux",
},
},
expected: false,
},
{
name: "other is nil",
this: &CSITopology{
Segments: map[string]string{
"topology.kubernetes.io/zone": "us-east-1a",
},
},
other: nil,
expected: false,
},
}

for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
must.Eq(t, tc.expected, tc.this.Contains(tc.other))
})
}

}

0 comments on commit 83ed6ed

Please sign in to comment.