@@ -157,16 +157,16 @@ func (c *AWSTagController) Run(ctx context.Context) {
157
157
defer k8sruntime .HandleCrash ()
158
158
defer c .queue .ShutDown ()
159
159
160
- klog .Infof ("Starting AWS Controller" )
160
+ klog .Infof ("Starting AWS Tag Controller" )
161
161
if ! cache .WaitForCacheSync (ctx .Done (), c .cachesToSync ... ) {
162
162
return
163
163
}
164
164
165
165
go wait .Until (c .runWorker , time .Second , ctx .Done ())
166
166
167
- klog .Infof ("Started AWS Controller" )
167
+ klog .Infof ("Started AWS Tag Controller" )
168
168
<- ctx .Done ()
169
- klog .Infof ("Shutting down AWS Controller" )
169
+ klog .Infof ("Shutting down AWS Tag Controller" )
170
170
}
171
171
172
172
func (c * AWSTagController ) runWorker () {
@@ -183,13 +183,13 @@ func (c *AWSTagController) processNextWorkItem() bool {
183
183
}
184
184
defer c .queue .Done (obj )
185
185
186
- klog .V (5 ).Infof ("AWSController : got event from workqueue" )
186
+ klog .V (5 ).Infof ("AWSTagController : got event from workqueue" )
187
187
if err := c .sync (); err != nil {
188
188
c .queue .AddRateLimited (workqueueKey )
189
- klog .Errorf ("AWSController : failed to process event: %s, requeuing" , err )
189
+ klog .Errorf ("AWSTagController : failed to process event: %s, requeuing" , err )
190
190
} else {
191
191
c .queue .Forget (obj )
192
- klog .V (5 ).Infof ("AWSController : event from workqueue successfully processed" )
192
+ klog .V (5 ).Infof ("AWSTagController : event from workqueue successfully processed" )
193
193
}
194
194
return true
195
195
}
@@ -234,10 +234,8 @@ func (c *AWSTagController) syncTags() error {
234
234
return err
235
235
}
236
236
237
- // tags deletion is not supported. Should the user remove it from
238
- // PlatformStatus will be looked up for retaining the tag
239
- infraTagSet := make (map [string ]string )
240
- mergePlatformStatusTags (infra , infraTagSet )
237
+ // Filtering tags based on validation
238
+ infraTagSet := filterPlatformStatusTags (infra )
241
239
klog .V (5 ).Infof ("tags read from Infrastructure resource: %v" , infraTagSet )
242
240
243
241
// Create a driver with the current configuration
@@ -249,58 +247,50 @@ func (c *AWSTagController) syncTags() error {
249
247
klog .Errorf ("failed to fetch storage tags: %v" , err )
250
248
return err
251
249
}
252
- klog .V ( 5 ). Infof ("tags read from storage resource: %v" , s3TagSet )
250
+ klog .Infof ("tags read from storage resource: %v" , s3TagSet )
253
251
254
- tagUpdatedCount := compareS3InfraTagSet (s3TagSet , infraTagSet )
252
+ tagUpdatedCount := syncInfraTags (s3TagSet , infraTagSet )
255
253
if tagUpdatedCount > 0 {
256
254
if err := driver .PutStorageTags (s3TagSet ); err != nil {
257
- klog .Errorf ("failed to update/delete tagset of %s s3 bucket: %v" , driver .ID (), err )
255
+ klog .Errorf ("failed to update/append tagset of %s s3 bucket: %v" , driver .ID (), err )
258
256
c .event .Warningf ("UpdateAWSTags" ,
259
- "Failed to update/delete tagset of %s s3 bucket" , driver .ID ())
257
+ "Failed to update/append tagset of %s s3 bucket" , driver .ID ())
260
258
}
261
- klog .Infof ("successfully updated/deleted %d tags, tagset: %+v" , tagUpdatedCount , s3TagSet )
259
+ klog .Infof ("successfully updated/appended %d tags, tagset: %+v" , tagUpdatedCount , s3TagSet )
262
260
c .event .Eventf ("UpdateAWSTags" ,
263
- "Successfully updated/deleted tagset of %s s3 bucket" , driver .ID ())
261
+ "Successfully updated tagset of %s s3 bucket" , driver .ID ())
264
262
}
265
263
266
264
return nil
267
265
}
268
266
269
- // mergePlatformStatusTags is for reading and merging user tags present in both
267
+ // filterPlatformStatusTags is for reading and filter user tags present in
270
268
// Platform Status of Infrastructure config.
271
- // There could be scenarios(upgrade, user deletes) where user tags could be missing
272
- // from the Platform Status, hence using Status too to avoid said scenarios.
273
- // If a tag exists in Status.
274
- func mergePlatformStatusTags (infra * configv1.Infrastructure , infraTagSet map [string ]string ) {
269
+ func filterPlatformStatusTags (infra * configv1.Infrastructure ) map [string ]string {
270
+ infraTagSet := map [string ]string {}
275
271
for _ , statusTags := range infra .Status .PlatformStatus .AWS .ResourceTags {
276
272
if err := validateUserTag (statusTags .Key , statusTags .Value ); err != nil {
277
273
klog .Warningf ("validation failed for tag(%s:%s): %v" , statusTags .Key , statusTags .Value , err )
278
274
continue
279
275
}
280
276
infraTagSet [statusTags .Key ] = statusTags .Value
281
277
}
278
+ return infraTagSet
282
279
}
283
280
284
- // compareS3InfraTagSet is for comparing the tags obtained from S3 bucket and Infrastructure CR
285
- // to find if any new tags have been deleted, added or existing tags modified.
286
- func compareS3InfraTagSet (s3TagSet map [string ]string , infraTagSet map [string ]string ) (tagUpdatedCount int ) {
281
+ // syncInfraTags synchronizes the tags obtained from S3 bucket and Infrastructure CR.
282
+ // this modifies the s3TagSet based on new tags which are added and update the value to a key if it has changed.
283
+ func syncInfraTags (s3TagSet map [string ]string , infraTagSet map [string ]string ) int {
284
+ tagUpdatedCount := 0
287
285
for key , value := range infraTagSet {
288
- // If a tag is value is empty, it's marked for deletion
289
- // and is deleted from the list obtained from S3 bucket
290
- if value == "" {
291
- klog .V (5 ).Infof ("%s tag will be deleted" , key )
292
- delete (s3TagSet , key )
293
- tagUpdatedCount ++
294
- continue
295
- }
296
286
val , ok := s3TagSet [key ]
297
287
if ! ok || val != value {
298
288
klog .V (5 ).Infof ("%s tag will be added/updated with value %s" , key , value )
299
289
s3TagSet [key ] = value
300
290
tagUpdatedCount ++
301
291
}
302
292
}
303
- return
293
+ return tagUpdatedCount
304
294
}
305
295
306
296
// validateUserTag is for validating the user defined tags in Infrastructure CR
0 commit comments