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

Backport of Fix CSITopology matching logic for csi storage driver into release/1.9.x #24539

Merged
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
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))
})
}

}