Skip to content

Commit 1f4dea4

Browse files
committed
more tests
1 parent 59f73c8 commit 1f4dea4

File tree

5 files changed

+127
-11
lines changed

5 files changed

+127
-11
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" yaml:"nodes"`
200+
Nodes UpstreamNodes `json:"nodes,omitempty" yaml:"nodes,omitempty"`
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 & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,8 @@ type ApisixUpstreamSubset struct {
166166
// Discovery defines Service discovery related configuration.
167167
type Discovery struct {
168168
ServiceName string `json:"serviceName" yaml:"serviceName"`
169-
// +kubebuilder:validation:Enum=kubernetes;nacos;
170-
Type string `json:"type" yaml:"type"`
169+
Type string `json:"type" yaml:"type"`
170+
// +kubebuilder:validation:Optional
171171
Args map[string]string `json:"args,omitempty" yaml:"args,omitempty"`
172172
}
173173

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,6 @@ spec:
5050
serviceName:
5151
type: string
5252
type:
53-
enum:
54-
- kubernetes
55-
- nacos
5653
type: string
5754
required:
5855
- serviceName
@@ -257,9 +254,6 @@ spec:
257254
serviceName:
258255
type: string
259256
type:
260-
enum:
261-
- kubernetes
262-
- nacos
263257
type: string
264258
required:
265259
- serviceName

internal/provider/adc/translator/apisixupstream.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ func translateApisixUpstreamDiscovery(au *apiv2.ApisixUpstream, ups *adc.Upstrea
256256
ups.ServiceName = au.Spec.Discovery.ServiceName
257257
ups.DiscoveryType = au.Spec.Discovery.Type
258258
ups.DiscoveryArgs = au.Spec.Discovery.Args
259+
ups.Nodes = nil
259260

260261
return nil
261262
}
@@ -265,6 +266,10 @@ func composeExternalUpstreamName(au *apiv2.ApisixUpstream) string {
265266
}
266267

267268
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+
}
268273
for _, node := range au.Spec.ExternalNodes {
269274
switch node.Type {
270275
case apiv2.ExternalTypeDomain:

test/e2e/apisix/route.go

Lines changed: 119 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,8 +408,7 @@ spec:
408408
Expect(err).ShouldNot(HaveOccurred(), "apply service")
409409
applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default-upstream"}, new(apiv2.ApisixUpstream), apisixUpstreamSpec0)
410410

411-
var apisxiRoute apiv2.ApisixRoute
412-
applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default"}, &apisxiRoute, apisixRouteSpec)
411+
applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default"}, new(apiv2.ApisixRoute), apisixRouteSpec)
413412

414413
By("verify that the ApisixUpstream reference a Service which is not ExternalName should not request OK")
415414
request := func(path string) int {
@@ -497,5 +496,123 @@ spec:
497496
Eventually(upstreamAddrs).Should(HaveKey(endpoint))
498497
Eventually(upstreamAddrs).Should(HaveKey(clusterIP))
499498
})
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+
})
500617
})
501618
})

0 commit comments

Comments
 (0)