Skip to content

Commit

Permalink
feat: support multiple routes per rollout (#34)
Browse files Browse the repository at this point in the history
* feat: support multiple routes per rollout

Signed-off-by: Stepan Rakitin <stepanr@mailbox.org>

* Move route ref into its own struct

Signed-off-by: Stepan Rakitin <stepanr@mailbox.org>

* Use dedicated fields for each route kind

Signed-off-by: Stepan Rakitin <stepanr@mailbox.org>

* Update error message

Signed-off-by: Stepan Rakitin <stepanr@mailbox.org>

* Remove changes to setter signatures

Signed-off-by: Stepan Rakitin <stepanr@mailbox.org>

* Move for loop into function

Signed-off-by: Stepan Rakitin <stepanr@mailbox.org>

* refactor: linting

Signed-off-by: Philipp Plotnikov <philipp.plotnikov@icloud.com>

* feat: add support multiroutes for setHeaderRoute function

Signed-off-by: Philipp Plotnikov <philipp.plotnikov@icloud.com>

* feat: add logs about plugin controls what routes for every supported feature

Signed-off-by: Philipp Plotnikov <philipp.plotnikov@icloud.com>

* docs: added information about setHeaderRoute and multi routes features

Signed-off-by: Philipp Plotnikov <philipp.plotnikov@icloud.com>

* docs: added information about setHeaderRoute and multi routes features

Signed-off-by: Philipp Plotnikov <philipp.plotnikov@icloud.com>

* docs: added information about namespace default value

Signed-off-by: Philipp Plotnikov <philipp.plotnikov@icloud.com>

---------

Signed-off-by: Stepan Rakitin <stepanr@mailbox.org>
Signed-off-by: Philipp Plotnikov <philipp.plotnikov@icloud.com>
Co-authored-by: Philipp Plotnikov <philipp.plotnikov@icloud.com>
  • Loading branch information
svrakitin and Philipp-Plotnikov authored Feb 26, 2024
1 parent d059156 commit 18cc071
Show file tree
Hide file tree
Showing 11 changed files with 317 additions and 93 deletions.
71 changes: 70 additions & 1 deletion examples/traefik/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,75 @@ Apply all the yaml files to your cluster

## Step 8 - Test the canary

Perform a deployment like any other Rollout and the Gateway plugin will split the traffic to your canary by instructing Traefik proxy via the Gateway API
Perform a deployment like any other Rollout and the Gateway plugin will split the traffic to your canary by instructing Traefik proxy via the Gateway API.

### Notice

GatewayAPI plugin supports traffic routing based on a header values for canary, so you can also use setHeaderRoute step in Argo Rollouts manifest. It also means that plugin should control managed routes. It creates ConfigMap in the specified namespace in **namespace** field with specified name in **configMap** field for that.
```yaml
plugins:
argoproj-labs/gatewayAPI:
namespace: test # default value is default
httpRoute: http-route
configMap: test-gateway # default value is argo-gatewayapi-configmap
```

## How to use multiple routes per rollout

## Step 1 - Create several routes

```yaml
apiVersion: gateway.networking.k8s.io/v1beta1
kind: HTTPRoute
metadata:
name: first-route
spec:
parentRefs:
- name: gateway
rules:
- matches:
- path:
type: PathPrefix
value: /first
backendRefs:
- name: argo-rollouts-stable-service
kind: Service
port: 80
- name: argo-rollouts-canary-service
kind: Service
port: 80
---
apiVersion: gateway.networking.k8s.io/v1beta1
kind: HTTPRoute
metadata:
name: second-route
spec:
parentRefs:
- name: gateway
rules:
- matches:
- path:
type: PathPrefix
value: /second
backendRefs:
- name: argo-rollouts-stable-service
kind: Service
port: 80
- name: argo-rollouts-canary-service
kind: Service
port: 80
```

## Step 2 - Change argoproj-labs/gatewayAPI field in Argo Rollout manifest

```yaml
plugins:
argoproj-labs/gatewayAPI:
httpRoutes:
- name: first-route # required
useHeaderRoutes: true
- name: second-route
```
You can control for what routes you need to add header routes during step of setHeaderRoute in Argo Rollout.

**Notice** All these features except traffic routing based on a header values for canary work also with TCPRoutes
14 changes: 10 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,17 @@ require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/evanphx/json-patch v5.6.0+incompatible // indirect
github.com/fatih/color v1.15.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.18.0 // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/hashicorp/go-hclog v1.5.0 // indirect
github.com/hashicorp/yamux v0.1.1 // indirect
github.com/imdario/mergo v0.3.16 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
Expand All @@ -29,8 +34,9 @@ require (
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/crypto v0.19.0 // indirect
golang.org/x/oauth2 v0.11.0 // indirect
golang.org/x/term v0.11.0 // indirect
golang.org/x/term v0.17.0 // indirect
golang.org/x/time v0.3.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230815205213-6bfd019c3878 // indirect
Expand All @@ -52,9 +58,9 @@ require (
github.com/mailru/easyjson v0.7.7 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
golang.org/x/net v0.14.0 // indirect
golang.org/x/sys v0.11.0 // indirect
golang.org/x/text v0.12.0 // indirect
golang.org/x/net v0.21.0 // indirect
golang.org/x/sys v0.17.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
Expand Down
20 changes: 20 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ github.com/evanphx/json-patch v5.6.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLi
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs=
github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw=
github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0=
github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk=
github.com/go-logr/logr v1.2.0/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ=
github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
Expand All @@ -22,6 +24,12 @@ github.com/go-openapi/jsonreference v0.20.2/go.mod h1:Bl1zwGIM8/wsvqjsOQLJ/SH+En
github.com/go-openapi/swag v0.22.3/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14=
github.com/go-openapi/swag v0.22.4 h1:QLMzNJnMGPRNDCbySlcj1x01tzU8/9LTTL9hZZZogBU=
github.com/go-openapi/swag v0.22.4/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14=
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
github.com/go-playground/validator/v10 v10.18.0 h1:BvolUXjp4zuvkZ5YN5t7ebzbhlUtPsPm2S9NAZ5nl9U=
github.com/go-playground/validator/v10 v10.18.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI=
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
Expand Down Expand Up @@ -61,6 +69,8 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
Expand Down Expand Up @@ -111,6 +121,8 @@ github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9dec
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.19.0 h1:ENy+Az/9Y1vSrlrvBSyna3PITt4tiZLf7sgCjZBX7Wo=
golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
Expand All @@ -120,6 +132,8 @@ golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLL
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.14.0 h1:BONx9s002vGdD9umnlX1Po8vOZmrgH34qlHcD1MfK14=
golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI=
golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4=
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
golang.org/x/oauth2 v0.11.0 h1:vPL4xzxBM4niKCW6g9whtaWVXTJf1U5e4aZxxFx/gbU=
golang.org/x/oauth2 v0.11.0/go.mod h1:LdF7O/8bLR/qWK9DrpXmbHLTouvRHK0SgJl0GmDBchk=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand All @@ -138,13 +152,19 @@ golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM=
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y=
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.11.0 h1:F9tnn/DA/Im8nCwm+fX+1/eBwi4qFjRT++MhtVC4ZX0=
golang.org/x/term v0.11.0/go.mod h1:zC9APTIj3jG3FdV/Ons+XE1riIZXG4aZ4GTHiPZJPIU=
golang.org/x/term v0.17.0 h1:mkTF7LCd6WGJNL3K1Ad7kwxNfYAW6a8a8QqtMblp/4U=
golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.12.0 h1:k+n5B8goJNdU7hSvEtMUz3d1Q6D/XW4COJSJR6fN0mc=
golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4=
golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
Expand Down
1 change: 0 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ func main() {
var pluginMap = map[string]goPlugin.Plugin{
"RpcTrafficRouterPlugin": &rolloutsPlugin.RpcTrafficRouterPlugin{Impl: rpcPluginImp},
}
logCtx.Debug("message from plugin", "foo", "bar")
goPlugin.Serve(&goPlugin.ServeConfig{
HandshakeConfig: handshakeConfig,
Plugins: pluginMap,
Expand Down
8 changes: 4 additions & 4 deletions pkg/mocks/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const (
CanaryServiceName = "argo-rollouts-canary-service"
HTTPRouteName = "argo-rollouts-http-route"
TCPRouteName = "argo-rollouts-tcp-route"
Namespace = "default"
RolloutNamespace = "default"
ConfigMapName = "test-config"
HTTPManagedRouteName = "test-http-header-route"
)
Expand All @@ -35,7 +35,7 @@ var (
var HTTPRouteObj = v1beta1.HTTPRoute{
ObjectMeta: metav1.ObjectMeta{
Name: HTTPRouteName,
Namespace: Namespace,
Namespace: RolloutNamespace,
},
Spec: v1beta1.HTTPRouteSpec{
CommonRouteSpec: v1beta1.CommonRouteSpec{
Expand Down Expand Up @@ -80,7 +80,7 @@ var HTTPRouteObj = v1beta1.HTTPRoute{
var TCPPRouteObj = v1alpha2.TCPRoute{
ObjectMeta: metav1.ObjectMeta{
Name: TCPRouteName,
Namespace: Namespace,
Namespace: RolloutNamespace,
},
Spec: v1alpha2.TCPRouteSpec{
CommonRouteSpec: v1alpha2.CommonRouteSpec{
Expand Down Expand Up @@ -116,6 +116,6 @@ var TCPPRouteObj = v1alpha2.TCPRoute{
var ConfigMapObj = v1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: ConfigMapName,
Namespace: Namespace,
Namespace: RolloutNamespace,
},
}
2 changes: 1 addition & 1 deletion pkg/plugin/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package plugin

const (
GatewayAPIUpdateError = "error updating Gateway API %q: %s"
GatewayAPIManifestError = "httpRoute and tcpRoute fields are empty. tcpRoute or httpRoute should be set"
GatewayAPIManifestError = "No routes configured. One of 'tcpRoutes', 'httpRoutes', 'tcpRoute' or 'httpRoute' should be set"
HTTPRouteFieldIsEmptyError = "httpRoute field is empty. It has to be set to remove managed routes"
InvalidHeaderMatchTypeError = "invalid header match type"
BackendRefWasNotFoundInHTTPRouteError = "backendRef was not found in httpRoute"
Expand Down
34 changes: 18 additions & 16 deletions pkg/plugin/httproute.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"errors"
"fmt"
"sync"

"github.com/argoproj-labs/rollouts-plugin-trafficrouter-gatewayapi/internal/utils"
"github.com/argoproj/argo-rollouts/pkg/apis/rollouts/v1alpha1"
Expand All @@ -17,13 +16,6 @@ const (
HTTPConfigMapKey = "httpManagedRoutes"
)

var (
httpHeaderRoute = HTTPHeaderRoute{
mutex: sync.Mutex{},
managedRouteMap: make(map[string]int),
}
)

func (r *RpcPlugin) setHTTPRouteWeight(rollout *v1alpha1.Rollout, desiredWeight int32, additionalDestinations []v1alpha1.WeightDestination, gatewayAPIConfig *GatewayAPITrafficRouting) pluginTypes.RpcError {
ctx := context.TODO()
httpRouteClient := r.HTTPRouteClient
Expand Down Expand Up @@ -77,7 +69,8 @@ func (r *RpcPlugin) setHTTPHeaderRoute(rollout *v1alpha1.Rollout, headerRouting
}
ctx := context.TODO()
httpRouteClient := r.HTTPRouteClient
managedRouteMap := httpHeaderRoute.managedRouteMap
managedRouteMap := make(ManagedRouteMap)
httpRouteName := gatewayAPIConfig.HTTPRoute
clientset := r.TestClientset
if !r.IsTest {
gatewayV1beta1 := r.GatewayAPIClientset.GatewayV1beta1()
Expand All @@ -99,7 +92,7 @@ func (r *RpcPlugin) setHTTPHeaderRoute(rollout *v1alpha1.Rollout, headerRouting
ErrorString: err.Error(),
}
}
httpRoute, err := httpRouteClient.Get(ctx, gatewayAPIConfig.HTTPRoute, metav1.GetOptions{})
httpRoute, err := httpRouteClient.Get(ctx, httpRouteName, metav1.GetOptions{})
if err != nil {
return pluginTypes.RpcError{
ErrorString: err.Error(),
Expand All @@ -126,6 +119,7 @@ func (r *RpcPlugin) setHTTPHeaderRoute(rollout *v1alpha1.Rollout, headerRouting
backendRef := httpRouteRule.BackendRefs[i]
if canaryServiceName == backendRef.Name {
canaryBackendRef = (*HTTPBackendRef)(&backendRef)
break
}
}
httpHeaderRouteRule := v1beta1.HTTPRouteRule{
Expand Down Expand Up @@ -154,7 +148,7 @@ func (r *RpcPlugin) setHTTPHeaderRoute(rollout *v1alpha1.Rollout, headerRouting
httpRouteRuleList = append(httpRouteRuleList, httpHeaderRouteRule)
oldHTTPRuleList := httpRoute.Spec.Rules
httpRoute.Spec.Rules = httpRouteRuleList
oldConfigMapData := make(map[string]int)
oldConfigMapData := make(ManagedRouteMap)
err = utils.GetConfigMapData(configMap, HTTPConfigMapKey, &oldConfigMapData)
if err != nil {
return pluginTypes.RpcError{
Expand Down Expand Up @@ -187,7 +181,10 @@ func (r *RpcPlugin) setHTTPHeaderRoute(rollout *v1alpha1.Rollout, headerRouting
},
{
Action: func() error {
managedRouteMap[headerRouting.Name] = len(httpRouteRuleList) - 1
if managedRouteMap[headerRouting.Name] == nil {
managedRouteMap[headerRouting.Name] = make(map[string]int)
}
managedRouteMap[headerRouting.Name][httpRouteName] = len(httpRouteRuleList) - 1
err = utils.UpdateConfigMapData(configMap, managedRouteMap, utils.UpdateConfigMapOptions{
Clientset: clientset,
ConfigMapKey: HTTPConfigMapKey,
Expand Down Expand Up @@ -253,7 +250,8 @@ func (r *RpcPlugin) removeHTTPManagedRoutes(managedRouteNameList []v1alpha1.Mang
ctx := context.TODO()
httpRouteClient := r.HTTPRouteClient
clientset := r.TestClientset
managedRouteMap := httpHeaderRoute.managedRouteMap
httpRouteName := gatewayAPIConfig.HTTPRoute
managedRouteMap := make(ManagedRouteMap)
if !r.IsTest {
gatewayV1beta1 := r.GatewayAPIClientset.GatewayV1beta1()
httpRouteClient = gatewayV1beta1.HTTPRoutes(gatewayAPIConfig.Namespace)
Expand All @@ -274,7 +272,7 @@ func (r *RpcPlugin) removeHTTPManagedRoutes(managedRouteNameList []v1alpha1.Mang
ErrorString: err.Error(),
}
}
httpRoute, err := httpRouteClient.Get(ctx, gatewayAPIConfig.HTTPRoute, metav1.GetOptions{})
httpRoute, err := httpRouteClient.Get(ctx, httpRouteName, metav1.GetOptions{})
if err != nil {
return pluginTypes.RpcError{
ErrorString: err.Error(),
Expand All @@ -290,7 +288,7 @@ func (r *RpcPlugin) removeHTTPManagedRoutes(managedRouteNameList []v1alpha1.Mang
continue
}
isHTTPRouteRuleListChanged = true
httpRouteRuleList, err = removeManagedRouteEntry(managedRouteMap, httpRouteRuleList, managedRouteName)
httpRouteRuleList, err = removeManagedRouteEntry(managedRouteMap, httpRouteRuleList, managedRouteName, httpRouteName)
if err != nil {
return pluginTypes.RpcError{
ErrorString: err.Error(),
Expand All @@ -302,7 +300,7 @@ func (r *RpcPlugin) removeHTTPManagedRoutes(managedRouteNameList []v1alpha1.Mang
}
oldHTTPRuleList := httpRoute.Spec.Rules
httpRoute.Spec.Rules = httpRouteRuleList
oldConfigMapData := make(map[string]int)
oldConfigMapData := make(ManagedRouteMap)
err = utils.GetConfigMapData(configMap, HTTPConfigMapKey, &oldConfigMapData)
if err != nil {
return pluginTypes.RpcError{
Expand Down Expand Up @@ -402,3 +400,7 @@ func (r HTTPRouteRuleList) Error() error {
func (r *HTTPBackendRef) GetName() string {
return string(r.Name)
}

func (r HTTPRoute) GetName() string {
return r.Name
}
Loading

0 comments on commit 18cc071

Please sign in to comment.