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

chore: AddStorageAccountTags refine #5535

Merged
merged 1 commit into from
Feb 28, 2024
Merged
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
17 changes: 8 additions & 9 deletions pkg/provider/azure_storageaccount.go
Original file line number Diff line number Diff line change
Expand Up @@ -717,22 +717,20 @@ func (az *Cloud) AddStorageAccountTags(ctx context.Context, subsID, resourceGrou
return rerr
}

originalLen := len(result.Tags)
newTags := result.Tags
if newTags == nil {
newTags = make(map[string]*string)
}

// merge two tag map
// merge two tag map into one
newTags := make(map[string]*string)
for k, v := range tags {
newTags[k] = v
}
for k, v := range result.Tags {
newTags[k] = v
}

if len(newTags) > originalLen {
if len(newTags) > len(result.Tags) {
// only update when newTags is different from old tags
_ = az.storageAccountCache.Delete(account) // clean cache
updateParams := storage.AccountUpdateParameters{Tags: newTags}
klog.V(2).Infof("update storage account(%s) with tags(%+v)", account, newTags)
klog.V(2).Infof("add storage account(%s) with tags(%+v)", account, newTags)
return az.StorageAccountClient.Update(ctx, subsID, resourceGroup, account, updateParams)
}
return nil
Expand All @@ -759,6 +757,7 @@ func (az *Cloud) RemoveStorageAccountTag(ctx context.Context, subsID, resourceGr
// only update when newTags is different from old tags
_ = az.storageAccountCache.Delete(account) // clean cache
updateParams := storage.AccountUpdateParameters{Tags: result.Tags}
klog.V(2).Infof("remove tag(%s) from storage account(%s)", key, account)
return az.StorageAccountClient.Update(ctx, subsID, resourceGroup, account, updateParams)
}
return nil
Expand Down
Loading