Skip to content
Closed
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
21 changes: 20 additions & 1 deletion test/e2e/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package e2e

import (
"context"
"flag"
"fmt"
"log"
Expand All @@ -28,6 +29,8 @@ import (
"testing"

"github.com/kubernetes-csi/csi-driver-smb/pkg/smb"
"github.com/kubernetes-csi/csi-driver-smb/test/utils/azure"
"github.com/kubernetes-csi/csi-driver-smb/test/utils/credentials"
"github.com/onsi/ginkgo/v2"
"github.com/onsi/ginkgo/v2/reporters"
"github.com/onsi/gomega"
Expand Down Expand Up @@ -110,7 +113,7 @@ type testCmd struct {
endLog string
}

var _ = ginkgo.BeforeSuite(func() {
var _ = ginkgo.BeforeSuite(func(ctx ginkgo.SpecContext) {
// k8s.io/kubernetes/test/e2e/framework requires env KUBECONFIG to be set
// it does not fall back to defaults
if os.Getenv(kubeconfigEnvVar) == "" {
Expand All @@ -123,6 +126,8 @@ var _ = ginkgo.BeforeSuite(func() {
kubeconfig := os.Getenv(kubeconfigEnvVar)
log.Println(testWinServerVerEnvVar, os.Getenv(testWinServerVerEnvVar), fmt.Sprintf("%v", winServerVer))

checkAccountCreationLeak(ctx)

// Install SMB provisioner on cluster
installSMBProvisioner := testCmd{
command: "make",
Expand Down Expand Up @@ -315,3 +320,17 @@ func getSmbTestEnvVarValue(envVarName string, defaultVarValue string) (smbTestEn
}
return
}

func checkAccountCreationLeak(ctx context.Context) {
creds, err := credentials.CreateAzureCredentialFile(false)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
azureClient, err := azure.GetAzureClient(creds.Cloud, creds.SubscriptionID, creds.AADClientID, creds.TenantID, creds.AADClientSecret)
gomega.Expect(err).NotTo(gomega.HaveOccurred())

accountNum, err := azureClient.GetAccountNumByResourceGroup(ctx, creds.ResourceGroup)
framework.ExpectNoError(err, fmt.Sprintf("failed to GetAccountNumByResourceGroup(%s): %v", creds.ResourceGroup, err))
ginkgo.By(fmt.Sprintf("GetAccountNumByResourceGroup(%s) returns %d accounts", creds.ResourceGroup, accountNum))

accountLimitInTest := 15
gomega.Expect(accountNum >= accountLimitInTest).To(gomega.BeFalse())
}
12 changes: 12 additions & 0 deletions test/utils/azure/azure_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-03-01/compute"
"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2018-08-01/network"
"github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2018-05-01/resources"
"github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage"
"github.com/Azure/go-autorest/autorest"
"github.com/Azure/go-autorest/autorest/adal"
"github.com/Azure/go-autorest/autorest/azure"
Expand All @@ -40,6 +41,7 @@ type Client struct {
nicClient network.InterfacesClient
subnetsClient network.SubnetsClient
vnetClient network.VirtualNetworksClient
accountsClient storage.AccountsClient
}

func GetAzureClient(cloud, subscriptionID, clientID, tenantID, clientSecret string) (*Client, error) {
Expand Down Expand Up @@ -259,6 +261,7 @@ func getClient(env azure.Environment, subscriptionID string, armSpt *adal.Servic
nicClient: network.NewInterfacesClient(subscriptionID),
subnetsClient: network.NewSubnetsClient(subscriptionID),
vnetClient: network.NewVirtualNetworksClient(subscriptionID),
accountsClient: storage.NewAccountsClient(subscriptionID),
}

authorizer := autorest.NewBearerAuthorizer(armSpt)
Expand All @@ -267,10 +270,19 @@ func getClient(env azure.Environment, subscriptionID string, armSpt *adal.Servic
c.nicClient.Authorizer = authorizer
c.subnetsClient.Authorizer = authorizer
c.vnetClient.Authorizer = authorizer
c.accountsClient.Authorizer = authorizer

return c
}

func (az *Client) GetAccountNumByResourceGroup(ctx context.Context, groupName string) (count int, err error) {
_, err = az.accountsClient.ListByResourceGroup(ctx, groupName)
if err != nil {
return -1, err
}
return 0, nil
}

func stringPointer(s string) *string {
return &s
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading