@@ -275,7 +275,8 @@ func (gr *GlooRouter) createFlaggerUpstream(canary *flaggerv1.Canary, upstreamNa
275
275
if err != nil {
276
276
return fmt .Errorf ("service %s.%s get query error: %w" , svcName , canary .Namespace , err )
277
277
}
278
- _ , err = upstreamClient .Get (context .TODO (), upstreamName , metav1.GetOptions {})
278
+ curUpstream , err := upstreamClient .Get (context .TODO (), upstreamName , metav1.GetOptions {})
279
+
279
280
if errors .IsNotFound (err ) {
280
281
glooUpstreamWithConfig , err := gr .getGlooConfigUpstream (canary )
281
282
if err != nil {
@@ -288,7 +289,37 @@ func (gr *GlooRouter) createFlaggerUpstream(canary *flaggerv1.Canary, upstreamNa
288
289
}
289
290
} else if err != nil {
290
291
return fmt .Errorf ("upstream %s.%s get query error: %w" , upstreamName , canary .Namespace , err )
292
+ } else {
293
+ return gr .syncUpstreamSpec (curUpstream , canary )
294
+ }
295
+ return nil
296
+ }
297
+
298
+ func (gr * GlooRouter ) syncUpstreamSpec (curUpstream * gloov1.Upstream , canary * flaggerv1.Canary ) error {
299
+ glooUpstreamWithConfig , err := gr .getGlooConfigUpstream (canary )
300
+ if err != nil {
301
+ return err
302
+ }
303
+
304
+ if glooUpstreamWithConfig == nil {
305
+ return nil
291
306
}
307
+
308
+ glooUpstreamLB := glooUpstreamWithConfig .Spec .LoadBalancerConfig
309
+ loadBalancerDiff := cmp .Diff (glooUpstreamLB , curUpstream .Spec .LoadBalancerConfig )
310
+
311
+ if loadBalancerDiff != "" {
312
+ gr .logger .Debugf ("detect diff in upstream spec %s.%s %s" , curUpstream .Name , canary .Namespace , loadBalancerDiff )
313
+
314
+ cloneUpstream := curUpstream .DeepCopy ()
315
+ cloneUpstream .Spec .LoadBalancerConfig = glooUpstreamLB
316
+
317
+ _ , err = gr .glooClient .GlooV1 ().Upstreams (canary .Namespace ).Update (context .TODO (), cloneUpstream , metav1.UpdateOptions {})
318
+ if err != nil {
319
+ return fmt .Errorf ("upstream %s.%s spec update error: %w" , curUpstream .Name , canary .Namespace , err )
320
+ }
321
+ }
322
+
292
323
return nil
293
324
}
294
325
0 commit comments