Skip to content

Commit

Permalink
flaky: e2e: fix pre-provisioned test
Browse files Browse the repository at this point in the history
  • Loading branch information
cvvz committed Apr 3, 2023
1 parent 3b5a6ee commit cce9102
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion test/e2e/pre_provisioning_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ var _ = ginkgo.Describe("[blob-csi-e2e] Pre-Provisioned", func() {
test.Run(cs, ns)
})

ginkgo.It("should use provided credentials", func() {
ginkgo.It("should use provided credentials", ginkgo.Label("flaky"), func() {
volumeSize := fmt.Sprintf("%dGi", defaultVolumeSize)
reclaimPolicy := v1.PersistentVolumeReclaimRetain
volumeBindingMode := storagev1.VolumeBindingImmediate
Expand Down
13 changes: 11 additions & 2 deletions test/e2e/testsuites/pre_provisioned_provided_credentials_tester.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package testsuites
import (
"context"
"fmt"
"strings"

"github.com/onsi/ginkgo/v2"

Expand Down Expand Up @@ -55,7 +56,7 @@ func (t *PreProvisionedProvidedCredentiasTest) Run(client clientset.Interface, n
var run = func() {
// add suffix to volumeID to force kubelet to NodeStageVolume every time,
// otherwise it will skip NodeStageVolume for the same VolumeID(VolumeHanlde)
volume.VolumeID = fmt.Sprintf("%s-%d", volume.VolumeID, i)
pod.Volumes[n].VolumeID = fmt.Sprintf("%s-%d", volume.VolumeID, i)
i++

tsecret := NewTestSecret(client, namespace, volume.NodeStageSecretRef, secretData)
Expand Down Expand Up @@ -110,6 +111,7 @@ func (t *PreProvisionedProvidedCredentiasTest) Run(client clientset.Interface, n
"azurestoragespnclientsecret": kvClient.Cred.AADClientSecret,
}

// assign role to service principal
objectID, err := kvClient.GetServicePrincipalObjectID(context.TODO(), kvClient.Cred.AADClientID)
framework.ExpectNoError(err, fmt.Sprintf("Error GetServicePrincipalObjectID from clientID(%s): %v", kvClient.Cred.AADClientID, err))

Expand All @@ -121,14 +123,17 @@ func (t *PreProvisionedProvidedCredentiasTest) Run(client clientset.Interface, n

roleDefID := *roleDef.ID
_, err = authClient.AssignRole(context.TODO(), resourceID, objectID, roleDefID)
if strings.Contains(err.Error(), "The role assignment already exists") {
err = nil
}
framework.ExpectNoError(err, fmt.Sprintf("Error AssignRole (roleDefID(%s)) to objectID(%s) to access resource (resourceID(%s)), error: %v", roleDefID, objectID, resourceID, err))

run()

// test for managed identity(objectID)
// e2e-vmss test job uses msi blobfuse-csi-driver-e2e-test-id, other jobs use service principal
objectID, err = kvClient.GetMSIObjectID(context.TODO(), "blobfuse-csi-driver-e2e-test-id")
if err != nil {
// only e2e-vmss test job will use msi blobfuse-csi-driver-e2e-test-id, other jobs use service principal, so skip here
return
}

Expand All @@ -143,13 +148,17 @@ func (t *PreProvisionedProvidedCredentiasTest) Run(client clientset.Interface, n
}
ginkgo.By(fmt.Sprintf("assign Storage Blob Data Contributor role to the managed identity, objectID:%s", objectID))
_, err = authClient.AssignRole(context.TODO(), resourceID, objectID, roleDefID)
if strings.Contains(err.Error(), "The role assignment already exists") {
err = nil
}
framework.ExpectNoError(err, fmt.Sprintf("Error AssignRole (roleDefID(%s)) to objectID(%s) to access resource (resourceID(%s)), error: %v", roleDefID, objectID, resourceID, err))

run()

// test for managed identity(resourceID)
resourceID, err = kvClient.GetMSIResourceID(context.TODO(), "blobfuse-csi-driver-e2e-test-id")
if err != nil {
// only e2e-vmss test job will use msi blobfuse-csi-driver-e2e-test-id, other jobs use service principal, so skip here
return
}
ginkgo.By(fmt.Sprintf("Run for managed identity (resourceID %s)", resourceID))
Expand Down

0 comments on commit cce9102

Please sign in to comment.