Skip to content

Commit 9c2c810

Browse files
committed
refactor: remove deprecated discovery and health check features from ApisixUpstream in standalone mode
1 parent b9e1aae commit 9c2c810

File tree

7 files changed

+21
-294
lines changed

7 files changed

+21
-294
lines changed

api/adc/types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ type Upstream struct {
197197

198198
HashOn string `json:"hash_on,omitempty" yaml:"hash_on,omitempty"`
199199
Key string `json:"key,omitempty" yaml:"key,omitempty"`
200-
Nodes UpstreamNodes `json:"nodes,omitempty" yaml:"nodes,omitempty"`
200+
Nodes UpstreamNodes `json:"nodes" yaml:"nodes"`
201201
PassHost string `json:"pass_host,omitempty" yaml:"pass_host,omitempty"`
202202
Retries *int64 `json:"retries,omitempty" yaml:"retries,omitempty"`
203203
RetryTimeout *float64 `json:"retry_timeout,omitempty" yaml:"retry_timeout,omitempty"`

api/v2/apisixupstream_types.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919
)
2020

2121
// ApisixUpstreamSpec describes the specification of ApisixUpstream.
22-
// +kubebuilder:validation:XValidation:rule="has(self.subsets) || (has(self.externalNodes)!=has(self.discovery))"
2322
type ApisixUpstreamSpec struct {
2423
// IngressClassName is the name of an IngressClass cluster resource.
2524
// controller implementations use this field to know whether they should be
@@ -95,6 +94,7 @@ type ApisixUpstreamConfig struct {
9594
// +kubebuilder:validation:Optional
9695
Timeout *UpstreamTimeout `json:"timeout,omitempty" yaml:"timeout,omitempty"`
9796

97+
// Deprecated: this is no longer support on standalone mode.
9898
// The health check configurations for the upstream.
9999
// +kubebuilder:validation:Optional
100100
HealthCheck *HealthCheck `json:"healthCheck,omitempty" yaml:"healthCheck,omitempty"`
@@ -119,6 +119,7 @@ type ApisixUpstreamConfig struct {
119119
// +kubebuilder:validation:Optional
120120
UpstreamHost string `json:"upstreamHost,omitempty" yaml:"upstreamHost,omitempty"`
121121

122+
// Deprecated: this is no longer support on standalone mode.
122123
// Discovery is used to configure service discovery for upstream.
123124
// +kubebuilder:validation:Optional
124125
Discovery *Discovery `json:"discovery,omitempty" yaml:"discovery,omitempty"`

config/crd/bases/apisix.apache.org_apisixupstreams.yaml

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ spec:
4040
description: ApisixUpstreamSpec describes the specification of ApisixUpstream.
4141
properties:
4242
discovery:
43-
description: Discovery is used to configure service discovery for
44-
upstream.
43+
description: |-
44+
Deprecated: this is no longer support on standalone mode.
45+
Discovery is used to configure service discovery for upstream.
4546
properties:
4647
args:
4748
additionalProperties:
@@ -77,7 +78,9 @@ spec:
7778
minItems: 1
7879
type: array
7980
healthCheck:
80-
description: The health check configurations for the upstream.
81+
description: |-
82+
Deprecated: this is no longer support on standalone mode.
83+
The health check configurations for the upstream.
8184
properties:
8285
active:
8386
description: ActiveHealthCheck defines the active kind of upstream
@@ -244,8 +247,9 @@ spec:
244247
them if they are set on the port level.
245248
properties:
246249
discovery:
247-
description: Discovery is used to configure service discovery
248-
for upstream.
250+
description: |-
251+
Deprecated: this is no longer support on standalone mode.
252+
Discovery is used to configure service discovery for upstream.
249253
properties:
250254
args:
251255
additionalProperties:
@@ -260,7 +264,9 @@ spec:
260264
- type
261265
type: object
262266
healthCheck:
263-
description: The health check configurations for the upstream.
267+
description: |-
268+
Deprecated: this is no longer support on standalone mode.
269+
The health check configurations for the upstream.
264270
properties:
265271
active:
266272
description: ActiveHealthCheck defines the active kind of
@@ -555,8 +561,6 @@ spec:
555561
the pass_host is set to rewrite
556562
type: string
557563
type: object
558-
x-kubernetes-validations:
559-
- rule: has(self.subsets) || (has(self.externalNodes)!=has(self.discovery))
560564
status:
561565
description: ApisixStatus is the status report for Apisix ingress Resources
562566
properties:

docs/crd/api.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1334,12 +1334,12 @@ load balancer, health check, etc.
13341334
| `scheme` _string_ | The scheme used to talk with the upstream. Now value can be http, grpc. |
13351335
| `retries` _integer_ | How many times that the proxy (Apache APISIX) should do when errors occur (error, timeout or bad http status codes like 500, 502). |
13361336
| `timeout` _[UpstreamTimeout](#upstreamtimeout)_ | Timeout settings for the read, send and connect to the upstream. |
1337-
| `healthCheck` _[HealthCheck](#healthcheck)_ | The health check configurations for the upstream. |
1337+
| `healthCheck` _[HealthCheck](#healthcheck)_ | Deprecated: this is no longer support on standalone mode. The health check configurations for the upstream. |
13381338
| `tlsSecret` _[ApisixSecret](#apisixsecret)_ | Set the client certificate when connecting to TLS upstream. |
13391339
| `subsets` _[ApisixUpstreamSubset](#apisixupstreamsubset) array_ | Subsets groups the service endpoints by their labels. Usually used to differentiate service versions. |
13401340
| `passHost` _string_ | Configures the host when the request is forwarded to the upstream. Can be one of pass, node or rewrite. |
13411341
| `upstreamHost` _string_ | Specifies the host of the Upstream request. This is only valid if the pass_host is set to rewrite |
1342-
| `discovery` _[Discovery](#discovery)_ | Discovery is used to configure service discovery for upstream. |
1342+
| `discovery` _[Discovery](#discovery)_ | Deprecated: this is no longer support on standalone mode. Discovery is used to configure service discovery for upstream. |
13431343

13441344

13451345
_Appears in:_
@@ -1391,12 +1391,12 @@ ApisixUpstreamSpec describes the specification of ApisixUpstream.
13911391
| `scheme` _string_ | The scheme used to talk with the upstream. Now value can be http, grpc. |
13921392
| `retries` _integer_ | How many times that the proxy (Apache APISIX) should do when errors occur (error, timeout or bad http status codes like 500, 502). |
13931393
| `timeout` _[UpstreamTimeout](#upstreamtimeout)_ | Timeout settings for the read, send and connect to the upstream. |
1394-
| `healthCheck` _[HealthCheck](#healthcheck)_ | The health check configurations for the upstream. |
1394+
| `healthCheck` _[HealthCheck](#healthcheck)_ | Deprecated: this is no longer support on standalone mode. The health check configurations for the upstream. |
13951395
| `tlsSecret` _[ApisixSecret](#apisixsecret)_ | Set the client certificate when connecting to TLS upstream. |
13961396
| `subsets` _[ApisixUpstreamSubset](#apisixupstreamsubset) array_ | Subsets groups the service endpoints by their labels. Usually used to differentiate service versions. |
13971397
| `passHost` _string_ | Configures the host when the request is forwarded to the upstream. Can be one of pass, node or rewrite. |
13981398
| `upstreamHost` _string_ | Specifies the host of the Upstream request. This is only valid if the pass_host is set to rewrite |
1399-
| `discovery` _[Discovery](#discovery)_ | Discovery is used to configure service discovery for upstream. |
1399+
| `discovery` _[Discovery](#discovery)_ | Deprecated: this is no longer support on standalone mode. Discovery is used to configure service discovery for upstream. |
14001400
| `portLevelSettings` _[PortLevelSettings](#portlevelsettings) array_ | |
14011401

14021402

@@ -1560,12 +1560,12 @@ them if they are set on the port level.
15601560
| `scheme` _string_ | The scheme used to talk with the upstream. Now value can be http, grpc. |
15611561
| `retries` _integer_ | How many times that the proxy (Apache APISIX) should do when errors occur (error, timeout or bad http status codes like 500, 502). |
15621562
| `timeout` _[UpstreamTimeout](#upstreamtimeout)_ | Timeout settings for the read, send and connect to the upstream. |
1563-
| `healthCheck` _[HealthCheck](#healthcheck)_ | The health check configurations for the upstream. |
1563+
| `healthCheck` _[HealthCheck](#healthcheck)_ | Deprecated: this is no longer support on standalone mode. The health check configurations for the upstream. |
15641564
| `tlsSecret` _[ApisixSecret](#apisixsecret)_ | Set the client certificate when connecting to TLS upstream. |
15651565
| `subsets` _[ApisixUpstreamSubset](#apisixupstreamsubset) array_ | Subsets groups the service endpoints by their labels. Usually used to differentiate service versions. |
15661566
| `passHost` _string_ | Configures the host when the request is forwarded to the upstream. Can be one of pass, node or rewrite. |
15671567
| `upstreamHost` _string_ | Specifies the host of the Upstream request. This is only valid if the pass_host is set to rewrite |
1568-
| `discovery` _[Discovery](#discovery)_ | Discovery is used to configure service discovery for upstream. |
1568+
| `discovery` _[Discovery](#discovery)_ | Deprecated: this is no longer support on standalone mode. Discovery is used to configure service discovery for upstream. |
15691569
| `port` _integer_ | Port is a Kubernetes Service port, it should be already defined. |
15701570

15711571

internal/provider/adc/translator/apisixupstream.go

Lines changed: 0 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,8 @@ func (t *Translator) translateApisixUpstream(tctx *provider.TranslateContext, au
3232
patchApisixUpstreamBasics,
3333
translateApisixUpstreamScheme,
3434
translateApisixUpstreamLoadBalancer,
35-
translateApisixUpstreamHealthCheck,
3635
translateApisixUpstreamRetriesAndTimeout,
3736
translateApisixUpstreamPassHost,
38-
translateApisixUpstreamDiscovery,
3937
} {
4038
if err = f(au, ups); err != nil {
4139
return
@@ -98,83 +96,6 @@ func translateApisixUpstreamLoadBalancer(au *apiv2.ApisixUpstream, ups *adc.Upst
9896
return nil
9997
}
10098

101-
func translateApisixUpstreamHealthCheck(au *apiv2.ApisixUpstream, ups *adc.Upstream) error {
102-
check := au.Spec.HealthCheck
103-
if check == nil {
104-
return nil
105-
}
106-
107-
ups.Checks = new(adc.UpstreamHealthCheck)
108-
ups.Checks.Active = translateApisixUpstreamHealthCheckActive(check.Active)
109-
110-
if check.Passive != nil {
111-
ups.Checks.Passive = translateApisixUpstreamHealthCheckPassive(check.Passive)
112-
}
113-
114-
return nil
115-
}
116-
117-
func translateApisixUpstreamHealthCheckActive(config *apiv2.ActiveHealthCheck) *adc.UpstreamActiveHealthCheck {
118-
var active adc.UpstreamActiveHealthCheck
119-
120-
active.Type = cmp.Or(config.Type, apiv2.HealthCheckHTTP)
121-
active.Timeout = int(config.Timeout.Seconds())
122-
active.Port = config.Port
123-
active.Concurrency = config.Concurrency
124-
active.Host = config.Host
125-
active.HTTPPath = config.HTTPPath
126-
active.HTTPRequestHeaders = config.RequestHeaders
127-
active.HTTPSVerifyCert = config.StrictTLS != nil && *config.StrictTLS
128-
129-
if config.Healthy != nil {
130-
active.Healthy = adc.UpstreamActiveHealthCheckHealthy{
131-
UpstreamPassiveHealthCheckHealthy: adc.UpstreamPassiveHealthCheckHealthy{
132-
HTTPStatuses: config.Healthy.HTTPCodes,
133-
Successes: config.Healthy.Successes,
134-
},
135-
Interval: int(config.Healthy.Interval.Seconds()),
136-
}
137-
}
138-
139-
if config.Unhealthy != nil {
140-
active.Unhealthy = adc.UpstreamActiveHealthCheckUnhealthy{
141-
UpstreamPassiveHealthCheckUnhealthy: adc.UpstreamPassiveHealthCheckUnhealthy{
142-
HTTPStatuses: config.Unhealthy.HTTPCodes,
143-
HTTPFailures: config.Unhealthy.HTTPFailures,
144-
TCPFailures: config.Unhealthy.TCPFailures,
145-
Timeouts: int(config.Timeout.Seconds()),
146-
},
147-
Interval: int(config.Unhealthy.Interval.Seconds()),
148-
}
149-
}
150-
151-
return &active
152-
}
153-
154-
func translateApisixUpstreamHealthCheckPassive(config *apiv2.PassiveHealthCheck) *adc.UpstreamPassiveHealthCheck {
155-
var passive adc.UpstreamPassiveHealthCheck
156-
157-
passive.Type = cmp.Or(config.Type, apiv2.HealthCheckHTTP)
158-
159-
if config.Healthy != nil {
160-
passive.Healthy = adc.UpstreamPassiveHealthCheckHealthy{
161-
HTTPStatuses: config.Healthy.HTTPCodes,
162-
Successes: config.Healthy.Successes,
163-
}
164-
}
165-
166-
if config.Unhealthy != nil {
167-
passive.Unhealthy = adc.UpstreamPassiveHealthCheckUnhealthy{
168-
HTTPStatuses: config.Unhealthy.HTTPCodes,
169-
HTTPFailures: config.Unhealthy.HTTPFailures,
170-
TCPFailures: config.Unhealthy.TCPFailures,
171-
Timeouts: config.Unhealthy.Timeouts,
172-
}
173-
}
174-
175-
return &passive
176-
}
177-
17899
func translateApisixUpstreamRetriesAndTimeout(au *apiv2.ApisixUpstream, ups *adc.Upstream) error {
179100
retries := au.Spec.Retries
180101
timeout := au.Spec.Timeout
@@ -248,28 +169,11 @@ func translateApisixUpstreamPassHost(au *apiv2.ApisixUpstream, ups *adc.Upstream
248169
return nil
249170
}
250171

251-
func translateApisixUpstreamDiscovery(au *apiv2.ApisixUpstream, ups *adc.Upstream) error {
252-
if au.Spec.Discovery == nil {
253-
return nil
254-
}
255-
256-
ups.ServiceName = au.Spec.Discovery.ServiceName
257-
ups.DiscoveryType = au.Spec.Discovery.Type
258-
ups.DiscoveryArgs = au.Spec.Discovery.Args
259-
ups.Nodes = nil
260-
261-
return nil
262-
}
263-
264172
func composeExternalUpstreamName(au *apiv2.ApisixUpstream) string {
265173
return au.GetGenerateName() + "_" + au.GetName()
266174
}
267175

268176
func translateApisixUpstreamExternalNodes(tctx *provider.TranslateContext, au *apiv2.ApisixUpstream, ups *adc.Upstream) error {
269-
if au.Spec.Discovery != nil {
270-
ups.Nodes = nil
271-
return nil
272-
}
273177
for _, node := range au.Spec.ExternalNodes {
274178
switch node.Type {
275179
case apiv2.ExternalTypeDomain:

test/e2e/apisix/route.go

Lines changed: 0 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -496,123 +496,5 @@ spec:
496496
Eventually(upstreamAddrs).Should(HaveKey(endpoint))
497497
Eventually(upstreamAddrs).Should(HaveKey(clusterIP))
498498
})
499-
500-
PIt("Test Upstream healthcheck", func() {
501-
const apisixRouteSpec = `
502-
apiVersion: apisix.apache.org/v2
503-
kind: ApisixRoute
504-
metadata:
505-
name: default
506-
spec:
507-
ingressClassName: apisix
508-
http:
509-
- name: rule0
510-
match:
511-
paths:
512-
- /*
513-
upstreams:
514-
- name: default-upstream
515-
`
516-
const apisixUpstreamSpec0 = `
517-
apiVersion: apisix.apache.org/v2
518-
kind: ApisixUpstream
519-
metadata:
520-
name: default-upstream
521-
spec:
522-
ingressClassName: apisix
523-
externalNodes:
524-
- type: Domain
525-
name: httpbin-service-e2e-test
526-
`
527-
const apisixUpstreamSpec1 = `
528-
apiVersion: apisix.apache.org/v2
529-
kind: ApisixUpstream
530-
metadata:
531-
name: default-upstream
532-
spec:
533-
ingressClassName: apisix
534-
externalNodes:
535-
- type: Domain
536-
name: httpbin-service-e2e-test
537-
healthCheck:
538-
active:
539-
type: http
540-
httpPath: %s
541-
healthy:
542-
httpCodes: [200]
543-
interval: 1s
544-
unhealthy:
545-
httpFailures: 2
546-
interval: 1s
547-
`
548-
By("apply ApisixRoute")
549-
applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default"}, new(apiv2.ApisixRoute), apisixRouteSpec)
550-
551-
By("apply ApisixUpstream without healthCheck")
552-
applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default-upstream"}, new(apiv2.ApisixUpstream), apisixUpstreamSpec0)
553-
554-
By("verify ApisixRoute and ApisixUpstream works")
555-
request := func() int {
556-
return s.NewAPISIXClient().GET("/get").Expect().Raw().StatusCode
557-
}
558-
Eventually(request).WithTimeout(8 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusOK))
559-
560-
By("apply ApisixUpstream with a healthCheck")
561-
auSpec := fmt.Sprintf(apisixUpstreamSpec1, "/status/200")
562-
applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default-upstream"}, new(apiv2.ApisixUpstream), auSpec)
563-
564-
By("verify ApisixRoute and ApisixUpstream with a healthCheck works")
565-
Eventually(request).WithTimeout(8 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusOK))
566-
567-
By("apply ApisixUpstream with the healthCheck which is always failure")
568-
auSpec = fmt.Sprintf(apisixUpstreamSpec1, "/status/502")
569-
applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default-upstream"}, new(apiv2.ApisixUpstream), auSpec)
570-
571-
// FIXME: can not pass yet
572-
Skip("checks did not sync to the dataplane")
573-
By("verify ApisixRoute and ApisixUpstream works")
574-
Eventually(request).WithTimeout(8 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusServiceUnavailable))
575-
})
576-
577-
PIt("Test discovery", func() {
578-
const apisixRouteSpec = `
579-
apiVersion: apisix.apache.org/v2
580-
kind: ApisixRoute
581-
metadata:
582-
name: default
583-
spec:
584-
ingressClassName: apisix
585-
http:
586-
- name: rule0
587-
match:
588-
paths:
589-
- /*
590-
upstreams:
591-
- name: default-upstream
592-
`
593-
const apisixUpstreamSpec0 = `
594-
apiVersion: apisix.apache.org/v2
595-
kind: ApisixUpstream
596-
metadata:
597-
name: default-upstream
598-
spec:
599-
ingressClassName: apisix
600-
discovery:
601-
type: dns
602-
serviceName: httpbin-service-e2e-test.%s.svc.cluster.local
603-
`
604-
By("apply ApisixRoute")
605-
applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default"}, new(apiv2.ApisixRoute), apisixRouteSpec)
606-
607-
By("apply ApisixUpstream with discovery")
608-
applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default-upstream"}, new(apiv2.ApisixUpstream), fmt.Sprintf(apisixUpstreamSpec0, s.Namespace()))
609-
610-
By("verify ApisixUpstream works")
611-
time.Sleep(time.Hour)
612-
request := func() int {
613-
return s.NewAPISIXClient().GET("/get").Expect().Raw().StatusCode
614-
}
615-
Eventually(request).WithTimeout(8 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusOK))
616-
})
617499
})
618500
})

0 commit comments

Comments
 (0)