Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release-1.29] fix: match tags issue in account search #5480

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 7 additions & 8 deletions pkg/provider/azure_storageaccount.go
Original file line number Diff line number Diff line change
Expand Up @@ -840,17 +840,16 @@ func isTagsEqual(account storage.Account, accountOptions *AccountOptions) bool {
return true
}

for k, v := range account.Tags {
var value string
// nil and empty value should be regarded as equal
if v != nil {
value = *v
}
if accountOptions.Tags[k] != value {
if len(account.Tags) < len(accountOptions.Tags) {
return false
}

// ensure all tags in accountOptions are in account
for k, v := range accountOptions.Tags {
if pointer.StringDeref(account.Tags[k], "") != v {
return false
}
}

return true
}

Expand Down
28 changes: 28 additions & 0 deletions pkg/provider/azure_storageaccount_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -917,6 +917,34 @@ func TestIsTagsEqual(t *testing.T) {
},
expectedResult: false,
},
{
desc: "non-identitical tags with different keys",
account: storage.Account{
Tags: map[string]*string{
"key1": pointer.String("value2"),
},
},
accountOptions: &AccountOptions{
MatchTags: true,
Tags: map[string]string{
"key2": "value",
},
},
expectedResult: false,
},
{
desc: "account tags is empty",
account: storage.Account{
Tags: map[string]*string{},
},
accountOptions: &AccountOptions{
MatchTags: true,
Tags: map[string]string{
"key": "value",
},
},
expectedResult: false,
},
}

for _, test := range tests {
Expand Down