Skip to content

Commit 0e627e9

Browse files
fixed review comments
1 parent 8ef80a5 commit 0e627e9

File tree

2 files changed

+23
-56
lines changed

2 files changed

+23
-56
lines changed

pkg/operator/awsTagController.go renamed to pkg/operator/awstagcontroller.go

Lines changed: 23 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -157,16 +157,16 @@ func (c *AWSTagController) Run(ctx context.Context) {
157157
defer k8sruntime.HandleCrash()
158158
defer c.queue.ShutDown()
159159

160-
klog.Infof("Starting AWS Controller")
160+
klog.Infof("Starting AWS Tag Controller")
161161
if !cache.WaitForCacheSync(ctx.Done(), c.cachesToSync...) {
162162
return
163163
}
164164

165165
go wait.Until(c.runWorker, time.Second, ctx.Done())
166166

167-
klog.Infof("Started AWS Controller")
167+
klog.Infof("Started AWS Tag Controller")
168168
<-ctx.Done()
169-
klog.Infof("Shutting down AWS Controller")
169+
klog.Infof("Shutting down AWS Tag Controller")
170170
}
171171

172172
func (c *AWSTagController) runWorker() {
@@ -183,13 +183,13 @@ func (c *AWSTagController) processNextWorkItem() bool {
183183
}
184184
defer c.queue.Done(obj)
185185

186-
klog.V(5).Infof("AWSController: got event from workqueue")
186+
klog.V(5).Infof("AWSTagController: got event from workqueue")
187187
if err := c.sync(); err != nil {
188188
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)
190190
} else {
191191
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")
193193
}
194194
return true
195195
}
@@ -234,10 +234,8 @@ func (c *AWSTagController) syncTags() error {
234234
return err
235235
}
236236

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)
241239
klog.V(5).Infof("tags read from Infrastructure resource: %v", infraTagSet)
242240

243241
// Create a driver with the current configuration
@@ -249,58 +247,50 @@ func (c *AWSTagController) syncTags() error {
249247
klog.Errorf("failed to fetch storage tags: %v", err)
250248
return err
251249
}
252-
klog.V(5).Infof("tags read from storage resource: %v", s3TagSet)
250+
klog.Infof("tags read from storage resource: %v", s3TagSet)
253251

254-
tagUpdatedCount := compareS3InfraTagSet(s3TagSet, infraTagSet)
252+
tagUpdatedCount := syncInfraTags(s3TagSet, infraTagSet)
255253
if tagUpdatedCount > 0 {
256254
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)
258256
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())
260258
}
261-
klog.Infof("successfully updated/deleted %d tags, tagset: %+v", tagUpdatedCount, s3TagSet)
259+
klog.Infof("successfully updated/appended %d tags, tagset: %+v", tagUpdatedCount, s3TagSet)
262260
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())
264262
}
265263

266264
return nil
267265
}
268266

269-
// mergePlatformStatusTags is for reading and merging user tags present in both
267+
// filterPlatformStatusTags is for reading and filter user tags present in
270268
// 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{}
275271
for _, statusTags := range infra.Status.PlatformStatus.AWS.ResourceTags {
276272
if err := validateUserTag(statusTags.Key, statusTags.Value); err != nil {
277273
klog.Warningf("validation failed for tag(%s:%s): %v", statusTags.Key, statusTags.Value, err)
278274
continue
279275
}
280276
infraTagSet[statusTags.Key] = statusTags.Value
281277
}
278+
return infraTagSet
282279
}
283280

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
287285
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-
}
296286
val, ok := s3TagSet[key]
297287
if !ok || val != value {
298288
klog.V(5).Infof("%s tag will be added/updated with value %s", key, value)
299289
s3TagSet[key] = value
300290
tagUpdatedCount++
301291
}
302292
}
303-
return
293+
return tagUpdatedCount
304294
}
305295

306296
// validateUserTag is for validating the user defined tags in Infrastructure CR

pkg/operator/starter.go

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -256,29 +256,6 @@ func RunOperator(ctx context.Context, kubeconfig *restclient.Config) error {
256256
go awsTagController.Run(ctx)
257257
go metricsController.Run(ctx)
258258

259-
//// Fetch on Infrastructure resource is trivial and failure to fetch
260-
//// shouldn't be a reason to shutdown operator. Starting an unnecessary
261-
//// routine can be avoided if fetch is successful.
262-
//var platformType configv1.PlatformType
263-
//infra, err := configClient.ConfigV1().Infrastructures().Get(
264-
// context.Background(),
265-
// defaults.InfrastructureResourceName,
266-
// metav1.GetOptions{},
267-
//)
268-
//if err != nil {
269-
// klog.Errorf("failed to fetch Infrastructure resource: %v", err)
270-
//}
271-
//if infra != nil {
272-
// platformType = infra.Status.PlatformStatus.Type
273-
//}
274-
//if platformType == configv1.AzurePlatformType || platformType == "" {
275-
// go azureStackCloudController.Run(ctx)
276-
// go azurePathFixController.Run(ctx.Done())
277-
//}
278-
//if platformType == configv1.AWSPlatformType || platformType == "" {
279-
// go awsController.Run(ctx)
280-
//}
281-
282259
<-ctx.Done()
283260
return nil
284261
}

0 commit comments

Comments
 (0)