@@ -20,10 +20,10 @@ import (
2020 "fmt"
2121 "hash/fnv"
2222 "maps"
23- "reflect"
2423 "time"
2524
2625 corev1 "k8s.io/api/core/v1"
26+ "k8s.io/apimachinery/pkg/api/equality"
2727 k8serrors "k8s.io/apimachinery/pkg/api/errors"
2828 "k8s.io/apimachinery/pkg/api/meta"
2929 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -308,18 +308,24 @@ func podIPsFromStatus(podIPs []corev1.PodIP) []string {
308308}
309309
310310func (r * SandboxReconciler ) updateStatus (ctx context.Context , oldStatus * sandboxv1alpha1.SandboxStatus , sandbox * sandboxv1alpha1.Sandbox ) error {
311- log := log .FromContext (ctx )
311+ logger := log .FromContext (ctx )
312312
313- if reflect .DeepEqual (oldStatus , & sandbox .Status ) {
313+ if equality . Semantic .DeepEqual (oldStatus , & sandbox .Status ) {
314314 return nil
315315 }
316316
317- if err := r .Status ().Update (ctx , sandbox ); err != nil {
318- log .Error (err , "Failed to update sandbox status" )
317+ oldSandbox := sandbox .DeepCopy ()
318+ oldSandbox .Status = * oldStatus
319+
320+ sandbox .SetGroupVersionKind (sandboxv1alpha1 .GroupVersion .WithKind ("Sandbox" ))
321+
322+ patch := client .MergeFrom (oldSandbox )
323+
324+ if err := r .Status ().Patch (ctx , sandbox , patch ); err != nil {
325+ logger .Error (err , "Failed to patch sandbox status" )
319326 return err
320327 }
321328
322- // Surface error
323329 return nil
324330}
325331
0 commit comments