@@ -18,6 +18,7 @@ package router
18
18
19
19
import (
20
20
"context"
21
+ "encoding/json"
21
22
"fmt"
22
23
23
24
corev1 "k8s.io/api/core/v1"
@@ -30,6 +31,7 @@ import (
30
31
"k8s.io/apimachinery/pkg/api/errors"
31
32
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
32
33
"k8s.io/apimachinery/pkg/runtime/schema"
34
+ types "k8s.io/apimachinery/pkg/types"
33
35
"k8s.io/client-go/kubernetes"
34
36
35
37
flaggerv1 "github.com/fluxcd/flagger/pkg/apis/flagger/v1beta1"
@@ -311,12 +313,17 @@ func (gr *GlooRouter) syncUpstreamSpec(curUpstream *gloov1.Upstream, canary *fla
311
313
if loadBalancerDiff != "" {
312
314
gr .logger .Debugf ("detect diff in upstream spec %s.%s %s" , curUpstream .Name , canary .Namespace , loadBalancerDiff )
313
315
314
- cloneUpstream := curUpstream .DeepCopy ()
315
- cloneUpstream .Spec .LoadBalancerConfig = glooUpstreamLB
316
+ patchUpstream := gloov1.Upstream {}
317
+ patchUpstream .Spec = gloov1.UpstreamSpec {}
318
+ patchUpstream .Spec .LoadBalancerConfig = glooUpstreamLB
319
+ patchBytes , err := json .Marshal (patchUpstream )
320
+ if err != nil {
321
+ return fmt .Errorf ("unable to marshal patch upstream from %s.%s with error: %w" , glooUpstreamWithConfig .Name , glooUpstreamWithConfig .Namespace , err )
322
+ }
316
323
317
- _ , err = gr .glooClient .GlooV1 ().Upstreams (canary .Namespace ).Update (context .TODO (), cloneUpstream , metav1.UpdateOptions {})
324
+ _ , err = gr .glooClient .GlooV1 ().Upstreams (canary .Namespace ).Patch (context .TODO (), curUpstream . Name , types . MergePatchType , patchBytes , metav1.PatchOptions {})
318
325
if err != nil {
319
- return fmt .Errorf ("upstream %s.%s spec update error: %w" , curUpstream .Name , canary .Namespace , err )
326
+ return fmt .Errorf ("upstream %s.%s spec patch error: %w" , curUpstream .Name , canary .Namespace , err )
320
327
}
321
328
}
322
329
0 commit comments