You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2021/03/19 05:09:28 UTC
[GitHub] [apisix-ingress-controller] tokers opened a new pull request #308: feat: traffic split
tokers opened a new pull request #308:
URL: https://github.com/apache/apisix-ingress-controller/pull/308
Please answer these questions before submitting a pull request
- Why submit this pull request?
- [ ] Bugfix
- [x] New feature provided
- [ ] Improve performance
- [ ] Backport patches
- Related issues
#289
### New feature or improvement
- Describe the details and related test reports.
This PR supports the traffic split in ApisixRoute.
___
### Backport patches
- Why need to backport?
- Source branch
- Related commits and pull requests
- Target branch
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix-ingress-controller] gxthrj commented on a change in pull request #308: feat: traffic split
Posted by GitBox <gi...@apache.org>.
gxthrj commented on a change in pull request #308:
URL: https://github.com/apache/apisix-ingress-controller/pull/308#discussion_r598109279
##########
File path: docs/en/latest/concepts/apisix_route.md
##########
@@ -139,12 +139,46 @@ spec:
- /*
methods:
- GET
- backend:
- serviceName: foo
- servicePort: 80
- resolveGranularity: service
+ backends:
+ - serviceName: foo
+ servicePort: 80
+ resolveGranularity: service
```
+Weight Based Traffic Split
+--------------------------
+
+There can more than one backend specified in one route rule,
+when multiple backends co-exist there, the traffic split based on weights
+will be applied (which actually uses the [traffic-split](http://apisix.apache.org/docs/apisix/plugins/traffic-split/) plugin in Apache APISIX).
+You can specify weight for each backend, the default weight is `100`.
+
+```yaml
+apiVersion: apisix.apache.org/v2alpha1
+kind: ApisixRoute
+metadata:
+ name: method-route
+spec:
+ http:
+ - name: method
+ match:
+ paths:
+ - /*
+ methods:
+ - GET
+ backends:
+ - serviceName: foo
+ servicePort: 80
+ weight: 100
+ - serviceName: bar
+ servicePort: 81
+ weight: 50
+```
+
+The above `ApisixRoute` has one route rule, which contains two backends `foo` and `bar`, the
+weight ratio is `100:50`, which means `2/3` requests will be sent to service `foo` and `1/3` requests
+will be proxied to serivce `bar`.
+
Review comment:
Need example to show `match` with `vars`.
##########
File path: pkg/kube/translation/util.go
##########
@@ -0,0 +1,86 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+package translation
+
+import (
+ "errors"
+
+ "go.uber.org/zap"
+ "k8s.io/apimachinery/pkg/util/intstr"
+
+ "github.com/apache/apisix-ingress-controller/pkg/id"
+ configv2alpha1 "github.com/apache/apisix-ingress-controller/pkg/kube/apisix/apis/config/v2alpha1"
+ "github.com/apache/apisix-ingress-controller/pkg/log"
+ apisixv1 "github.com/apache/apisix-ingress-controller/pkg/types/apisix/v1"
+)
+
+func (t *translator) getServiceClusterIPAndPort(backend *configv2alpha1.ApisixRouteHTTPBackend, ar *configv2alpha1.ApisixRoute) (string, int32, error) {
+ svc, err := t.ServiceLister.Services(ar.Namespace).Get(backend.ServiceName)
+ if err != nil {
+ return "", 0, err
+ }
+ svcPort := int32(-1)
+loop:
+ for _, port := range svc.Spec.Ports {
+ switch backend.ServicePort.Type {
+ case intstr.Int:
+ if backend.ServicePort.IntVal == port.Port {
+ svcPort = port.Port
+ break loop
+ }
+ case intstr.String:
+ if backend.ServicePort.StrVal == port.Name {
+ svcPort = port.Port
+ break loop
+ }
+ }
+ }
+ if svcPort == -1 {
+ log.Errorw("ApisixRoute refers to non-existent Service port",
+ zap.Any("ApisixRoute", ar),
+ zap.String("port", backend.ServicePort.String()),
+ )
+ return "", 0, err
+ }
+
+ if backend.ResolveGranularity == "service" && svc.Spec.ClusterIP == "" {
+ log.Errorw("ApisixRoute refers to a headless service but want to use the service level resolve granularity",
+ zap.Any("ApisixRoute", ar),
+ zap.Any("service", svc),
+ )
+ return "", 0, errors.New("conflict headless service and backend resolve granularity")
+ }
+ return svc.Spec.ClusterIP, svcPort, nil
+}
+
+func (t *translator) translateUpstream(namespace, svcName, svcResolveGranularity, svcClusterIP string, svcPort int32) (*apisixv1.Upstream, error) {
+ ups, err := t.TranslateUpstream(namespace, svcName, svcPort)
+ if err != nil {
+ return nil, err
+ }
+ if svcResolveGranularity == "service" {
+ ups.Nodes = []apisixv1.UpstreamNode{
+ {
+ IP: svcClusterIP,
+ Port: int(svcPort),
+ Weight: _defaultWeight,
+ },
+ }
+ }
+ ups.FullName = apisixv1.ComposeUpstreamName(namespace, svcName, svcPort)
+ ups.Name = ups.FullName
+ ups.ID = id.GenID(ups.FullName)
Review comment:
If upstream.ID is nil, what is the behavior of the controller ?
##########
File path: pkg/kube/translation/apisix_route.go
##########
@@ -108,40 +108,29 @@ func (t *translator) TranslateRouteV2alpha1(ar *configv2alpha1.ApisixRoute) ([]*
if len(part.Match.Paths) < 1 {
return nil, nil, errors.New("empty route paths match")
}
- svc, err := t.ServiceLister.Services(ar.Namespace).Get(part.Backend.ServiceName)
- if err != nil {
- return nil, nil, err
+ if part.Backend != nil && len(part.Backends) > 1 {
+ return nil, nil, errors.New("backend and backends are exclusive")
}
- svcPort := int32(-1)
- loop:
- for _, port := range svc.Spec.Ports {
- switch part.Backend.ServicePort.Type {
- case intstr.Int:
- if part.Backend.ServicePort.IntVal == port.Port {
- svcPort = port.Port
- break loop
- }
- case intstr.String:
- if part.Backend.ServicePort.StrVal == port.Name {
- svcPort = port.Port
- break loop
- }
- }
- }
- if svcPort == -1 {
- log.Errorw("ApisixRoute refers to non-existent Service port",
- zap.Any("ApisixRoute", ar),
- zap.String("port", part.Backend.ServicePort.String()),
- )
- return nil, nil, err
+ if part.Backend == nil && len(part.Backends) == 0 {
+ return nil, nil, errors.New("no specified backend")
}
+ backends := part.Backends
+ backend := part.Backend
+ if len(backends) > 0 {
+ // Use the first backend as the default backend in Route,
+ // others will be configured in traffic-split plugin.
+ backend = backends[0]
Review comment:
Confused here, `backend ` will be covered if backends is not empty ?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix-ingress-controller] tokers commented on a change in pull request #308: feat: traffic split
Posted by GitBox <gi...@apache.org>.
tokers commented on a change in pull request #308:
URL: https://github.com/apache/apisix-ingress-controller/pull/308#discussion_r598236990
##########
File path: pkg/kube/translation/apisix_route.go
##########
@@ -108,40 +108,29 @@ func (t *translator) TranslateRouteV2alpha1(ar *configv2alpha1.ApisixRoute) ([]*
if len(part.Match.Paths) < 1 {
return nil, nil, errors.New("empty route paths match")
}
- svc, err := t.ServiceLister.Services(ar.Namespace).Get(part.Backend.ServiceName)
- if err != nil {
- return nil, nil, err
+ if part.Backend != nil && len(part.Backends) > 1 {
+ return nil, nil, errors.New("backend and backends are exclusive")
}
- svcPort := int32(-1)
- loop:
- for _, port := range svc.Spec.Ports {
- switch part.Backend.ServicePort.Type {
- case intstr.Int:
- if part.Backend.ServicePort.IntVal == port.Port {
- svcPort = port.Port
- break loop
- }
- case intstr.String:
- if part.Backend.ServicePort.StrVal == port.Name {
- svcPort = port.Port
- break loop
- }
- }
- }
- if svcPort == -1 {
- log.Errorw("ApisixRoute refers to non-existent Service port",
- zap.Any("ApisixRoute", ar),
- zap.String("port", part.Backend.ServicePort.String()),
- )
- return nil, nil, err
+ if part.Backend == nil && len(part.Backends) == 0 {
+ return nil, nil, errors.New("no specified backend")
}
+ backends := part.Backends
+ backend := part.Backend
+ if len(backends) > 0 {
+ // Use the first backend as the default backend in Route,
+ // others will be configured in traffic-split plugin.
+ backend = backends[0]
Review comment:
No, already check the exclusive relationship before this, when `backends` not empty, `backend` is `nil`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix-ingress-controller] codecov-io commented on pull request #308: feat: traffic split
Posted by GitBox <gi...@apache.org>.
codecov-io commented on pull request #308:
URL: https://github.com/apache/apisix-ingress-controller/pull/308#issuecomment-802563470
# [Codecov](https://codecov.io/gh/apache/apisix-ingress-controller/pull/308?src=pr&el=h1) Report
> Merging [#308](https://codecov.io/gh/apache/apisix-ingress-controller/pull/308?src=pr&el=desc) (d08cfec) into [master](https://codecov.io/gh/apache/apisix-ingress-controller/commit/f45203e67c5875ecdd0407814f1742ccf4bd6859?el=desc) (f45203e) will **decrease** coverage by `1.54%`.
> The diff coverage is `0.00%`.
[](https://codecov.io/gh/apache/apisix-ingress-controller/pull/308?src=pr&el=tree)
```diff
@@ Coverage Diff @@
## master #308 +/- ##
==========================================
- Coverage 53.00% 51.46% -1.55%
==========================================
Files 33 34 +1
Lines 2394 2460 +66
==========================================
- Hits 1269 1266 -3
- Misses 965 1034 +69
Partials 160 160
```
| [Impacted Files](https://codecov.io/gh/apache/apisix-ingress-controller/pull/308?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pkg/kube/translation/apisix\_route.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/308/diff?src=pr&el=tree#diff-cGtnL2t1YmUvdHJhbnNsYXRpb24vYXBpc2l4X3JvdXRlLmdv) | `28.41% <0.00%> (ø)` | |
| [pkg/kube/translation/plugin.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/308/diff?src=pr&el=tree#diff-cGtnL2t1YmUvdHJhbnNsYXRpb24vcGx1Z2luLmdv) | `0.00% <0.00%> (ø)` | |
| [pkg/kube/translation/util.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/308/diff?src=pr&el=tree#diff-cGtnL2t1YmUvdHJhbnNsYXRpb24vdXRpbC5nbw==) | `0.00% <0.00%> (ø)` | |
| [pkg/seven/state/solver.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/308/diff?src=pr&el=tree#diff-cGtnL3NldmVuL3N0YXRlL3NvbHZlci5nbw==) | `2.00% <0.00%> (-2.00%)` | :arrow_down: |
| [test/e2e/e2e.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/308/diff?src=pr&el=tree#diff-dGVzdC9lMmUvZTJlLmdv) | | |
------
[Continue to review full report at Codecov](https://codecov.io/gh/apache/apisix-ingress-controller/pull/308?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/apache/apisix-ingress-controller/pull/308?src=pr&el=footer). Last update [f45203e...d08cfec](https://codecov.io/gh/apache/apisix-ingress-controller/pull/308?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix-ingress-controller] codecov-io edited a comment on pull request #308: feat: traffic split
Posted by GitBox <gi...@apache.org>.
codecov-io edited a comment on pull request #308:
URL: https://github.com/apache/apisix-ingress-controller/pull/308#issuecomment-802563470
# [Codecov](https://codecov.io/gh/apache/apisix-ingress-controller/pull/308?src=pr&el=h1) Report
> Merging [#308](https://codecov.io/gh/apache/apisix-ingress-controller/pull/308?src=pr&el=desc) (3ac2766) into [master](https://codecov.io/gh/apache/apisix-ingress-controller/commit/f45203e67c5875ecdd0407814f1742ccf4bd6859?el=desc) (f45203e) will **increase** coverage by `1.26%`.
> The diff coverage is `63.20%`.
[](https://codecov.io/gh/apache/apisix-ingress-controller/pull/308?src=pr&el=tree)
```diff
@@ Coverage Diff @@
## master #308 +/- ##
==========================================
+ Coverage 53.00% 54.26% +1.26%
==========================================
Files 33 34 +1
Lines 2394 2460 +66
==========================================
+ Hits 1269 1335 +66
- Misses 965 966 +1
+ Partials 160 159 -1
```
| [Impacted Files](https://codecov.io/gh/apache/apisix-ingress-controller/pull/308?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pkg/kube/translation/apisix\_route.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/308/diff?src=pr&el=tree#diff-cGtnL2t1YmUvdHJhbnNsYXRpb24vYXBpc2l4X3JvdXRlLmdv) | `28.41% <0.00%> (ø)` | |
| [pkg/kube/translation/plugin.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/308/diff?src=pr&el=tree#diff-cGtnL2t1YmUvdHJhbnNsYXRpb24vcGx1Z2luLmdv) | `100.00% <100.00%> (ø)` | |
| [pkg/kube/translation/util.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/308/diff?src=pr&el=tree#diff-cGtnL2t1YmUvdHJhbnNsYXRpb24vdXRpbC5nbw==) | `100.00% <100.00%> (ø)` | |
| [pkg/seven/state/solver.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/308/diff?src=pr&el=tree#diff-cGtnL3NldmVuL3N0YXRlL3NvbHZlci5nbw==) | `2.00% <0.00%> (-2.00%)` | :arrow_down: |
| [test/e2e/e2e.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/308/diff?src=pr&el=tree#diff-dGVzdC9lMmUvZTJlLmdv) | | |
| [pkg/kube/translation/translator.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/308/diff?src=pr&el=tree#diff-cGtnL2t1YmUvdHJhbnNsYXRpb24vdHJhbnNsYXRvci5nbw==) | `56.06% <0.00%> (+3.03%)` | :arrow_up: |
------
[Continue to review full report at Codecov](https://codecov.io/gh/apache/apisix-ingress-controller/pull/308?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/apache/apisix-ingress-controller/pull/308?src=pr&el=footer). Last update [f45203e...3ac2766](https://codecov.io/gh/apache/apisix-ingress-controller/pull/308?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix-ingress-controller] tokers commented on a change in pull request #308: feat: traffic split
Posted by GitBox <gi...@apache.org>.
tokers commented on a change in pull request #308:
URL: https://github.com/apache/apisix-ingress-controller/pull/308#discussion_r598393337
##########
File path: docs/en/latest/concepts/apisix_route.md
##########
@@ -139,12 +139,46 @@ spec:
- /*
methods:
- GET
- backend:
- serviceName: foo
- servicePort: 80
- resolveGranularity: service
+ backends:
+ - serviceName: foo
+ servicePort: 80
+ resolveGranularity: service
```
+Weight Based Traffic Split
+--------------------------
+
+There can more than one backend specified in one route rule,
+when multiple backends co-exist there, the traffic split based on weights
+will be applied (which actually uses the [traffic-split](http://apisix.apache.org/docs/apisix/plugins/traffic-split/) plugin in Apache APISIX).
+You can specify weight for each backend, the default weight is `100`.
+
+```yaml
+apiVersion: apisix.apache.org/v2alpha1
+kind: ApisixRoute
+metadata:
+ name: method-route
+spec:
+ http:
+ - name: method
+ match:
+ paths:
+ - /*
+ methods:
+ - GET
+ backends:
+ - serviceName: foo
+ servicePort: 80
+ weight: 100
+ - serviceName: bar
+ servicePort: 81
+ weight: 50
+```
+
+The above `ApisixRoute` has one route rule, which contains two backends `foo` and `bar`, the
+weight ratio is `100:50`, which means `2/3` requests will be sent to service `foo` and `1/3` requests
+will be proxied to serivce `bar`.
+
Review comment:
Added.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix-ingress-controller] codecov-io edited a comment on pull request #308: feat: traffic split
Posted by GitBox <gi...@apache.org>.
codecov-io edited a comment on pull request #308:
URL: https://github.com/apache/apisix-ingress-controller/pull/308#issuecomment-802563470
# [Codecov](https://codecov.io/gh/apache/apisix-ingress-controller/pull/308?src=pr&el=h1) Report
> Merging [#308](https://codecov.io/gh/apache/apisix-ingress-controller/pull/308?src=pr&el=desc) (c618397) into [master](https://codecov.io/gh/apache/apisix-ingress-controller/commit/f45203e67c5875ecdd0407814f1742ccf4bd6859?el=desc) (f45203e) will **increase** coverage by `1.26%`.
> The diff coverage is `63.20%`.
[](https://codecov.io/gh/apache/apisix-ingress-controller/pull/308?src=pr&el=tree)
```diff
@@ Coverage Diff @@
## master #308 +/- ##
==========================================
+ Coverage 53.00% 54.26% +1.26%
==========================================
Files 33 34 +1
Lines 2394 2460 +66
==========================================
+ Hits 1269 1335 +66
- Misses 965 966 +1
+ Partials 160 159 -1
```
| [Impacted Files](https://codecov.io/gh/apache/apisix-ingress-controller/pull/308?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pkg/kube/translation/apisix\_route.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/308/diff?src=pr&el=tree#diff-cGtnL2t1YmUvdHJhbnNsYXRpb24vYXBpc2l4X3JvdXRlLmdv) | `28.41% <0.00%> (ø)` | |
| [pkg/kube/translation/plugin.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/308/diff?src=pr&el=tree#diff-cGtnL2t1YmUvdHJhbnNsYXRpb24vcGx1Z2luLmdv) | `100.00% <100.00%> (ø)` | |
| [pkg/kube/translation/util.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/308/diff?src=pr&el=tree#diff-cGtnL2t1YmUvdHJhbnNsYXRpb24vdXRpbC5nbw==) | `100.00% <100.00%> (ø)` | |
| [pkg/seven/state/solver.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/308/diff?src=pr&el=tree#diff-cGtnL3NldmVuL3N0YXRlL3NvbHZlci5nbw==) | `2.00% <0.00%> (-2.00%)` | :arrow_down: |
| [test/e2e/e2e.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/308/diff?src=pr&el=tree#diff-dGVzdC9lMmUvZTJlLmdv) | | |
| [pkg/kube/translation/translator.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/308/diff?src=pr&el=tree#diff-cGtnL2t1YmUvdHJhbnNsYXRpb24vdHJhbnNsYXRvci5nbw==) | `56.06% <0.00%> (+3.03%)` | :arrow_up: |
------
[Continue to review full report at Codecov](https://codecov.io/gh/apache/apisix-ingress-controller/pull/308?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/apache/apisix-ingress-controller/pull/308?src=pr&el=footer). Last update [f45203e...c618397](https://codecov.io/gh/apache/apisix-ingress-controller/pull/308?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix-ingress-controller] tokers commented on a change in pull request #308: feat: traffic split
Posted by GitBox <gi...@apache.org>.
tokers commented on a change in pull request #308:
URL: https://github.com/apache/apisix-ingress-controller/pull/308#discussion_r598237061
##########
File path: pkg/kube/translation/util.go
##########
@@ -0,0 +1,86 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+package translation
+
+import (
+ "errors"
+
+ "go.uber.org/zap"
+ "k8s.io/apimachinery/pkg/util/intstr"
+
+ "github.com/apache/apisix-ingress-controller/pkg/id"
+ configv2alpha1 "github.com/apache/apisix-ingress-controller/pkg/kube/apisix/apis/config/v2alpha1"
+ "github.com/apache/apisix-ingress-controller/pkg/log"
+ apisixv1 "github.com/apache/apisix-ingress-controller/pkg/types/apisix/v1"
+)
+
+func (t *translator) getServiceClusterIPAndPort(backend *configv2alpha1.ApisixRouteHTTPBackend, ar *configv2alpha1.ApisixRoute) (string, int32, error) {
+ svc, err := t.ServiceLister.Services(ar.Namespace).Get(backend.ServiceName)
+ if err != nil {
+ return "", 0, err
+ }
+ svcPort := int32(-1)
+loop:
+ for _, port := range svc.Spec.Ports {
+ switch backend.ServicePort.Type {
+ case intstr.Int:
+ if backend.ServicePort.IntVal == port.Port {
+ svcPort = port.Port
+ break loop
+ }
+ case intstr.String:
+ if backend.ServicePort.StrVal == port.Name {
+ svcPort = port.Port
+ break loop
+ }
+ }
+ }
+ if svcPort == -1 {
+ log.Errorw("ApisixRoute refers to non-existent Service port",
+ zap.Any("ApisixRoute", ar),
+ zap.String("port", backend.ServicePort.String()),
+ )
+ return "", 0, err
+ }
+
+ if backend.ResolveGranularity == "service" && svc.Spec.ClusterIP == "" {
+ log.Errorw("ApisixRoute refers to a headless service but want to use the service level resolve granularity",
+ zap.Any("ApisixRoute", ar),
+ zap.Any("service", svc),
+ )
+ return "", 0, errors.New("conflict headless service and backend resolve granularity")
+ }
+ return svc.Spec.ClusterIP, svcPort, nil
+}
+
+func (t *translator) translateUpstream(namespace, svcName, svcResolveGranularity, svcClusterIP string, svcPort int32) (*apisixv1.Upstream, error) {
+ ups, err := t.TranslateUpstream(namespace, svcName, svcPort)
+ if err != nil {
+ return nil, err
+ }
+ if svcResolveGranularity == "service" {
+ ups.Nodes = []apisixv1.UpstreamNode{
+ {
+ IP: svcClusterIP,
+ Port: int(svcPort),
+ Weight: _defaultWeight,
+ },
+ }
+ }
+ ups.FullName = apisixv1.ComposeUpstreamName(namespace, svcName, svcPort)
+ ups.Name = ups.FullName
+ ups.ID = id.GenID(ups.FullName)
Review comment:
Update of Upstream will fail in APISIX side since the necessary ID is not provided by the caller.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix-ingress-controller] tokers commented on a change in pull request #308: feat: traffic split
Posted by GitBox <gi...@apache.org>.
tokers commented on a change in pull request #308:
URL: https://github.com/apache/apisix-ingress-controller/pull/308#discussion_r598236940
##########
File path: docs/en/latest/concepts/apisix_route.md
##########
@@ -139,12 +139,46 @@ spec:
- /*
methods:
- GET
- backend:
- serviceName: foo
- servicePort: 80
- resolveGranularity: service
+ backends:
+ - serviceName: foo
+ servicePort: 80
+ resolveGranularity: service
```
+Weight Based Traffic Split
+--------------------------
+
+There can more than one backend specified in one route rule,
+when multiple backends co-exist there, the traffic split based on weights
+will be applied (which actually uses the [traffic-split](http://apisix.apache.org/docs/apisix/plugins/traffic-split/) plugin in Apache APISIX).
+You can specify weight for each backend, the default weight is `100`.
+
+```yaml
+apiVersion: apisix.apache.org/v2alpha1
+kind: ApisixRoute
+metadata:
+ name: method-route
+spec:
+ http:
+ - name: method
+ match:
+ paths:
+ - /*
+ methods:
+ - GET
+ backends:
+ - serviceName: foo
+ servicePort: 80
+ weight: 100
+ - serviceName: bar
+ servicePort: 81
+ weight: 50
+```
+
+The above `ApisixRoute` has one route rule, which contains two backends `foo` and `bar`, the
+weight ratio is `100:50`, which means `2/3` requests will be sent to service `foo` and `1/3` requests
+will be proxied to serivce `bar`.
+
Review comment:
OK, will added.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix-ingress-controller] tokers merged pull request #308: feat: traffic split
Posted by GitBox <gi...@apache.org>.
tokers merged pull request #308:
URL: https://github.com/apache/apisix-ingress-controller/pull/308
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org