From cce9102f05f99a1e9f85499e7a38844418672762 Mon Sep 17 00:00:00 2001 From: weizhichen Date: Mon, 3 Apr 2023 07:40:40 +0000 Subject: [PATCH] flaky: e2e: fix pre-provisioned test --- test/e2e/pre_provisioning_test.go | 2 +- .../pre_provisioned_provided_credentials_tester.go | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/test/e2e/pre_provisioning_test.go b/test/e2e/pre_provisioning_test.go index cfe2805bf3..c6018a98d4 100644 --- a/test/e2e/pre_provisioning_test.go +++ b/test/e2e/pre_provisioning_test.go @@ -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 diff --git a/test/e2e/testsuites/pre_provisioned_provided_credentials_tester.go b/test/e2e/testsuites/pre_provisioned_provided_credentials_tester.go index 37af906a80..912ca782fc 100644 --- a/test/e2e/testsuites/pre_provisioned_provided_credentials_tester.go +++ b/test/e2e/testsuites/pre_provisioned_provided_credentials_tester.go @@ -19,6 +19,7 @@ package testsuites import ( "context" "fmt" + "strings" "github.com/onsi/ginkgo/v2" @@ -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) @@ -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)) @@ -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 } @@ -143,6 +148,9 @@ 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() @@ -150,6 +158,7 @@ func (t *PreProvisionedProvidedCredentiasTest) Run(client clientset.Interface, n // 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))