Repository: kubernetes-sigs/cloud-provider-azure
Pull request #1492 (2022-04-14 09:09:12)

fix: disable match tags by default in account search when creating file share
<!--  Thanks for sending a pull request!  Here are some tips for you:

1. If this is your first time, please read our contributor guidelines: https://git.k8s.io/community/contributors/guide/first-contribution.md#your-first-contribution and developer guide https://git.k8s.io/community/contributors/devel/development.md#development-guide
2. Please label this pull request according to what type of issue you are addressing, especially if this is a release targeted pull request. For reference on required PR/issue labels, read here:
https://git.k8s.io/community/contributors/devel/sig-release/release.md#issuepr-kind-label
3. Ensure you have added or ran the appropriate tests for your PR: https://git.k8s.io/community/contributors/devel/sig-testing/testing.md
4. If you want *faster* PR reviews, read how: https://git.k8s.io/community/contributors/guide/pull-requests.md#best-practices-for-faster-reviews
5. If the PR is unfinished, see how to mark it: https://git.k8s.io/community/contributors/guide/pull-requests.md#marking-unfinished-pull-requests
-->

#### What type of PR is this?
/kind bug

#### What this PR does / why we need it:
fix: disable match tags by default in account search when creating file share

From azure file csi driver v1.13.0, there is tags matching, unfortunately there is a bug in tags matching which would lead to creating a new account every time when creating a new file share, this PR fixes the issue by disabling match tags by default in account search when creating file share. Tag matching is only enabled when it's specified explicitly.

#### Which issue(s) this PR fixes:
<!--
*Automatically closes linked issue when PR is merged.
Usage: `Fixes #<issue number>`, or `Fixes (paste link of issue)`.
_If PR is about `failing-tests or flakes`, please post the related issues/tests in a comment and do not use `Fixes`_*
-->
Fixes #

#### Special notes for your reviewer:

#### Does this PR introduce a user-facing change?
<!--
If no, just write "NONE" in the release-note block below.
If yes, a release note is required:
Enter your extended release note in the block below. If the PR requires additional action from users switching to the new release, include the string "action required".

For more information on release notes see: https://git.k8s.io/community/contributors/guide/release-notes.md
-->
```release-note
fix: disable match tags by default in account search when creating file share
```

#### Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:

<!--
This section can be blank if this pull request does not require a release note.

When adding links which point to resources within git repositories, like
KEPs or supporting documentation, please reference a specific commit and avoid
linking directly to the master branch. This ensures that links reference a
specific point in time, rather than a document that may change over time.

See here for guidance on getting permanent links to files: https://help.github.com/en/articles/getting-permanent-links-to-files

Please use the following format for linking documentation:
- [KEP]: <link>
- [Usage]: <link>
- [Other doc]: <link>
-->
```docs
fix: disable match tags by default in account search when creating file share
```



Patch:
diff --git a/pkg/provider/azure_storageaccount.go b/pkg/provider/azure_storageaccount.go
index 3b8e9024f..278567821 100644
--- a/pkg/provider/azure_storageaccount.go
+++ b/pkg/provider/azure_storageaccount.go
@@ -57,6 +57,7 @@ type AccountOptions struct {
 	VNetResourceGroup                       string
 	VNetName                                string
 	SubnetName                              string
+	MatchTags                               bool
 }
 
 type accountWithLocation struct {
@@ -510,6 +511,11 @@ func isTaggedWithSkip(account storage.Account) bool {
 }
 
 func isTagsEqual(account storage.Account, accountOptions *AccountOptions) bool {
+	if !accountOptions.MatchTags {
+		// always return true when tags matching is false (by default)
+		return true
+	}
+
 	// nil and empty map should be regarded as equal
 	if len(account.Tags) == 0 && len(accountOptions.Tags) == 0 {
 		return true


Test patch:
diff --git a/pkg/provider/azure_storageaccount_test.go b/pkg/provider/azure_storageaccount_test.go
index ac8fe8a57..d844548c6 100644
--- a/pkg/provider/azure_storageaccount_test.go
+++ b/pkg/provider/azure_storageaccount_test.go
@@ -593,6 +593,21 @@ func TestIsTagsEqual(t *testing.T) {
 			},
 			expectedResult: true,
 		},
+		{
+			desc: "non-identitical tags while MatchTags is false",
+			account: storage.Account{
+				Tags: map[string]*string{
+					"key": to.StringPtr("value2"),
+				},
+			},
+			accountOptions: &AccountOptions{
+				MatchTags: false,
+				Tags: map[string]string{
+					"key": "value",
+				},
+			},
+			expectedResult: true,
+		},
 		{
 			desc: "non-identitical tags",
 			account: storage.Account{
@@ -601,6 +616,7 @@ func TestIsTagsEqual(t *testing.T) {
 				},
 			},
 			accountOptions: &AccountOptions{
+				MatchTags: true,
 				Tags: map[string]string{
 					"key": "value",
 				},