Skip to content

Commit

Permalink
Merge pull request #1968 from AndrewSirenko/fix-tag-test
Browse files Browse the repository at this point in the history
Randomly generate tag names in e2e tests to prevent flakes due to collisions
  • Loading branch information
k8s-ci-robot authored Mar 14, 2024
2 parents 0ceeadd + a2d834c commit 286f72f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
github.com/container-storage-interface/spec v1.9.0
github.com/golang/mock v1.6.0
github.com/google/go-cmp v0.6.0
github.com/google/uuid v1.6.0
github.com/kubernetes-csi/csi-proxy/client v1.1.3
github.com/kubernetes-csi/external-snapshotter/client/v4 v4.2.0
github.com/onsi/ginkgo/v2 v2.15.0
Expand Down Expand Up @@ -67,7 +68,6 @@ require (
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/pprof v0.0.0-20240207164012-fb44976bdcd5 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1 // indirect
github.com/imdario/mergo v0.3.16 // indirect
Expand Down
18 changes: 13 additions & 5 deletions tests/e2e/requires_aws_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package e2e

import (
"fmt"
"github.com/google/uuid"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
Expand All @@ -36,9 +37,14 @@ import (
ebscsidriver "github.com/kubernetes-sigs/aws-ebs-csi-driver/pkg/driver"
)

const testTagName = "testTag"
const testTagNamePrefix = "testTag"
const testTagValue = "3.1415926"

// generateTagName appends a random uuid to tag name to prevent clashes on parallel e2e test runs on shared cluster
func generateTagName() string {
return testTagNamePrefix + uuid.NewString()[:8]
}

func validateEc2Snapshot(ec2Client ec2iface.EC2API, input *ec2.DescribeSnapshotsInput) *ec2.DescribeSnapshotsOutput {
describeResult, err := ec2Client.DescribeSnapshots(input)
if err != nil {
Expand Down Expand Up @@ -78,6 +84,7 @@ var _ = Describe("[ebs-csi-e2e] [single-az] [requires-aws-api] Dynamic Provision
ec2Client := ec2.New(session.Must(session.NewSession()))

It("should create a volume with additional tags", func() {
testTag := generateTagName()
pods := []testsuites.PodDetails{
{
Cmd: testsuites.PodCmdWriteToVolume("/mnt/test-1"),
Expand All @@ -86,7 +93,7 @@ var _ = Describe("[ebs-csi-e2e] [single-az] [requires-aws-api] Dynamic Provision
CreateVolumeParameters: map[string]string{
ebscsidriver.VolumeTypeKey: awscloud.VolumeTypeGP3,
ebscsidriver.FSTypeKey: ebscsidriver.FSTypeExt4,
ebscsidriver.TagKeyPrefix: fmt.Sprintf("%s=%s", testTagName, testTagValue),
ebscsidriver.TagKeyPrefix: fmt.Sprintf("%s=%s", testTag, testTagValue),
},
ClaimSize: driver.MinimumSizeForVolumeType(awscloud.VolumeTypeGP3),
VolumeMount: testsuites.DefaultGeneratedVolumeMount,
Expand All @@ -101,7 +108,7 @@ var _ = Describe("[ebs-csi-e2e] [single-az] [requires-aws-api] Dynamic Provision
result, err := ec2Client.DescribeVolumes(&ec2.DescribeVolumesInput{
Filters: []*ec2.Filter{
{
Name: aws.String("tag:" + testTagName),
Name: aws.String("tag:" + testTag),
Values: []*string{aws.String(testTagValue)},
},
},
Expand All @@ -119,6 +126,7 @@ var _ = Describe("[ebs-csi-e2e] [single-az] [requires-aws-api] Dynamic Provision
})

It("should create a snapshot with additional tags", func() {
testTag := generateTagName()
pod := testsuites.PodDetails{
Cmd: testsuites.PodCmdWriteToVolume("/mnt/test-1"),
Volumes: []testsuites.VolumeDetails{
Expand Down Expand Up @@ -150,13 +158,13 @@ var _ = Describe("[ebs-csi-e2e] [single-az] [requires-aws-api] Dynamic Provision
Pod: pod,
RestoredPod: restoredPod,
Parameters: map[string]string{
ebscsidriver.TagKeyPrefix: fmt.Sprintf("%s=%s", testTagName, testTagValue),
ebscsidriver.TagKeyPrefix: fmt.Sprintf("%s=%s", testTag, testTagValue),
},
ValidateFunc: func(_ *volumesnapshotv1.VolumeSnapshot) {
validateEc2Snapshot(ec2Client, &ec2.DescribeSnapshotsInput{
Filters: []*ec2.Filter{
{
Name: aws.String("tag:" + testTagName),
Name: aws.String("tag:" + testTag),
Values: []*string{aws.String(testTagValue)},
},
},
Expand Down

0 comments on commit 286f72f

Please sign in to comment.