Skip to content

Commit e3a529e

Browse files
switch to use patch
Signed-off-by: sopida-chotwanwirach <[email protected]>
1 parent e153b8a commit e3a529e

File tree

2 files changed

+12
-24
lines changed

2 files changed

+12
-24
lines changed

pkg/router/gloo.go

+11-4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package router
1818

1919
import (
2020
"context"
21+
"encoding/json"
2122
"fmt"
2223

2324
corev1 "k8s.io/api/core/v1"
@@ -30,6 +31,7 @@ import (
3031
"k8s.io/apimachinery/pkg/api/errors"
3132
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3233
"k8s.io/apimachinery/pkg/runtime/schema"
34+
types "k8s.io/apimachinery/pkg/types"
3335
"k8s.io/client-go/kubernetes"
3436

3537
flaggerv1 "github.com/fluxcd/flagger/pkg/apis/flagger/v1beta1"
@@ -311,12 +313,17 @@ func (gr *GlooRouter) syncUpstreamSpec(curUpstream *gloov1.Upstream, canary *fla
311313
if loadBalancerDiff != "" {
312314
gr.logger.Debugf("detect diff in upstream spec %s.%s %s", curUpstream.Name, canary.Namespace, loadBalancerDiff)
313315

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+
}
316323

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{})
318325
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)
320327
}
321328
}
322329

test/gloo/test-canary.sh

+1-20
Original file line numberDiff line numberDiff line change
@@ -120,26 +120,7 @@ echo '✔ Canary initialization test passed'
120120
echo '>>> Waiting for primary spec to be updated'
121121

122122
# 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
123+
kubectl -n gloo-system patch upstream config-upstream --type json --patch='[ { "op": "replace", "path": "/spec/loadBalancerConfig/roundRobin/slowStartConfig/minWeightPercent", "value": 20 } ]'
143124

144125
retries=50
145126
count=0

0 commit comments

Comments
 (0)