44 "context"
55 "encoding/json"
66 "fmt"
7+ "strings"
78
89 "github.com/google/go-cmp/cmp"
910 "go.uber.org/zap"
@@ -176,7 +177,8 @@ func (skp *SkipperRouter) SetRoutes(canary *flaggerv1.Canary, primaryWeight, can
176177
177178 // Disable the canary-ingress route after the canary process
178179 if canaryWeight == 0 {
179- iClone .Annotations [skipperpredicateAnnotationKey ] = canaryRouteDisable
180+ // ensuring False() is at first place
181+ iClone .Annotations [skipperpredicateAnnotationKey ] = insertPredicate (iClone .Annotations [skipperpredicateAnnotationKey ], canaryRouteDisable )
180182 }
181183
182184 _ , err = skp .kubeClient .NetworkingV1beta1 ().Ingresses (canary .Namespace ).Update (
@@ -212,7 +214,7 @@ func (skp *SkipperRouter) makeAnnotations(annotations map[string]string, backend
212214 }
213215 annotations [skipperBackendWeightsAnnotationKey ] = string (b )
214216 // adding more weight to canary route solves traffic bypassing through apexIngress
215- annotations [skipperpredicateAnnotationKey ] = canaryRouteWeight
217+ annotations [skipperpredicateAnnotationKey ] = insertPredicate ( annotations [ skipperpredicateAnnotationKey ], canaryRouteWeight )
216218
217219 return annotations
218220}
@@ -233,3 +235,19 @@ func (skp *SkipperRouter) backendWeights(annotation map[string]string) (backendW
233235func (skp * SkipperRouter ) getIngressNames (name string ) (apexName , canaryName string ) {
234236 return name , fmt .Sprintf (canaryPatternf , name )
235237}
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