Skip to content

Commit

Permalink
Use Patch instead of Update
Browse files Browse the repository at this point in the history
  • Loading branch information
nolancon committed Dec 16, 2024
1 parent 1397dd4 commit 4b68ad4
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions internal/controller/bucket/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/linode/provider-ceph/internal/consts"
"github.com/linode/provider-ceph/internal/utils"
"go.opentelemetry.io/otel"
"sigs.k8s.io/controller-runtime/pkg/client"

kerrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/types"
Expand Down Expand Up @@ -273,12 +274,13 @@ func (c *external) updateBucketCR(ctx context.Context, bucket *v1alpha1.Bucket,
if err := c.kubeClient.Get(ctx, nn, bucket); err != nil {
return err
}

switch cb(bucketDeepCopy, bucket) {
newCopy := bucket.DeepCopy()
updateRequired := cb(bucketDeepCopy, bucket)
switch updateRequired {
case NeedsStatusUpdate:
return c.kubeClient.Status().Update(ctx, bucket)
return c.kubeClient.Status().Patch(ctx, bucket, client.MergeFrom(newCopy))
case NeedsObjectUpdate:
return c.kubeClient.Update(ctx, bucket)
return c.kubeClient.Patch(ctx, bucket, client.MergeFrom(newCopy))
default:
return nil
}
Expand Down

0 comments on commit 4b68ad4

Please sign in to comment.