Skip to content

Commit 7deb843

Browse files
committed
test: use wi for e2e test
1 parent b471b1a commit 7deb843

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+49
-5964
lines changed

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ require (
1919
github.com/onsi/ginkgo/v2 v2.19.1
2020
github.com/onsi/gomega v1.34.1
2121
github.com/pborman/uuid v1.2.1
22-
github.com/pelletier/go-toml v1.9.5
2322
github.com/pkg/errors v0.9.1
2423
github.com/satori/go.uuid v1.2.0
2524
github.com/stretchr/testify v1.9.0

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,6 @@ github.com/opencontainers/selinux v1.11.0 h1:+5Zbo97w3Lbmb3PeqQtpmTkMwsW5nRI3YaL
220220
github.com/opencontainers/selinux v1.11.0/go.mod h1:E5dMC3VPuVvVHDYmi78qvhJp8+M586T4DlDRYpFkyec=
221221
github.com/pborman/uuid v1.2.1 h1:+ZZIw58t/ozdjRaXh/3awHfmWRbzYxJoAdNJxe/3pvw=
222222
github.com/pborman/uuid v1.2.1/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k=
223-
github.com/pelletier/go-toml v1.9.5 h1:4yBQzkHv+7BHq2PQUZF3Mx0IYxG7LsP222s7Agd3ve8=
224-
github.com/pelletier/go-toml v1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
225223
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c h1:+mdjkGKdHQG3305AYmdv1U2eRNDiU2ErMBj1gwrq8eQ=
226224
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c/go.mod h1:7rwL4CYBLnjLxUqIJNnCWiEdr3bn6IUYi15bNlnbCCU=
227225
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=

hack/verify-examples.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ rollout_and_wait() {
2828
}
2929

3030
echo "begin to create deployment examples ..."
31+
32+
kubectl config set-context --current --namespace=default
33+
3134
if [ -v EXTERNAL_E2E_TEST_BLOBFUSE_v2 ]; then
3235
echo "create blobfuse2 storage class ..."
3336
kubectl apply -f deploy/example/storageclass-blobfuse2.yaml

pkg/util/util.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,10 @@ func parseAzcopyJobShow(jobshow string) (AzcopyJobState, string, error) {
331331
func GetKubeClient(kubeconfig string, kubeAPIQPS float64, kubeAPIBurst int, userAgent string) (kubernetes.Interface, error) {
332332
var err error
333333
var kubeCfg *rest.Config
334+
if kubeconfig == "no-need-kubeconfig" {
335+
klog.V(2).Infof("kubeconfig is set as no-need-kubeconfig, kubeClient will be nil")
336+
return nil, nil
337+
}
334338
if kubeCfg, err = clientcmd.BuildConfigFromFlags("", kubeconfig); err != nil {
335339
return nil, err
336340
}

test/e2e/suite_test.go

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package e2e
1818

1919
import (
2020
"context"
21-
"encoding/json"
2221
"flag"
2322
"fmt"
2423
"log"
@@ -42,7 +41,6 @@ import (
4241
"sigs.k8s.io/blob-csi-driver/pkg/util"
4342
"sigs.k8s.io/blob-csi-driver/test/utils/azure"
4443
"sigs.k8s.io/blob-csi-driver/test/utils/credentials"
45-
"sigs.k8s.io/blob-csi-driver/test/utils/testutil"
4644
)
4745

4846
const (
@@ -90,24 +88,11 @@ func TestE2E(t *testing.T) {
9088
var _ = ginkgo.SynchronizedBeforeSuite(func(ctx ginkgo.SpecContext) []byte {
9189
creds, err := credentials.CreateAzureCredentialFile()
9290
gomega.Expect(err).NotTo(gomega.HaveOccurred())
93-
azureClient, err := azure.GetClient(creds.Cloud, creds.SubscriptionID, creds.AADClientID, creds.TenantID, creds.AADClientSecret)
91+
azureClient, err := azure.GetClient(creds.Cloud, creds.SubscriptionID, creds.AADClientID, creds.TenantID, creds.AADClientSecret, creds.AADFederatedTokenFile)
9492
gomega.Expect(err).NotTo(gomega.HaveOccurred())
9593
_, err = azureClient.EnsureResourceGroup(ctx, creds.ResourceGroup, creds.Location, nil)
9694
gomega.Expect(err).NotTo(gomega.HaveOccurred())
9795

98-
if testutil.IsRunningInProw() {
99-
// Need to login to ACR using SP credential if we are running in Prow so we can push test images.
100-
// If running locally, user should run 'docker login' before running E2E tests
101-
registry := os.Getenv("REGISTRY")
102-
gomega.Expect(registry).NotTo(gomega.Equal(""))
103-
104-
log.Println("Attempting docker login with Azure service principal")
105-
cmd := exec.Command("docker", "login", fmt.Sprintf("--username=%s", creds.AADClientID), fmt.Sprintf("--password=%s", creds.AADClientSecret), registry)
106-
err = cmd.Run()
107-
gomega.Expect(err).NotTo(gomega.HaveOccurred())
108-
log.Println("docker login is successful")
109-
}
110-
11196
// Install Azure Blob Storage CSI driver on cluster from project root
11297
e2eBootstrap := testCmd{
11398
command: "make",
@@ -123,25 +108,8 @@ var _ = ginkgo.SynchronizedBeforeSuite(func(ctx ginkgo.SpecContext) []byte {
123108
endLog: "metrics service created",
124109
}
125110
execTestCmd([]testCmd{e2eBootstrap, createMetricsSVC})
126-
127-
if testutil.IsRunningInProw() {
128-
data, err := json.Marshal(creds)
129-
gomega.Expect(err).NotTo(gomega.HaveOccurred())
130-
return data
131-
}
132-
133111
return nil
134112
}, func(ctx ginkgo.SpecContext, data []byte) {
135-
if testutil.IsRunningInProw() {
136-
creds := &credentials.Credentials{}
137-
err := json.Unmarshal(data, creds)
138-
gomega.Expect(err).NotTo(gomega.HaveOccurred())
139-
// set env for azidentity.EnvironmentCredential
140-
os.Setenv("AZURE_TENANT_ID", creds.TenantID)
141-
os.Setenv("AZURE_CLIENT_ID", creds.AADClientID)
142-
os.Setenv("AZURE_CLIENT_SECRET", creds.AADClientSecret)
143-
}
144-
145113
// k8s.io/kubernetes/test/e2e/framework requires env KUBECONFIG to be set
146114
// it does not fall back to defaults
147115
if os.Getenv(kubeconfigEnvVar) == "" {
@@ -230,7 +198,7 @@ func execTestCmd(cmds []testCmd) {
230198
func checkAccountCreationLeak(ctx context.Context) {
231199
creds, err := credentials.CreateAzureCredentialFile()
232200
gomega.Expect(err).NotTo(gomega.HaveOccurred())
233-
azureClient, err := azure.GetClient(creds.Cloud, creds.SubscriptionID, creds.AADClientID, creds.TenantID, creds.AADClientSecret)
201+
azureClient, err := azure.GetClient(creds.Cloud, creds.SubscriptionID, creds.AADClientID, creds.TenantID, creds.AADClientSecret, creds.AADFederatedTokenFile)
234202
gomega.Expect(err).NotTo(gomega.HaveOccurred())
235203

236204
accountNum, err := azureClient.GetAccountNumByResourceGroup(ctx, creds.ResourceGroup)

test/sanity/run-test.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ if [ ! -f "$azcopyPath" ]; then
4343
chmod +x /usr/local/bin/azcopy
4444
fi
4545

46-
_output/amd64/blobplugin --endpoint "$controllerendpoint" -v=5 &
47-
_output/amd64/blobplugin --endpoint "$nodeendpoint" --nodeid "$nodeid" --enable-blob-mock-mount -v=5 &
46+
_output/amd64/blobplugin --endpoint "$controllerendpoint" -v=5 --kubeconfig "no-need-kubeconfig" &
47+
_output/amd64/blobplugin --endpoint "$nodeendpoint" --nodeid "$nodeid" --enable-blob-mock-mount -v=5 --kubeconfig "no-need-kubeconfig" &
4848

4949
echo "Begin to run sanity test..."
5050
readonly CSI_SANITY_BIN='csi-sanity'

test/sanity/sanity_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func TestSanity(t *testing.T) {
4141

4242
os.Setenv("AZURE_CREDENTIAL_FILE", credentials.TempAzureCredentialFilePath)
4343

44-
azureClient, err := azure.GetClient(creds.Cloud, creds.SubscriptionID, creds.AADClientID, creds.TenantID, creds.AADClientSecret)
44+
azureClient, err := azure.GetClient(creds.Cloud, creds.SubscriptionID, creds.AADClientID, creds.TenantID, creds.AADClientSecret, creds.AADFederatedTokenFile)
4545
assert.NoError(t, err)
4646

4747
ctx := context.Background()

test/utils/azure/azure_helper.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,20 @@ type Client struct {
3535
accountsClient accountclient.Interface
3636
}
3737

38-
func GetClient(cloud, subscriptionID, clientID, tenantID, clientSecret string) (*Client, error) {
38+
func GetClient(cloud, subscriptionID, clientID, tenantID, clientSecret string, aadFederatedTokenFile string) (*Client, error) {
3939
armConfig := &azclient.ARMClientConfig{
4040
Cloud: cloud,
4141
TenantID: tenantID,
4242
}
43+
useFederatedWorkloadIdentityExtension := false
44+
if aadFederatedTokenFile != "" {
45+
useFederatedWorkloadIdentityExtension = true
46+
}
4347
credProvider, err := azclient.NewAuthProvider(armConfig, &azclient.AzureAuthConfig{
44-
AADClientID: clientID,
45-
AADClientSecret: clientSecret,
48+
AADClientID: clientID,
49+
AADClientSecret: clientSecret,
50+
AADFederatedTokenFile: aadFederatedTokenFile,
51+
UseFederatedWorkloadIdentityExtension: useFederatedWorkloadIdentityExtension,
4652
})
4753
if err != nil {
4854
return nil, err

test/utils/credentials/credentials.go

Lines changed: 17 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,9 @@ import (
2020
"encoding/json"
2121
"fmt"
2222
"html/template"
23-
"log"
2423
"os"
2524

26-
"sigs.k8s.io/blob-csi-driver/test/utils/testutil"
27-
2825
"github.com/pborman/uuid"
29-
"github.com/pelletier/go-toml"
3026
)
3127

3228
const (
@@ -41,7 +37,8 @@ const (
4137
"aadClientId": "{{.AADClientID}}",
4238
"aadClientSecret": "{{.AADClientSecret}}",
4339
"resourceGroup": "{{.ResourceGroup}}",
44-
"location": "{{.Location}}"
40+
"location": "{{.Location}}",
41+
"aadFederatedTokenFile": "{{.AADFederatedTokenFile}}"
4542
}`
4643
defaultAzurePublicCloudLocation = "eastus2"
4744

@@ -53,6 +50,7 @@ const (
5350
aadClientSecretEnvVar = "AZURE_CLIENT_SECRET"
5451
resourceGroupEnvVar = "AZURE_RESOURCE_GROUP"
5552
locationEnvVar = "AZURE_LOCATION"
53+
federatedTokenFileVar = "AZURE_FEDERATED_TOKEN_FILE"
5654
)
5755

5856
// Config is used in Prow to store Azure credentials
@@ -74,20 +72,21 @@ type FromProw struct {
7472

7573
// Credentials is used in Azure Blob Storage CSI driver to store Azure credentials
7674
type Credentials struct {
77-
Cloud string
78-
TenantID string
79-
SubscriptionID string
80-
AADClientID string
81-
AADClientSecret string
82-
ResourceGroup string
83-
Location string
75+
Cloud string
76+
TenantID string
77+
SubscriptionID string
78+
AADClientID string
79+
AADClientSecret string
80+
AADFederatedTokenFile string
81+
ResourceGroup string
82+
Location string
8483
}
8584

8685
// CreateAzureCredentialFile creates a temporary Azure credential file for
8786
// Azure Blob Storage CSI driver tests and returns the credentials
8887
func CreateAzureCredentialFile() (*Credentials, error) {
8988
// Search credentials through env vars first
90-
var cloud, tenantID, subscriptionID, aadClientID, aadClientSecret, resourceGroup, location string
89+
var cloud, tenantID, subscriptionID, aadClientID, aadClientSecret, resourceGroup, location, aadFederatedTokenFile string
9190
cloud = os.Getenv(cloudNameEnvVar)
9291
if cloud == "" {
9392
cloud = AzurePublicCloud
@@ -98,6 +97,7 @@ func CreateAzureCredentialFile() (*Credentials, error) {
9897
aadClientSecret = os.Getenv(aadClientSecretEnvVar)
9998
resourceGroup = os.Getenv(resourceGroupEnvVar)
10099
location = os.Getenv(locationEnvVar)
100+
aadFederatedTokenFile = os.Getenv(federatedTokenFileVar)
101101

102102
if resourceGroup == "" {
103103
resourceGroup = ResourceGroupPrefix + uuid.NewUUID().String()
@@ -107,20 +107,8 @@ func CreateAzureCredentialFile() (*Credentials, error) {
107107
location = defaultAzurePublicCloudLocation
108108
}
109109

110-
// Running test locally
111-
if tenantID != "" && subscriptionID != "" && aadClientID != "" && aadClientSecret != "" {
112-
return parseAndExecuteTemplate(cloud, tenantID, subscriptionID, aadClientID, aadClientSecret, resourceGroup, location)
113-
}
114-
115-
// If the tests are being run in Prow, credentials are not supplied through env vars. Instead, it is supplied
116-
// through env var AZURE_CREDENTIALS. We need to convert it to AZURE_CREDENTIAL_FILE for sanity, integration and E2E tests
117-
if testutil.IsRunningInProw() {
118-
log.Println("Running in Prow, converting AZURE_CREDENTIALS to AZURE_CREDENTIAL_FILE")
119-
c, err := getCredentialsFromAzureCredentials(os.Getenv("AZURE_CREDENTIALS"))
120-
if err != nil {
121-
return nil, err
122-
}
123-
return parseAndExecuteTemplate(cloud, c.TenantID, c.SubscriptionID, c.ClientID, c.ClientSecret, resourceGroup, location)
110+
if tenantID != "" && subscriptionID != "" && aadClientID != "" && (aadClientSecret != "" || aadFederatedTokenFile != "") {
111+
return parseAndExecuteTemplate(cloud, tenantID, subscriptionID, aadClientID, aadClientSecret, aadFederatedTokenFile, resourceGroup, location)
124112
}
125113

126114
return nil, fmt.Errorf("If you are running tests locally, you will need to set the following env vars: $%s, $%s, $%s, $%s, $%s, $%s",
@@ -152,25 +140,8 @@ func ParseAzureCredentialFile() (*Credentials, error) {
152140
return cred, nil
153141
}
154142

155-
// getCredentialsFromAzureCredentials parses the azure credentials toml (AZURE_CREDENTIALS)
156-
// in Prow and returns the credential information usable to Azure Blob Storage CSI driver
157-
func getCredentialsFromAzureCredentials(azureCredentialsPath string) (*FromProw, error) {
158-
content, err := os.ReadFile(azureCredentialsPath)
159-
log.Printf("Reading credentials file %v", azureCredentialsPath)
160-
if err != nil {
161-
return nil, fmt.Errorf("error reading credentials file %v %w", azureCredentialsPath, err)
162-
}
163-
164-
c := Config{}
165-
if err := toml.Unmarshal(content, &c); err != nil {
166-
return nil, fmt.Errorf("error parsing credentials file %v %w", azureCredentialsPath, err)
167-
}
168-
169-
return &c.Creds, nil
170-
}
171-
172143
// parseAndExecuteTemplate replaces credential placeholders in azureCredentialFileTemplate with actual credentials
173-
func parseAndExecuteTemplate(cloud, tenantID, subscriptionID, aadClientID, aadClientSecret, resourceGroup, location string) (*Credentials, error) {
144+
func parseAndExecuteTemplate(cloud, tenantID, subscriptionID, aadClientID, aadClientSecret, aadFederatedTokenFile, resourceGroup, location string) (*Credentials, error) {
174145
t := template.New("AzureCredentialFileTemplate")
175146
t, err := t.Parse(azureCredentialFileTemplate)
176147
if err != nil {
@@ -189,6 +160,7 @@ func parseAndExecuteTemplate(cloud, tenantID, subscriptionID, aadClientID, aadCl
189160
subscriptionID,
190161
aadClientID,
191162
aadClientSecret,
163+
aadFederatedTokenFile,
192164
resourceGroup,
193165
location,
194166
}

0 commit comments

Comments
 (0)