Skip to content

Commit e153b8a

Browse files
fix(gloo): Update reconciler to detect change in gloo upstream spec
Signed-off-by: sopida-chotwanwirach <[email protected]>
1 parent 9a0f010 commit e153b8a

File tree

2 files changed

+73
-1
lines changed

2 files changed

+73
-1
lines changed

pkg/router/gloo.go

+32-1
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,8 @@ func (gr *GlooRouter) createFlaggerUpstream(canary *flaggerv1.Canary, upstreamNa
275275
if err != nil {
276276
return fmt.Errorf("service %s.%s get query error: %w", svcName, canary.Namespace, err)
277277
}
278-
_, err = upstreamClient.Get(context.TODO(), upstreamName, metav1.GetOptions{})
278+
curUpstream, err := upstreamClient.Get(context.TODO(), upstreamName, metav1.GetOptions{})
279+
279280
if errors.IsNotFound(err) {
280281
glooUpstreamWithConfig, err := gr.getGlooConfigUpstream(canary)
281282
if err != nil {
@@ -288,7 +289,37 @@ func (gr *GlooRouter) createFlaggerUpstream(canary *flaggerv1.Canary, upstreamNa
288289
}
289290
} else if err != nil {
290291
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
291306
}
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+
292323
return nil
293324
}
294325

test/gloo/test-canary.sh

+41
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,47 @@ done
117117

118118
echo '✔ Canary initialization test passed'
119119

120+
echo '>>> Waiting for primary spec to be updated'
121+
122+
# Update gloo upstream on slow start config which will trigger update on flagger upstreams
123+
cat <<EOF | kubectl apply -f -
124+
apiVersion: gloo.solo.io/v1
125+
kind: Upstream
126+
metadata:
127+
name: config-upstream
128+
namespace: gloo-system
129+
spec:
130+
static:
131+
hosts:
132+
- addr: "example.com"
133+
port: 80
134+
connectionConfig:
135+
connectTimeout: 2s
136+
maxRequestsPerConnection: 51
137+
loadBalancerConfig:
138+
roundRobin:
139+
slowStartConfig:
140+
slowStartWindow: 2m
141+
minWeightPercent: 20
142+
EOF
143+
144+
retries=50
145+
count=0
146+
ok=false
147+
until ${ok}; do
148+
kubectl -n test get upstream/test-podinfo-canaryupstream-80 -ojson | jq '.spec.loadBalancerConfig.roundRobin.slowStartConfig.minWeightPercent' | grep '20' && ok=true || ok=false
149+
150+
sleep 5
151+
count=$(($count + 1))
152+
if [[ ${count} -eq ${retries} ]]; then
153+
kubectl -n gloo-system logs deployment/flagger
154+
echo "No more retries left"
155+
exit 1
156+
fi
157+
done
158+
159+
echo '✔ Canary reconcilation test passed'
160+
120161
echo '>>> Triggering canary deployment'
121162
kubectl -n test set image deployment/podinfo podinfod=ghcr.io/stefanprodan/podinfo:6.0.1
122163

0 commit comments

Comments
 (0)