Skip to content
Merged
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
24 changes: 19 additions & 5 deletions pkg/azurefile/azurefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -1471,12 +1471,26 @@ func isKataNode(ctx context.Context, nodeID, confidentialContainerLabel string,
// createFolderIfNotExists creates a folder in Azure File Share if it doesn't already exist
// This function handles nested paths by creating each directory level recursively
func (d *Driver) createFolderIfNotExists(ctx context.Context, accountName, accountKey, fileShareName, folderName, storageEndpointSuffix string) error {
if accountName == "" {
return fmt.Errorf("accountName is empty")
}
if fileShareName == "" {
return fmt.Errorf("fileShareName is empty")
}

fileClient, err := newAzureFileClient(accountName, accountKey, storageEndpointSuffix)
if err != nil || fileClient.(*azureFileDataplaneClient).Client == nil {
return fmt.Errorf("create Azure File client(%s) failed: %v", accountName, err)
if err != nil {
return fmt.Errorf("create Azure File client(%s) failed: %w", accountName, err)
}
dc, ok := fileClient.(*azureFileDataplaneClient)
if !ok {
return fmt.Errorf("create Azure File client(%s) failed: expected *azureFileDataplaneClient but got %T", accountName, fileClient)
}
if dc.Client == nil {
return fmt.Errorf("create Azure File client(%s) failed: dataplane client is nil", accountName)
}

shareClient := fileClient.(*azureFileDataplaneClient).Client.NewShareClient(fileShareName)
shareClient := dc.Client.NewShareClient(fileShareName)

// Performance optimization: First check if the complete directory structure already exists
// This is the most common case and avoids unnecessary recursive checking
Expand All @@ -1501,12 +1515,12 @@ func (d *Driver) createFolderIfNotExists(ctx context.Context, accountName, accou

// Build path incrementally and create each directory level
currentPath := ""
for i, component := range pathComponents {
for _, component := range pathComponents {
if component == "" {
continue // Skip empty components
}

if i > 0 {
if currentPath != "" {
currentPath += "/"
}
currentPath += component
Expand Down
18 changes: 18 additions & 0 deletions pkg/azurefile/azurefile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1942,6 +1942,24 @@ func TestCreateFolderIfNotExists(t *testing.T) {
storageEndpointSuffix string
expectedError string
}{
{
name: "Empty account name",
accountName: "",
accountKey: base64.StdEncoding.EncodeToString([]byte("testkey")),
fileShareName: "testshare",
folderName: "testfolder",
storageEndpointSuffix: "core.windows.net",
expectedError: "accountName is empty",
},
{
name: "Empty file share name",
accountName: "testaccount",
accountKey: base64.StdEncoding.EncodeToString([]byte("testkey")),
fileShareName: "",
folderName: "testfolder",
storageEndpointSuffix: "core.windows.net",
expectedError: "fileShareName is empty",
},
{
name: "Invalid account key",
accountName: "testaccount",
Expand Down
Loading