4
4
"context"
5
5
"encoding/json"
6
6
"fmt"
7
+ "strings"
7
8
8
9
"github.com/google/go-cmp/cmp"
9
10
"go.uber.org/zap"
@@ -176,7 +177,8 @@ func (skp *SkipperRouter) SetRoutes(canary *flaggerv1.Canary, primaryWeight, can
176
177
177
178
// Disable the canary-ingress route after the canary process
178
179
if canaryWeight == 0 {
179
- iClone .Annotations [skipperpredicateAnnotationKey ] = canaryRouteDisable
180
+ // ensuring False() is at first place
181
+ iClone .Annotations [skipperpredicateAnnotationKey ] = insertPredicate (iClone .Annotations [skipperpredicateAnnotationKey ], canaryRouteDisable )
180
182
}
181
183
182
184
_ , err = skp .kubeClient .NetworkingV1beta1 ().Ingresses (canary .Namespace ).Update (
@@ -212,7 +214,7 @@ func (skp *SkipperRouter) makeAnnotations(annotations map[string]string, backend
212
214
}
213
215
annotations [skipperBackendWeightsAnnotationKey ] = string (b )
214
216
// adding more weight to canary route solves traffic bypassing through apexIngress
215
- annotations [skipperpredicateAnnotationKey ] = canaryRouteWeight
217
+ annotations [skipperpredicateAnnotationKey ] = insertPredicate ( annotations [ skipperpredicateAnnotationKey ], canaryRouteWeight )
216
218
217
219
return annotations
218
220
}
@@ -233,3 +235,19 @@ func (skp *SkipperRouter) backendWeights(annotation map[string]string) (backendW
233
235
func (skp * SkipperRouter ) getIngressNames (name string ) (apexName , canaryName string ) {
234
236
return name , fmt .Sprintf (canaryPatternf , name )
235
237
}
238
+
239
+ func insertPredicate (raw , insert string ) string {
240
+ // ensuring it at first place
241
+ predicates := []string {insert }
242
+ for _ , x := range strings .Split (raw , "&&" ) {
243
+ predicate := strings .TrimSpace (x )
244
+ // dropping conflicting predicates
245
+ if predicate == "" ||
246
+ predicate == canaryRouteWeight ||
247
+ predicate == canaryRouteDisable {
248
+ continue
249
+ }
250
+ predicates = append (predicates , predicate )
251
+ }
252
+ return strings .Join (predicates , " && " )
253
+ }
0 commit comments