@@ -39,24 +39,38 @@ func canaryFeature(ingresses []networkingv1.Ingress, gatewayResources *i2gw.Gate
39
39
return errs
40
40
}
41
41
42
+ // We're dividing ingresses based on rule groups. If any path within a
43
+ // rule group is associated with an ingress object containing canary annotations,
44
+ // the entire rule group is affected.
45
+ canaryEnabled := false
42
46
for _ , paths := range ingressPathsByMatchKey {
43
- path := paths [0 ]
47
+ for _ , path := range paths {
48
+ if path .extra .canary .enable {
49
+ canaryEnabled = true
50
+ }
51
+ }
52
+ }
44
53
45
- backendRefs , calculationErrs := calculateBackendRefWeight (paths )
46
- errs = append (errs , calculationErrs ... )
54
+ if canaryEnabled {
55
+ for _ , paths := range ingressPathsByMatchKey {
56
+ path := paths [0 ]
47
57
48
- key := types.NamespacedName {Namespace : path .ingress .Namespace , Name : common .RouteName (rg .Name , rg .Host )}
49
- httpRoute , ok := gatewayResources .HTTPRoutes [key ]
50
- if ! ok {
51
- // If there wasn't an HTTPRoute for this Ingress, we can skip it as something is wrong.
52
- // All the available errors will be returned at the end.
53
- continue
54
- }
58
+ backendRefs , calculationErrs := calculateBackendRefWeight (paths )
59
+ errs = append (errs , calculationErrs ... )
55
60
56
- patchHTTPRouteWithBackendRefs (& httpRoute , backendRefs )
57
- }
58
- if len (errs ) > 0 {
59
- return errs
61
+ key := types.NamespacedName {Namespace : path .ingress .Namespace , Name : common .RouteName (rg .Name , rg .Host )}
62
+ httpRoute , ok := gatewayResources .HTTPRoutes [key ]
63
+ if ! ok {
64
+ // If there wasn't an HTTPRoute for this Ingress, we can skip it as something is wrong.
65
+ // All the available errors will be returned at the end.
66
+ continue
67
+ }
68
+
69
+ patchHTTPRouteWithBackendRefs (& httpRoute , backendRefs )
70
+ }
71
+ if len (errs ) > 0 {
72
+ return errs
73
+ }
60
74
}
61
75
}
62
76
@@ -92,20 +106,14 @@ func patchHTTPRouteWithBackendRefs(httpRoute *gatewayv1.HTTPRoute, backendRefs [
92
106
93
107
ruleExists = false
94
108
95
- for j , rule := range httpRoute .Spec .Rules {
96
- foundBackendRef := false
109
+ for _ , rule := range httpRoute .Spec .Rules {
97
110
for i := range rule .BackendRefs {
98
111
if backendRef .Name == rule .BackendRefs [i ].Name {
99
112
rule .BackendRefs [i ].Weight = backendRef .Weight
100
- foundBackendRef = true
101
113
ruleExists = true
102
114
break
103
115
}
104
116
}
105
-
106
- if ! foundBackendRef {
107
- httpRoute .Spec .Rules [j ].BackendRefs = append (rule .BackendRefs , backendRef )
108
- }
109
117
}
110
118
111
119
if ! ruleExists {
0 commit comments