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

Use the old topology key for e2e tests #814

Merged
merged 1 commit into from
Mar 23, 2021
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
1 change: 1 addition & 0 deletions tests/e2e/driver/ebs_csi_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func (d *ebsCSIDriver) GetDynamicProvisionStorageClass(parameters map[string]str
{
MatchLabelExpressions: []v1.TopologySelectorLabelRequirement{
{
// TODO we should use the new topology key eventually
Key: ebscsidriver.TopologyKey,
Values: allowedTopologyValues,
},
Expand Down
24 changes: 21 additions & 3 deletions tests/e2e/testsuites/testsuites.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ package testsuites
import (
"context"
"fmt"
"github.com/aws/aws-sdk-go/aws"
"math/rand"
"time"

"github.com/aws/aws-sdk-go/aws"

"github.com/kubernetes-csi/external-snapshotter/v2/pkg/apis/volumesnapshot/v1beta1"

snapshotclientset "github.com/kubernetes-csi/external-snapshotter/v2/pkg/client/clientset/versioned"
Expand Down Expand Up @@ -365,8 +366,25 @@ func (t *TestPersistentVolumeClaim) ValidateProvisionedPersistentVolume() {
To(HaveLen(1))
}
if len(t.storageClass.AllowedTopologies) > 0 {
Expect(t.persistentVolume.Spec.NodeAffinity.Required.NodeSelectorTerms[0].MatchExpressions[0].Key).
To(Equal(t.storageClass.AllowedTopologies[0].MatchLabelExpressions[0].Key))
// Since we're chaging our topology key, assume we have the values below to compare:
// NodeSelectorTerms: [{[{topology.ebs.csi.aws.com/zone In [us-west-2a]} {topology.kubernetes.io/zone In [us-west-2a]}] []}]
// AllowedTopologies: [{[{topology.ebs.csi.aws.com/zone [us-west-2a us-west-2b us-west-2c]}]}]
// As you can see tests might fail depending on the ordering of the NodeSelectorTerms. That's why we're doing this "hack".
// This is a quick fix to unblock the PRs we have. We really need to improve this. TODO

keyFound := false
for _, v := range t.persistentVolume.Spec.NodeAffinity.Required.NodeSelectorTerms[0].MatchExpressions {
if v.Key == "topology.ebs.csi.aws.com/zone" {
keyFound = true
Expect(v.Key).To(Equal(t.storageClass.AllowedTopologies[0].MatchLabelExpressions[0].Key))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This statement is pointless, it's a tautology, if you're in this if statement then this is already guaranteed to be true

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

never mind, I confused storageClass allowedTopoloigies with the PV spec field? I'm a bit lost TBH,whether my SC has the old key or new key, the PV should have both old or new key right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah PV has the both keys, but SC has one (in e2e tests it's always the oldest one, see above tests/e2e/driver/ebs_csi_driver.go). So we have to make sure we're comparing the correct keys.

For example, this test fails when t.persistentVolume.Spec.NodeAffinity.Required.NodeSelectorTerms[0].MatchExpressions[0].Key is not topology.ebs.csi.aws.com/zone, which is possible because we also have topology.kubernetes.io/zone in the slice.

}
}

// additional sanity check so we can catch an unintended test case that'd hide failures
if !keyFound {
Fail("Volume is expected to have a node selector term.")
}

for _, v := range t.persistentVolume.Spec.NodeAffinity.Required.NodeSelectorTerms[0].MatchExpressions[0].Values {
Expect(t.storageClass.AllowedTopologies[0].MatchLabelExpressions[0].Values).To(ContainElement(v))
}
Expand Down