@@ -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