Skip to content

Commit

Permalink
Optimise updateBucketCR
Browse files Browse the repository at this point in the history
  • Loading branch information
nolancon committed Dec 17, 2024
1 parent 227d64e commit 01818a4
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions internal/controller/bucket/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,14 +241,25 @@ func (c *external) updateBucketCR(ctx context.Context, bucket *v1alpha1.Bucket,
ctx, span := otel.Tracer("").Start(ctx, "bucket.external.updateBucketCR")
defer span.End()

bucketDeepCopy := &v1alpha1.Bucket{}
nn := types.NamespacedName{Name: bucket.GetName()}
err := retry.OnError(retry.DefaultRetry, resource.IsAPIError, func() error {
if err := c.kubeClient.Get(ctx, nn, bucket); err != nil {
return err
}
bucketDeepCopy = bucket.DeepCopy()
return nil

Check failure on line 251 in internal/controller/bucket/helpers.go

View workflow job for this annotation

GitHub Actions / lint

return with no blank line before (nlreturn)
})
if err != nil {
if kerrors.IsNotFound(err) {
c.log.Info("Bucket doesn't exists", consts.KeyBucketName, bucket.Name)

return nil
}
}

for _, cb := range callbacks {
err := retry.OnError(retry.DefaultRetry, resource.IsAPIError, func() error {
if err := c.kubeClient.Get(ctx, nn, bucket); err != nil {
return err
}
bucketDeepCopy := bucket.DeepCopy()
if err := retry.OnError(retry.DefaultRetry, resource.IsAPIError, func() error {
switch cb(bucket) {
case NeedsStatusUpdate:
return c.kubeClient.Status().Patch(ctx, bucket, client.MergeFrom(bucketDeepCopy))
Expand All @@ -257,15 +268,7 @@ func (c *external) updateBucketCR(ctx context.Context, bucket *v1alpha1.Bucket,
default:
return nil
}
})

if err != nil {
if kerrors.IsNotFound(err) {
c.log.Info("Bucket doesn't exists", consts.KeyBucketName, bucket.Name)

break
}

}); err != nil {
return errors.Wrap(err, "unable to update object")
}
}
Expand Down

0 comments on commit 01818a4

Please sign in to comment.