9
9
"github.com/argoproj-labs/rollouts-plugin-trafficrouter-gatewayapi/internal/utils"
10
10
"github.com/argoproj/argo-rollouts/pkg/apis/rollouts/v1alpha1"
11
11
pluginTypes "github.com/argoproj/argo-rollouts/utils/plugin/types"
12
+ "github.com/sirupsen/logrus"
12
13
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
13
14
gatewayv1 "sigs.k8s.io/gateway-api/apis/v1"
14
15
)
@@ -19,10 +20,12 @@ const (
19
20
20
21
func (r * RpcPlugin ) setHTTPRouteWeight (rollout * v1alpha1.Rollout , desiredWeight int32 , gatewayAPIConfig * GatewayAPITrafficRouting ) pluginTypes.RpcError {
21
22
ctx := context .TODO ()
23
+ clientset := r .TestClientset
22
24
httpRouteClient := r .HTTPRouteClient
23
25
if ! r .IsTest {
24
26
gatewayClientV1 := r .GatewayAPIClientset .GatewayV1 ()
25
27
httpRouteClient = gatewayClientV1 .HTTPRoutes (gatewayAPIConfig .Namespace )
28
+ clientset = r .Clientset .CoreV1 ().ConfigMaps (gatewayAPIConfig .Namespace )
26
29
}
27
30
httpRoute , err := httpRouteClient .Get (ctx , gatewayAPIConfig .HTTPRoute , metav1.GetOptions {})
28
31
if err != nil {
@@ -32,16 +35,63 @@ func (r *RpcPlugin) setHTTPRouteWeight(rollout *v1alpha1.Rollout, desiredWeight
32
35
}
33
36
canaryServiceName := rollout .Spec .Strategy .Canary .CanaryService
34
37
stableServiceName := rollout .Spec .Strategy .Canary .StableService
38
+
39
+ // Retrieve the managed routes from the configmap to determine which rules were added via setHTTPHeaderRoute
40
+ managedRouteMap := make (ManagedRouteMap )
41
+ configMap , err := utils .GetOrCreateConfigMap (gatewayAPIConfig .ConfigMap , utils.CreateConfigMapOptions {
42
+ Clientset : clientset ,
43
+ Ctx : ctx ,
44
+ })
45
+ if err != nil {
46
+ return pluginTypes.RpcError {
47
+ ErrorString : err .Error (),
48
+ }
49
+ }
50
+ err = utils .GetConfigMapData (configMap , HTTPConfigMapKey , & managedRouteMap )
51
+ if err != nil {
52
+ return pluginTypes.RpcError {
53
+ ErrorString : err .Error (),
54
+ }
55
+ }
56
+ managedRuleIndices := make (map [int ]bool )
57
+ for _ , managedRoute := range managedRouteMap {
58
+ if idx , ok := managedRoute [httpRoute .Name ]; ok {
59
+ managedRuleIndices [idx ] = true
60
+ }
61
+ }
62
+
35
63
routeRuleList := HTTPRouteRuleList (httpRoute .Spec .Rules )
36
- canaryBackendRefs , err := getBackendRefs (canaryServiceName , routeRuleList )
64
+ indexedCanaryBackendRefs , err := getIndexedBackendRefs (canaryServiceName , routeRuleList )
37
65
if err != nil {
38
66
return pluginTypes.RpcError {
39
67
ErrorString : err .Error (),
40
68
}
41
69
}
70
+ canaryBackendRefs := make ([]* HTTPBackendRef , 0 )
71
+ for _ , indexedCanaryBackendRef := range indexedCanaryBackendRefs {
72
+ // TODO - when setMirrorRoute is implemented, we would need to update the weight of the managed
73
+ // canary backendRefs for mirror routes.
74
+ // Ideally - these would be stored differently in the configmap from the managed header based routes
75
+ // but that would mean a breaking change to the configmap structure
76
+ if managedRuleIndices [indexedCanaryBackendRef .RuleIndex ] {
77
+ r .LogCtx .WithFields (logrus.Fields {
78
+ "rule" : httpRoute .Spec .Rules [indexedCanaryBackendRef .RuleIndex ],
79
+ "index" : indexedCanaryBackendRef .RuleIndex ,
80
+ "managedRouteMap" : managedRouteMap ,
81
+ }).Info ("Skipping matched canary backendRef for weight adjustment since it is a part of a rule marked as a managed route" )
82
+ continue
83
+ }
84
+ canaryBackendRefs = append (canaryBackendRefs , indexedCanaryBackendRef .Refs ... )
85
+ }
86
+
87
+ // Update the weight of the canary backendRefs not owned by a rule marked as a managed route
42
88
for _ , ref := range canaryBackendRefs {
43
89
ref .Weight = & desiredWeight
44
90
}
91
+
92
+ // Noted above, but any managed routes that would have a stableBackendRef would be updated with weight here.
93
+ // Since this is not yet possible (all managed routes will only have a single canary backendRef),
94
+ // we can avoid checking for managed route rule indexes here.
45
95
stableBackendRefs , err := getBackendRefs (stableServiceName , routeRuleList )
46
96
if err != nil {
47
97
return pluginTypes.RpcError {
0 commit comments