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/02/07 10:23:54 UTC
[GitHub] [apisix-ingress-controller] tokers opened a new pull request #247: feat: support health check on ApisixUpstream
tokers opened a new pull request #247:
URL: https://github.com/apache/apisix-ingress-controller/pull/247
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
___
### Bugfix
- Description
- How to fix?
___
### New feature or improvement
- Describe the details and related test reports.
___
### 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] tokers commented on a change in pull request #247: feat: support health check on ApisixUpstream
Posted by GitBox <gi...@apache.org>.
tokers commented on a change in pull request #247:
URL: https://github.com/apache/apisix-ingress-controller/pull/247#discussion_r571910296
##########
File path: pkg/kube/apisix_upstream.go
##########
@@ -0,0 +1,260 @@
+// 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 kube
+
+import (
+ configv1 "github.com/apache/apisix-ingress-controller/pkg/kube/apisix/apis/config/v1"
+ apisixv1 "github.com/apache/apisix-ingress-controller/pkg/types/apisix/v1"
+)
+
+func (t *translator) translateUpstreamScheme(scheme string, ups *apisixv1.Upstream) error {
+ if scheme == "" {
+ ups.Scheme = apisixv1.SchemeHTTP
+ return nil
+ }
+ switch scheme {
+ case apisixv1.SchemeHTTP, apisixv1.SchemeGRPC:
+ ups.Scheme = scheme
+ return nil
+ default:
+ return &translateError{field: "scheme", reason: "invalid value"}
+ }
+}
+
+func (t *translator) translateUpstreamLoadBalancer(lb *configv1.LoadBalancer, ups *apisixv1.Upstream) error {
+ if lb == nil || lb.Type == "" {
+ ups.Type = apisixv1.LbRoundRobin
+ return nil
+ }
+ switch lb.Type {
+ case apisixv1.LbRoundRobin, apisixv1.LbLeastConn, apisixv1.LbEwma:
+ ups.Type = lb.Type
+ case apisixv1.LbConsistentHash:
+ ups.Type = lb.Type
+ ups.Key = lb.Key
+ switch lb.HashOn {
+ case apisixv1.HashOnVars:
+ fallthrough
+ case apisixv1.HashOnHeader:
+ fallthrough
+ case apisixv1.HashOnCookie:
+ fallthrough
+ case apisixv1.HashOnConsumer:
+ fallthrough
+ case apisixv1.HashOnVarsCombination:
+ ups.HashOn = lb.HashOn
+ default:
+ return &translateError{field: "loadbalancer.hashOn", reason: "invalid value"}
+ }
+ default:
+ return &translateError{
+ field: "loadbalancer.type",
+ reason: "invalid value",
+ }
+ }
+ return nil
+}
+
+func (t *translator) translateUpstreamHealthCheck(config *configv1.HealthCheck, ups *apisixv1.Upstream) error {
+ if config == nil || (config.Passive == nil && config.Active == nil) {
+ return nil
+ }
+ var hc apisixv1.UpstreamHealthCheck
+ if config.Passive != nil {
+ passive, err := t.translateUpstreamPassiveHealthCheck(config.Passive)
+ if err != nil {
+ return err
+ }
+ hc.Passive = passive
+ }
+
+ if config.Active != nil {
+ active, err := t.translateUpstreamActiveHealthCheck(config.Active)
+ if err != nil {
+ return err
+ }
+ hc.Active = active
+ } else {
+ return &translateError{
+ field: "healthCheck.active",
+ reason: "not exist",
+ }
+ }
+
+ ups.Checks = &hc
+ return nil
+}
+
+func (t *translator) translateUpstreamActiveHealthCheck(config *configv1.ActiveHealthCheck) (*apisixv1.UpstreamActiveHealthCheck, error) {
+ var active apisixv1.UpstreamActiveHealthCheck
+ switch config.Type {
+ case apisixv1.HealthCheckHTTP, apisixv1.HealthCheckHTTPS, apisixv1.HealthCheckTCP:
+ active.Type = config.Type
+ case "":
+ active.Type = apisixv1.HealthCheckHTTP
+ default:
+ return nil, &translateError{
+ field: "healthCheck.active.Type",
+ reason: "invalid value",
+ }
+ }
+
+ active.Timeout = int(config.Timeout.Seconds())
+ if config.Port < 0 || config.Port > 65535 {
+ return nil, &translateError{
+ field: "healthCheck.active.port",
+ reason: "invalid value",
+ }
+ } else {
+ active.Port = config.Port
+ }
+ if config.Concurrency < 0 {
+ return nil, &translateError{
+ field: "healthCheck.active.concurrency",
+ reason: "invalid value",
+ }
+ } else {
+ active.Concurrency = config.Concurrency
+ }
+ active.Host = config.Host
+ active.HTTPPath = config.HTTPPath
+ active.HTTPRequestHeaders = config.RequestHeaders
+
+ if config.StrictTLS == nil || *config.StrictTLS == true {
+ active.HTTPSVerifyCert = true
+ }
+
+ if config.Healthy != nil {
+ if config.Healthy.Successes < 0 || config.Healthy.Successes > apisixv1.HealthCheckMaxConsecutiveNumber {
+ return nil, &translateError{
+ field: "healthCheck.active.healthy.successes",
+ reason: "invalid value",
+ }
+ }
+ active.Healthy.Successes = config.Healthy.Successes
+ if config.Healthy.HTTPCodes != nil && len(config.Healthy.HTTPCodes) < 1 {
+ return nil, &translateError{
+ field: "healthCheck.active.healthy.httpCodes",
+ reason: "empty",
+ }
+ }
+ active.Healthy.HTTPStatuses = config.Healthy.HTTPCodes
+
+ if config.Healthy.Interval.Duration < apisixv1.ActiveHealthCheckMinInterval {
+ return nil, &translateError{
+ field: "healthCheck.active.healthy.interval",
+ reason: "invalid value",
+ }
+ }
+ active.Healthy.Interval = int(config.Healthy.Interval.Seconds())
+ }
+
+ if config.Unhealthy != nil {
+ if config.Unhealthy.HTTPFailures < 0 || config.Unhealthy.HTTPFailures > apisixv1.HealthCheckMaxConsecutiveNumber {
+ return nil, &translateError{
+ field: "healthCheck.active.unhealthy.httpFailures",
+ reason: "invalid value",
+ }
+ }
+ active.Unhealthy.HTTPFailures = config.Unhealthy.HTTPFailures
+
+ if config.Unhealthy.TCPFailures < 0 || config.Unhealthy.TCPFailures > apisixv1.HealthCheckMaxConsecutiveNumber {
+ return nil, &translateError{
+ field: "healthCheck.active.unhealthy.tcpFailures",
+ reason: "invalid value",
+ }
+ }
+ active.Unhealthy.TCPFailures = config.Unhealthy.TCPFailures
+ active.Unhealthy.Timeouts = config.Unhealthy.Timeout.Seconds()
+
+ if config.Unhealthy.HTTPCodes != nil && len(config.Unhealthy.HTTPCodes) < 1 {
+ return nil, &translateError{
+ field: "healthCheck.active.unhealthy.httpCodes",
+ reason: "empty",
+ }
+ }
+ active.Unhealthy.HTTPStatuses = config.Unhealthy.HTTPCodes
+
+ if config.Unhealthy.Interval.Duration < apisixv1.ActiveHealthCheckMinInterval {
+ return nil, &translateError{
+ field: "healthCheck.active.unhealthy.interval",
+ reason: "invalid value",
+ }
+ }
+ active.Unhealthy.Interval = int(config.Unhealthy.Interval.Seconds())
+ }
+
+ return &active, nil
+}
+
+func (t *translator) translateUpstreamPassiveHealthCheck(config *configv1.PassiveHealthCheck) (*apisixv1.UpstreamPassiveHealthCheck, error) {
+ var passive apisixv1.UpstreamPassiveHealthCheck
+ switch config.Type {
+ case apisixv1.HealthCheckHTTP, apisixv1.HealthCheckHTTPS, apisixv1.HealthCheckTCP:
+ passive.Type = config.Type
+ case "":
+ passive.Type = apisixv1.HealthCheckHTTP
+ default:
+ return nil, &translateError{
+ field: "healthCheck.passive.Type",
+ reason: "invalid value",
+ }
+ }
+ if config.Healthy != nil {
+ // zero means use the default value.
+ if config.Healthy.Successes < 0 || config.Healthy.Successes > apisixv1.HealthCheckMaxConsecutiveNumber {
+ return nil, &translateError{
+ field: "healthCheck.passive.healthy.successes",
+ reason: "invalid value",
+ }
+ }
+ passive.Healthy.Successes = config.Healthy.Successes
+ if config.Healthy.HTTPCodes != nil && len(config.Healthy.HTTPCodes) < 1 {
+ return nil, &translateError{
+ field: "healthCheck.passive.healthy.httpCodes",
+ reason: "empty",
+ }
+ }
+ passive.Healthy.HTTPStatuses = config.Healthy.HTTPCodes
+ }
+
+ if config.Unhealthy != nil {
+ if config.Unhealthy.HTTPFailures < 0 || config.Unhealthy.HTTPFailures > apisixv1.HealthCheckMaxConsecutiveNumber {
+ return nil, &translateError{
+ field: "healthCheck.passive.unhealthy.httpFailures",
+ reason: "invalid value",
+ }
+ }
+ passive.Unhealthy.HTTPFailures = config.Unhealthy.HTTPFailures
+
+ if config.Unhealthy.TCPFailures < 0 || config.Unhealthy.TCPFailures > apisixv1.HealthCheckMaxConsecutiveNumber {
+ return nil, &translateError{
+ field: "healthCheck.passive.unhealthy.tcpFailures",
+ reason: "invalid value",
+ }
+ }
+ passive.Unhealthy.TCPFailures = config.Unhealthy.TCPFailures
+ passive.Unhealthy.Timeouts = config.Unhealthy.Timeout.Seconds()
+
+ if config.Unhealthy.HTTPCodes != nil && len(config.Unhealthy.HTTPCodes) < 1 {
+ return nil, &translateError{
+ field: "healthCheck.passive.unhealthy.httpCodes",
+ reason: "empty",
+ }
+ }
+ passive.Unhealthy.HTTPStatuses = config.Unhealthy.HTTPCodes
+ }
+ return &passive, nil
+}
Review comment:
We can enhance these logics in the future.
----------------------------------------------------------------
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 #247: feat: support health check on ApisixUpstream
Posted by GitBox <gi...@apache.org>.
tokers merged pull request #247:
URL: https://github.com/apache/apisix-ingress-controller/pull/247
----------------------------------------------------------------
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 #247: feat: support health check on ApisixUpstream
Posted by GitBox <gi...@apache.org>.
codecov-io edited a comment on pull request #247:
URL: https://github.com/apache/apisix-ingress-controller/pull/247#issuecomment-774661264
# [Codecov](https://codecov.io/gh/apache/apisix-ingress-controller/pull/247?src=pr&el=h1) Report
> Merging [#247](https://codecov.io/gh/apache/apisix-ingress-controller/pull/247?src=pr&el=desc) (a53adc2) into [master](https://codecov.io/gh/apache/apisix-ingress-controller/commit/8ca50759480940120328bf99bc476e19d9599c39?el=desc) (8ca5075) will **increase** coverage by `54.67%`.
> The diff coverage is `n/a`.
[](https://codecov.io/gh/apache/apisix-ingress-controller/pull/247?src=pr&el=tree)
```diff
@@ Coverage Diff @@
## master #247 +/- ##
============================================
+ Coverage 45.32% 100.00% +54.67%
============================================
Files 35 1 -34
Lines 2054 1 -2053
============================================
- Hits 931 1 -930
+ Misses 984 0 -984
+ Partials 139 0 -139
```
| [Impacted Files](https://codecov.io/gh/apache/apisix-ingress-controller/pull/247?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pkg/apisix/nonexistentclient.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/247/diff?src=pr&el=tree#diff-cGtnL2FwaXNpeC9ub25leGlzdGVudGNsaWVudC5nbw==) | | |
| [pkg/metrics/prometheus.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/247/diff?src=pr&el=tree#diff-cGtnL21ldHJpY3MvcHJvbWV0aGV1cy5nbw==) | | |
| [pkg/log/default\_logger.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/247/diff?src=pr&el=tree#diff-cGtnL2xvZy9kZWZhdWx0X2xvZ2dlci5nbw==) | | |
| [pkg/seven/state/service\_worker.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/247/diff?src=pr&el=tree#diff-cGtnL3NldmVuL3N0YXRlL3NlcnZpY2Vfd29ya2VyLmdv) | | |
| [pkg/apisix/service.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/247/diff?src=pr&el=tree#diff-cGtnL2FwaXNpeC9zZXJ2aWNlLmdv) | | |
| [pkg/ingress/apisix/plugin.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/247/diff?src=pr&el=tree#diff-cGtnL2luZ3Jlc3MvYXBpc2l4L3BsdWdpbi5nbw==) | | |
| [pkg/apisix/route.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/247/diff?src=pr&el=tree#diff-cGtnL2FwaXNpeC9yb3V0ZS5nbw==) | | |
| [pkg/seven/state/route\_worker.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/247/diff?src=pr&el=tree#diff-cGtnL3NldmVuL3N0YXRlL3JvdXRlX3dvcmtlci5nbw==) | | |
| [pkg/types/timeduration.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/247/diff?src=pr&el=tree#diff-cGtnL3R5cGVzL3RpbWVkdXJhdGlvbi5nbw==) | | |
| [pkg/kube/init.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/247/diff?src=pr&el=tree#diff-cGtnL2t1YmUvaW5pdC5nbw==) | | |
| ... and [21 more](https://codecov.io/gh/apache/apisix-ingress-controller/pull/247/diff?src=pr&el=tree-more) | |
------
[Continue to review full report at Codecov](https://codecov.io/gh/apache/apisix-ingress-controller/pull/247?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/247?src=pr&el=footer). Last update [8ca5075...a53adc2](https://codecov.io/gh/apache/apisix-ingress-controller/pull/247?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 #247: feat: support health check on ApisixUpstream
Posted by GitBox <gi...@apache.org>.
tokers commented on a change in pull request #247:
URL: https://github.com/apache/apisix-ingress-controller/pull/247#discussion_r571910296
##########
File path: pkg/kube/apisix_upstream.go
##########
@@ -0,0 +1,260 @@
+// 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 kube
+
+import (
+ configv1 "github.com/apache/apisix-ingress-controller/pkg/kube/apisix/apis/config/v1"
+ apisixv1 "github.com/apache/apisix-ingress-controller/pkg/types/apisix/v1"
+)
+
+func (t *translator) translateUpstreamScheme(scheme string, ups *apisixv1.Upstream) error {
+ if scheme == "" {
+ ups.Scheme = apisixv1.SchemeHTTP
+ return nil
+ }
+ switch scheme {
+ case apisixv1.SchemeHTTP, apisixv1.SchemeGRPC:
+ ups.Scheme = scheme
+ return nil
+ default:
+ return &translateError{field: "scheme", reason: "invalid value"}
+ }
+}
+
+func (t *translator) translateUpstreamLoadBalancer(lb *configv1.LoadBalancer, ups *apisixv1.Upstream) error {
+ if lb == nil || lb.Type == "" {
+ ups.Type = apisixv1.LbRoundRobin
+ return nil
+ }
+ switch lb.Type {
+ case apisixv1.LbRoundRobin, apisixv1.LbLeastConn, apisixv1.LbEwma:
+ ups.Type = lb.Type
+ case apisixv1.LbConsistentHash:
+ ups.Type = lb.Type
+ ups.Key = lb.Key
+ switch lb.HashOn {
+ case apisixv1.HashOnVars:
+ fallthrough
+ case apisixv1.HashOnHeader:
+ fallthrough
+ case apisixv1.HashOnCookie:
+ fallthrough
+ case apisixv1.HashOnConsumer:
+ fallthrough
+ case apisixv1.HashOnVarsCombination:
+ ups.HashOn = lb.HashOn
+ default:
+ return &translateError{field: "loadbalancer.hashOn", reason: "invalid value"}
+ }
+ default:
+ return &translateError{
+ field: "loadbalancer.type",
+ reason: "invalid value",
+ }
+ }
+ return nil
+}
+
+func (t *translator) translateUpstreamHealthCheck(config *configv1.HealthCheck, ups *apisixv1.Upstream) error {
+ if config == nil || (config.Passive == nil && config.Active == nil) {
+ return nil
+ }
+ var hc apisixv1.UpstreamHealthCheck
+ if config.Passive != nil {
+ passive, err := t.translateUpstreamPassiveHealthCheck(config.Passive)
+ if err != nil {
+ return err
+ }
+ hc.Passive = passive
+ }
+
+ if config.Active != nil {
+ active, err := t.translateUpstreamActiveHealthCheck(config.Active)
+ if err != nil {
+ return err
+ }
+ hc.Active = active
+ } else {
+ return &translateError{
+ field: "healthCheck.active",
+ reason: "not exist",
+ }
+ }
+
+ ups.Checks = &hc
+ return nil
+}
+
+func (t *translator) translateUpstreamActiveHealthCheck(config *configv1.ActiveHealthCheck) (*apisixv1.UpstreamActiveHealthCheck, error) {
+ var active apisixv1.UpstreamActiveHealthCheck
+ switch config.Type {
+ case apisixv1.HealthCheckHTTP, apisixv1.HealthCheckHTTPS, apisixv1.HealthCheckTCP:
+ active.Type = config.Type
+ case "":
+ active.Type = apisixv1.HealthCheckHTTP
+ default:
+ return nil, &translateError{
+ field: "healthCheck.active.Type",
+ reason: "invalid value",
+ }
+ }
+
+ active.Timeout = int(config.Timeout.Seconds())
+ if config.Port < 0 || config.Port > 65535 {
+ return nil, &translateError{
+ field: "healthCheck.active.port",
+ reason: "invalid value",
+ }
+ } else {
+ active.Port = config.Port
+ }
+ if config.Concurrency < 0 {
+ return nil, &translateError{
+ field: "healthCheck.active.concurrency",
+ reason: "invalid value",
+ }
+ } else {
+ active.Concurrency = config.Concurrency
+ }
+ active.Host = config.Host
+ active.HTTPPath = config.HTTPPath
+ active.HTTPRequestHeaders = config.RequestHeaders
+
+ if config.StrictTLS == nil || *config.StrictTLS == true {
+ active.HTTPSVerifyCert = true
+ }
+
+ if config.Healthy != nil {
+ if config.Healthy.Successes < 0 || config.Healthy.Successes > apisixv1.HealthCheckMaxConsecutiveNumber {
+ return nil, &translateError{
+ field: "healthCheck.active.healthy.successes",
+ reason: "invalid value",
+ }
+ }
+ active.Healthy.Successes = config.Healthy.Successes
+ if config.Healthy.HTTPCodes != nil && len(config.Healthy.HTTPCodes) < 1 {
+ return nil, &translateError{
+ field: "healthCheck.active.healthy.httpCodes",
+ reason: "empty",
+ }
+ }
+ active.Healthy.HTTPStatuses = config.Healthy.HTTPCodes
+
+ if config.Healthy.Interval.Duration < apisixv1.ActiveHealthCheckMinInterval {
+ return nil, &translateError{
+ field: "healthCheck.active.healthy.interval",
+ reason: "invalid value",
+ }
+ }
+ active.Healthy.Interval = int(config.Healthy.Interval.Seconds())
+ }
+
+ if config.Unhealthy != nil {
+ if config.Unhealthy.HTTPFailures < 0 || config.Unhealthy.HTTPFailures > apisixv1.HealthCheckMaxConsecutiveNumber {
+ return nil, &translateError{
+ field: "healthCheck.active.unhealthy.httpFailures",
+ reason: "invalid value",
+ }
+ }
+ active.Unhealthy.HTTPFailures = config.Unhealthy.HTTPFailures
+
+ if config.Unhealthy.TCPFailures < 0 || config.Unhealthy.TCPFailures > apisixv1.HealthCheckMaxConsecutiveNumber {
+ return nil, &translateError{
+ field: "healthCheck.active.unhealthy.tcpFailures",
+ reason: "invalid value",
+ }
+ }
+ active.Unhealthy.TCPFailures = config.Unhealthy.TCPFailures
+ active.Unhealthy.Timeouts = config.Unhealthy.Timeout.Seconds()
+
+ if config.Unhealthy.HTTPCodes != nil && len(config.Unhealthy.HTTPCodes) < 1 {
+ return nil, &translateError{
+ field: "healthCheck.active.unhealthy.httpCodes",
+ reason: "empty",
+ }
+ }
+ active.Unhealthy.HTTPStatuses = config.Unhealthy.HTTPCodes
+
+ if config.Unhealthy.Interval.Duration < apisixv1.ActiveHealthCheckMinInterval {
+ return nil, &translateError{
+ field: "healthCheck.active.unhealthy.interval",
+ reason: "invalid value",
+ }
+ }
+ active.Unhealthy.Interval = int(config.Unhealthy.Interval.Seconds())
+ }
+
+ return &active, nil
+}
+
+func (t *translator) translateUpstreamPassiveHealthCheck(config *configv1.PassiveHealthCheck) (*apisixv1.UpstreamPassiveHealthCheck, error) {
+ var passive apisixv1.UpstreamPassiveHealthCheck
+ switch config.Type {
+ case apisixv1.HealthCheckHTTP, apisixv1.HealthCheckHTTPS, apisixv1.HealthCheckTCP:
+ passive.Type = config.Type
+ case "":
+ passive.Type = apisixv1.HealthCheckHTTP
+ default:
+ return nil, &translateError{
+ field: "healthCheck.passive.Type",
+ reason: "invalid value",
+ }
+ }
+ if config.Healthy != nil {
+ // zero means use the default value.
+ if config.Healthy.Successes < 0 || config.Healthy.Successes > apisixv1.HealthCheckMaxConsecutiveNumber {
+ return nil, &translateError{
+ field: "healthCheck.passive.healthy.successes",
+ reason: "invalid value",
+ }
+ }
+ passive.Healthy.Successes = config.Healthy.Successes
+ if config.Healthy.HTTPCodes != nil && len(config.Healthy.HTTPCodes) < 1 {
+ return nil, &translateError{
+ field: "healthCheck.passive.healthy.httpCodes",
+ reason: "empty",
+ }
+ }
+ passive.Healthy.HTTPStatuses = config.Healthy.HTTPCodes
+ }
+
+ if config.Unhealthy != nil {
+ if config.Unhealthy.HTTPFailures < 0 || config.Unhealthy.HTTPFailures > apisixv1.HealthCheckMaxConsecutiveNumber {
+ return nil, &translateError{
+ field: "healthCheck.passive.unhealthy.httpFailures",
+ reason: "invalid value",
+ }
+ }
+ passive.Unhealthy.HTTPFailures = config.Unhealthy.HTTPFailures
+
+ if config.Unhealthy.TCPFailures < 0 || config.Unhealthy.TCPFailures > apisixv1.HealthCheckMaxConsecutiveNumber {
+ return nil, &translateError{
+ field: "healthCheck.passive.unhealthy.tcpFailures",
+ reason: "invalid value",
+ }
+ }
+ passive.Unhealthy.TCPFailures = config.Unhealthy.TCPFailures
+ passive.Unhealthy.Timeouts = config.Unhealthy.Timeout.Seconds()
+
+ if config.Unhealthy.HTTPCodes != nil && len(config.Unhealthy.HTTPCodes) < 1 {
+ return nil, &translateError{
+ field: "healthCheck.passive.unhealthy.httpCodes",
+ reason: "empty",
+ }
+ }
+ passive.Unhealthy.HTTPStatuses = config.Unhealthy.HTTPCodes
+ }
+ return &passive, nil
+}
Review comment:
We can enhance these logics in the future. But these logics are for ApisixUpstream CRD, not for the Upstream in APISIX.
----------------------------------------------------------------
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 #247: feat: support health check on ApisixUpstream
Posted by GitBox <gi...@apache.org>.
tokers commented on a change in pull request #247:
URL: https://github.com/apache/apisix-ingress-controller/pull/247#discussion_r571913512
##########
File path: pkg/apisix/resource.go
##########
@@ -135,6 +135,17 @@ func (i *item) upstream(clusterName string) (*v1.Upstream, error) {
})
}
+ // XXX This is a work around scheme to avoid APISIX's
+ // health check schema about the health checker intervals.
+ if ups.Checks != nil && ups.Checks.Active != nil {
+ if ups.Checks.Active.Healthy.Interval == 0 {
+ ups.Checks.Active.Healthy.Interval = 1
Review comment:
The default interval in APISIX is zero...
----------------------------------------------------------------
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 #247: feat: support health check on ApisixUpstream
Posted by GitBox <gi...@apache.org>.
tokers commented on a change in pull request #247:
URL: https://github.com/apache/apisix-ingress-controller/pull/247#discussion_r571909852
##########
File path: pkg/apisix/resource.go
##########
@@ -135,6 +135,17 @@ func (i *item) upstream(clusterName string) (*v1.Upstream, error) {
})
}
+ // XXX This is a work around scheme to avoid APISIX's
+ // health check schema about the health checker intervals.
+ if ups.Checks != nil && ups.Checks.Active != nil {
+ if ups.Checks.Active.Healthy.Interval == 0 {
+ ups.Checks.Active.Healthy.Interval = 1
Review comment:
This is a work around scheme to avoid the APISIX's bug.
----------------------------------------------------------------
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 #247: feat: support health check on ApisixUpstream
Posted by GitBox <gi...@apache.org>.
codecov-io commented on pull request #247:
URL: https://github.com/apache/apisix-ingress-controller/pull/247#issuecomment-774661264
# [Codecov](https://codecov.io/gh/apache/apisix-ingress-controller/pull/247?src=pr&el=h1) Report
> Merging [#247](https://codecov.io/gh/apache/apisix-ingress-controller/pull/247?src=pr&el=desc) (90b241e) into [master](https://codecov.io/gh/apache/apisix-ingress-controller/commit/8ca50759480940120328bf99bc476e19d9599c39?el=desc) (8ca5075) will **increase** coverage by `54.67%`.
> The diff coverage is `n/a`.
[](https://codecov.io/gh/apache/apisix-ingress-controller/pull/247?src=pr&el=tree)
```diff
@@ Coverage Diff @@
## master #247 +/- ##
============================================
+ Coverage 45.32% 100.00% +54.67%
============================================
Files 35 1 -34
Lines 2054 1 -2053
============================================
- Hits 931 1 -930
+ Misses 984 0 -984
+ Partials 139 0 -139
```
| [Impacted Files](https://codecov.io/gh/apache/apisix-ingress-controller/pull/247?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pkg/kube/init.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/247/diff?src=pr&el=tree#diff-cGtnL2t1YmUvaW5pdC5nbw==) | | |
| [pkg/log/default\_logger.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/247/diff?src=pr&el=tree#diff-cGtnL2xvZy9kZWZhdWx0X2xvZ2dlci5nbw==) | | |
| [pkg/apisix/route.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/247/diff?src=pr&el=tree#diff-cGtnL2FwaXNpeC9yb3V0ZS5nbw==) | | |
| [pkg/seven/state/route\_worker.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/247/diff?src=pr&el=tree#diff-cGtnL3NldmVuL3N0YXRlL3JvdXRlX3dvcmtlci5nbw==) | | |
| [pkg/api/server.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/247/diff?src=pr&el=tree#diff-cGtnL2FwaS9zZXJ2ZXIuZ28=) | | |
| [pkg/apisix/nonexistentclient.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/247/diff?src=pr&el=tree#diff-cGtnL2FwaXNpeC9ub25leGlzdGVudGNsaWVudC5nbw==) | | |
| [pkg/types/errors.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/247/diff?src=pr&el=tree#diff-cGtnL3R5cGVzL2Vycm9ycy5nbw==) | | |
| [cmd/ingress/ingress.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/247/diff?src=pr&el=tree#diff-Y21kL2luZ3Jlc3MvaW5ncmVzcy5nbw==) | | |
| [pkg/apisix/apisix.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/247/diff?src=pr&el=tree#diff-cGtnL2FwaXNpeC9hcGlzaXguZ28=) | | |
| [pkg/types/timeduration.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/247/diff?src=pr&el=tree#diff-cGtnL3R5cGVzL3RpbWVkdXJhdGlvbi5nbw==) | | |
| ... and [21 more](https://codecov.io/gh/apache/apisix-ingress-controller/pull/247/diff?src=pr&el=tree-more) | |
------
[Continue to review full report at Codecov](https://codecov.io/gh/apache/apisix-ingress-controller/pull/247?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/247?src=pr&el=footer). Last update [8ca5075...90b241e](https://codecov.io/gh/apache/apisix-ingress-controller/pull/247?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 pull request #247: feat: support health check on ApisixUpstream
Posted by GitBox <gi...@apache.org>.
tokers commented on pull request #247:
URL: https://github.com/apache/apisix-ingress-controller/pull/247#issuecomment-774649516
Test cases will be added as soon as possible.
----------------------------------------------------------------
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 #247: feat: support health check on ApisixUpstream
Posted by GitBox <gi...@apache.org>.
gxthrj commented on a change in pull request #247:
URL: https://github.com/apache/apisix-ingress-controller/pull/247#discussion_r571879545
##########
File path: pkg/apisix/resource.go
##########
@@ -135,6 +135,17 @@ func (i *item) upstream(clusterName string) (*v1.Upstream, error) {
})
}
+ // XXX This is a work around scheme to avoid APISIX's
+ // health check schema about the health checker intervals.
+ if ups.Checks != nil && ups.Checks.Active != nil {
+ if ups.Checks.Active.Healthy.Interval == 0 {
+ ups.Checks.Active.Healthy.Interval = 1
+ }
+ if ups.Checks.Active.Unhealthy.Interval == 0 {
+ ups.Checks.Active.Healthy.Interval = 1
Review comment:
ditto
##########
File path: pkg/apisix/resource.go
##########
@@ -135,6 +135,17 @@ func (i *item) upstream(clusterName string) (*v1.Upstream, error) {
})
}
+ // XXX This is a work around scheme to avoid APISIX's
+ // health check schema about the health checker intervals.
+ if ups.Checks != nil && ups.Checks.Active != nil {
+ if ups.Checks.Active.Healthy.Interval == 0 {
+ ups.Checks.Active.Healthy.Interval = 1
Review comment:
Magic number, need a default interval variable instead.
##########
File path: pkg/apisix/upstream.go
##########
@@ -62,20 +62,16 @@ func (n *upstreamNodes) UnmarshalJSON(p []byte) error {
}
type upstreamReqBody struct {
- LBType string `json:"type"`
- HashOn string `json:"hash_on,omitempty"`
- Key string `json:"key,omitempty"`
- Nodes upstreamNodes `json:"nodes"`
- Desc string `json:"desc"`
- Scheme string `json:"scheme,omitempty"`
+ LBType string `json:"type"`
+ HashOn string `json:"hash_on,omitempty"`
+ Key string `json:"key,omitempty"`
+ Nodes upstreamNodes `json:"nodes"`
+ Desc string `json:"desc"`
+ Scheme string `json:"scheme,omitempty"`
+ Checks *v1.UpstreamHealthCheck `json:"checks,omitempty" yaml:"checks,omitempty"`
Review comment:
Why declare yaml mark ?
##########
File path: pkg/apisix/resource.go
##########
@@ -135,6 +135,17 @@ func (i *item) upstream(clusterName string) (*v1.Upstream, error) {
})
}
+ // XXX This is a work around scheme to avoid APISIX's
Review comment:
typo `XXX `
##########
File path: pkg/kube/apisix_upstream.go
##########
@@ -0,0 +1,260 @@
+// 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 kube
+
+import (
+ configv1 "github.com/apache/apisix-ingress-controller/pkg/kube/apisix/apis/config/v1"
+ apisixv1 "github.com/apache/apisix-ingress-controller/pkg/types/apisix/v1"
+)
+
+func (t *translator) translateUpstreamScheme(scheme string, ups *apisixv1.Upstream) error {
+ if scheme == "" {
+ ups.Scheme = apisixv1.SchemeHTTP
+ return nil
+ }
+ switch scheme {
+ case apisixv1.SchemeHTTP, apisixv1.SchemeGRPC:
+ ups.Scheme = scheme
+ return nil
+ default:
+ return &translateError{field: "scheme", reason: "invalid value"}
+ }
+}
+
+func (t *translator) translateUpstreamLoadBalancer(lb *configv1.LoadBalancer, ups *apisixv1.Upstream) error {
+ if lb == nil || lb.Type == "" {
+ ups.Type = apisixv1.LbRoundRobin
+ return nil
+ }
+ switch lb.Type {
+ case apisixv1.LbRoundRobin, apisixv1.LbLeastConn, apisixv1.LbEwma:
+ ups.Type = lb.Type
+ case apisixv1.LbConsistentHash:
+ ups.Type = lb.Type
+ ups.Key = lb.Key
+ switch lb.HashOn {
+ case apisixv1.HashOnVars:
+ fallthrough
+ case apisixv1.HashOnHeader:
+ fallthrough
+ case apisixv1.HashOnCookie:
+ fallthrough
+ case apisixv1.HashOnConsumer:
+ fallthrough
+ case apisixv1.HashOnVarsCombination:
+ ups.HashOn = lb.HashOn
+ default:
+ return &translateError{field: "loadbalancer.hashOn", reason: "invalid value"}
+ }
+ default:
+ return &translateError{
+ field: "loadbalancer.type",
+ reason: "invalid value",
+ }
+ }
+ return nil
+}
+
+func (t *translator) translateUpstreamHealthCheck(config *configv1.HealthCheck, ups *apisixv1.Upstream) error {
+ if config == nil || (config.Passive == nil && config.Active == nil) {
+ return nil
+ }
+ var hc apisixv1.UpstreamHealthCheck
+ if config.Passive != nil {
+ passive, err := t.translateUpstreamPassiveHealthCheck(config.Passive)
+ if err != nil {
+ return err
+ }
+ hc.Passive = passive
+ }
+
+ if config.Active != nil {
+ active, err := t.translateUpstreamActiveHealthCheck(config.Active)
+ if err != nil {
+ return err
+ }
+ hc.Active = active
+ } else {
+ return &translateError{
+ field: "healthCheck.active",
+ reason: "not exist",
+ }
+ }
+
+ ups.Checks = &hc
+ return nil
+}
+
+func (t *translator) translateUpstreamActiveHealthCheck(config *configv1.ActiveHealthCheck) (*apisixv1.UpstreamActiveHealthCheck, error) {
+ var active apisixv1.UpstreamActiveHealthCheck
+ switch config.Type {
+ case apisixv1.HealthCheckHTTP, apisixv1.HealthCheckHTTPS, apisixv1.HealthCheckTCP:
+ active.Type = config.Type
+ case "":
+ active.Type = apisixv1.HealthCheckHTTP
+ default:
+ return nil, &translateError{
+ field: "healthCheck.active.Type",
+ reason: "invalid value",
+ }
+ }
+
+ active.Timeout = int(config.Timeout.Seconds())
+ if config.Port < 0 || config.Port > 65535 {
+ return nil, &translateError{
+ field: "healthCheck.active.port",
+ reason: "invalid value",
+ }
+ } else {
+ active.Port = config.Port
+ }
+ if config.Concurrency < 0 {
+ return nil, &translateError{
+ field: "healthCheck.active.concurrency",
+ reason: "invalid value",
+ }
+ } else {
+ active.Concurrency = config.Concurrency
+ }
+ active.Host = config.Host
+ active.HTTPPath = config.HTTPPath
+ active.HTTPRequestHeaders = config.RequestHeaders
+
+ if config.StrictTLS == nil || *config.StrictTLS == true {
+ active.HTTPSVerifyCert = true
+ }
+
+ if config.Healthy != nil {
+ if config.Healthy.Successes < 0 || config.Healthy.Successes > apisixv1.HealthCheckMaxConsecutiveNumber {
+ return nil, &translateError{
+ field: "healthCheck.active.healthy.successes",
+ reason: "invalid value",
+ }
+ }
+ active.Healthy.Successes = config.Healthy.Successes
+ if config.Healthy.HTTPCodes != nil && len(config.Healthy.HTTPCodes) < 1 {
+ return nil, &translateError{
+ field: "healthCheck.active.healthy.httpCodes",
+ reason: "empty",
+ }
+ }
+ active.Healthy.HTTPStatuses = config.Healthy.HTTPCodes
+
+ if config.Healthy.Interval.Duration < apisixv1.ActiveHealthCheckMinInterval {
+ return nil, &translateError{
+ field: "healthCheck.active.healthy.interval",
+ reason: "invalid value",
+ }
+ }
+ active.Healthy.Interval = int(config.Healthy.Interval.Seconds())
+ }
+
+ if config.Unhealthy != nil {
+ if config.Unhealthy.HTTPFailures < 0 || config.Unhealthy.HTTPFailures > apisixv1.HealthCheckMaxConsecutiveNumber {
+ return nil, &translateError{
+ field: "healthCheck.active.unhealthy.httpFailures",
+ reason: "invalid value",
+ }
+ }
+ active.Unhealthy.HTTPFailures = config.Unhealthy.HTTPFailures
+
+ if config.Unhealthy.TCPFailures < 0 || config.Unhealthy.TCPFailures > apisixv1.HealthCheckMaxConsecutiveNumber {
+ return nil, &translateError{
+ field: "healthCheck.active.unhealthy.tcpFailures",
+ reason: "invalid value",
+ }
+ }
+ active.Unhealthy.TCPFailures = config.Unhealthy.TCPFailures
+ active.Unhealthy.Timeouts = config.Unhealthy.Timeout.Seconds()
+
+ if config.Unhealthy.HTTPCodes != nil && len(config.Unhealthy.HTTPCodes) < 1 {
+ return nil, &translateError{
+ field: "healthCheck.active.unhealthy.httpCodes",
+ reason: "empty",
+ }
+ }
+ active.Unhealthy.HTTPStatuses = config.Unhealthy.HTTPCodes
+
+ if config.Unhealthy.Interval.Duration < apisixv1.ActiveHealthCheckMinInterval {
+ return nil, &translateError{
+ field: "healthCheck.active.unhealthy.interval",
+ reason: "invalid value",
+ }
+ }
+ active.Unhealthy.Interval = int(config.Unhealthy.Interval.Seconds())
+ }
+
+ return &active, nil
+}
+
+func (t *translator) translateUpstreamPassiveHealthCheck(config *configv1.PassiveHealthCheck) (*apisixv1.UpstreamPassiveHealthCheck, error) {
+ var passive apisixv1.UpstreamPassiveHealthCheck
+ switch config.Type {
+ case apisixv1.HealthCheckHTTP, apisixv1.HealthCheckHTTPS, apisixv1.HealthCheckTCP:
+ passive.Type = config.Type
+ case "":
+ passive.Type = apisixv1.HealthCheckHTTP
+ default:
+ return nil, &translateError{
+ field: "healthCheck.passive.Type",
+ reason: "invalid value",
+ }
+ }
+ if config.Healthy != nil {
+ // zero means use the default value.
+ if config.Healthy.Successes < 0 || config.Healthy.Successes > apisixv1.HealthCheckMaxConsecutiveNumber {
+ return nil, &translateError{
+ field: "healthCheck.passive.healthy.successes",
+ reason: "invalid value",
+ }
+ }
+ passive.Healthy.Successes = config.Healthy.Successes
+ if config.Healthy.HTTPCodes != nil && len(config.Healthy.HTTPCodes) < 1 {
+ return nil, &translateError{
+ field: "healthCheck.passive.healthy.httpCodes",
+ reason: "empty",
+ }
+ }
+ passive.Healthy.HTTPStatuses = config.Healthy.HTTPCodes
+ }
+
+ if config.Unhealthy != nil {
+ if config.Unhealthy.HTTPFailures < 0 || config.Unhealthy.HTTPFailures > apisixv1.HealthCheckMaxConsecutiveNumber {
+ return nil, &translateError{
+ field: "healthCheck.passive.unhealthy.httpFailures",
+ reason: "invalid value",
+ }
+ }
+ passive.Unhealthy.HTTPFailures = config.Unhealthy.HTTPFailures
+
+ if config.Unhealthy.TCPFailures < 0 || config.Unhealthy.TCPFailures > apisixv1.HealthCheckMaxConsecutiveNumber {
+ return nil, &translateError{
+ field: "healthCheck.passive.unhealthy.tcpFailures",
+ reason: "invalid value",
+ }
+ }
+ passive.Unhealthy.TCPFailures = config.Unhealthy.TCPFailures
+ passive.Unhealthy.Timeouts = config.Unhealthy.Timeout.Seconds()
+
+ if config.Unhealthy.HTTPCodes != nil && len(config.Unhealthy.HTTPCodes) < 1 {
+ return nil, &translateError{
+ field: "healthCheck.passive.unhealthy.httpCodes",
+ reason: "empty",
+ }
+ }
+ passive.Unhealthy.HTTPStatuses = config.Unhealthy.HTTPCodes
+ }
+ return &passive, nil
+}
Review comment:
We can use `jsonschema` to simplify validation and avoid too many if else.
This suggest is an enhancement, do not block the PR.
----------------------------------------------------------------
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