You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by to...@apache.org on 2021/05/20 13:12:15 UTC
[apisix-ingress-controller] branch master updated: test: add basic
headless service e2e test (#466)
This is an automated email from the ASF dual-hosted git repository.
tokers pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix-ingress-controller.git
The following commit(s) were added to refs/heads/master by this push:
new 269cf07 test: add basic headless service e2e test (#466)
269cf07 is described below
commit 269cf07020cac239aac5e7d7334bc63305e740fb
Author: Sarasa Kisaragi <li...@gmail.com>
AuthorDate: Thu May 20 21:12:05 2021 +0800
test: add basic headless service e2e test (#466)
Signed-off-by: Ling Samuel <li...@gmail.com>
---
test/e2e/ingress/ingress.go | 108 +++++++++++++++++++++++++++++++++++++++++++-
test/e2e/scaffold/k8s.go | 5 ++
2 files changed, 112 insertions(+), 1 deletion(-)
diff --git a/test/e2e/ingress/ingress.go b/test/e2e/ingress/ingress.go
index a738bf6..9178637 100644
--- a/test/e2e/ingress/ingress.go
+++ b/test/e2e/ingress/ingress.go
@@ -22,7 +22,8 @@ import (
"github.com/stretchr/testify/assert"
"github.com/apache/apisix-ingress-controller/test/e2e/scaffold"
- "github.com/onsi/ginkgo"
+ ginkgo "github.com/onsi/ginkgo"
+ corev1 "k8s.io/api/core/v1"
)
var _ = ginkgo.Describe("support ingress.networking/v1", func() {
@@ -226,3 +227,108 @@ spec:
_ = s.NewAPISIXClient().GET("/status/200").WithHeader("Host", "a.httpbin.org").Expect().Status(http.StatusNotFound)
})
})
+
+var _ = ginkgo.Describe("support ingress.networking/v1 with headless service backend", func() {
+ s := scaffold.NewDefaultScaffold()
+
+ const _httpHeadlessService = `
+apiVersion: v1
+kind: Service
+metadata:
+ name: httpbin-headless-service-e2e-test
+spec:
+ selector:
+ app: httpbin-deployment-e2e-test
+ ports:
+ - name: http
+ port: 80
+ protocol: TCP
+ targetPort: 80
+ type: ClusterIP
+ clusterIP: None
+`
+
+ var (
+ backendSvc string
+ backendPort []int32
+ )
+ ginkgo.BeforeEach(func() {
+ err := s.CreateResourceFromString(_httpHeadlessService)
+ assert.Nil(ginkgo.GinkgoT(), err, "creating headless service")
+ svc, err := s.GetServiceByName("httpbin-headless-service-e2e-test")
+ assert.Nil(ginkgo.GinkgoT(), err, "get headless service")
+ getSvcNameAndPorts := func(svc *corev1.Service) (string, []int32) {
+ var ports []int32
+ for _, p := range svc.Spec.Ports {
+ ports = append(ports, p.Port)
+ }
+ return svc.Name, ports
+ }
+
+ backendSvc, backendPort = getSvcNameAndPorts(svc)
+ })
+
+ ginkgo.It("path exact match", func() {
+ ing := fmt.Sprintf(`
+apiVersion: networking.k8s.io/v1
+kind: Ingress
+metadata:
+ annotations:
+ kubernetes.io/ingress.class: apisix
+ name: ingress-v1
+spec:
+ rules:
+ - host: httpbin.org
+ http:
+ paths:
+ - path: /ip
+ pathType: Exact
+ backend:
+ service:
+ name: %s
+ port:
+ number: %d
+`, backendSvc, backendPort[0])
+ err := s.CreateResourceFromString(ing)
+ assert.Nil(ginkgo.GinkgoT(), err, "creating ingress")
+ time.Sleep(5 * time.Second)
+
+ _ = s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.org").Expect().Status(http.StatusOK)
+ // Exact path, doesn't match /ip/aha
+ _ = s.NewAPISIXClient().GET("/ip/aha").WithHeader("Host", "httpbin.org").Expect().Status(http.StatusNotFound)
+ // Mismatched host
+ _ = s.NewAPISIXClient().GET("/ip/aha").WithHeader("Host", "a.httpbin.org").Expect().Status(http.StatusNotFound)
+ })
+
+ ginkgo.It("path prefix match", func() {
+ ing := fmt.Sprintf(`
+apiVersion: networking.k8s.io/v1
+kind: Ingress
+metadata:
+ annotations:
+ kubernetes.io/ingress.class: apisix
+ name: ingress-v1
+spec:
+ rules:
+ - host: httpbin.org
+ http:
+ paths:
+ - path: /status
+ pathType: Prefix
+ backend:
+ service:
+ name: %s
+ port:
+ number: %d
+`, backendSvc, backendPort[0])
+ err := s.CreateResourceFromString(ing)
+ assert.Nil(ginkgo.GinkgoT(), err, "creating ingress")
+ time.Sleep(5 * time.Second)
+
+ _ = s.NewAPISIXClient().GET("/status/500").WithHeader("Host", "httpbin.org").Expect().Status(http.StatusInternalServerError)
+ _ = s.NewAPISIXClient().GET("/status/504").WithHeader("Host", "httpbin.org").Expect().Status(http.StatusGatewayTimeout)
+ _ = s.NewAPISIXClient().GET("/statusaaa").WithHeader("Host", "httpbin.org").Expect().Status(http.StatusNotFound).Body().Contains("404 Route Not Found")
+ // Mismatched host
+ _ = s.NewAPISIXClient().GET("/status/200").WithHeader("Host", "a.httpbin.org").Expect().Status(http.StatusNotFound)
+ })
+})
diff --git a/test/e2e/scaffold/k8s.go b/test/e2e/scaffold/k8s.go
index 1c80f55..8e3676d 100644
--- a/test/e2e/scaffold/k8s.go
+++ b/test/e2e/scaffold/k8s.go
@@ -27,6 +27,7 @@ import (
"github.com/gruntwork-io/terratest/modules/k8s"
"github.com/onsi/ginkgo"
"github.com/stretchr/testify/assert"
+ corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"
)
@@ -101,6 +102,10 @@ func (s *Scaffold) RemoveResourceByString(yaml string) error {
return k8s.KubectlDeleteFromStringE(s.t, s.kubectlOptions, yaml)
}
+func (s *Scaffold) GetServiceByName(name string) (*corev1.Service, error) {
+ return k8s.GetServiceE(s.t, s.kubectlOptions, name)
+}
+
// CreateResourceFromStringWithNamespace creates resource from a loaded yaml string
// and sets its namespace to the specified one.
func (s *Scaffold) CreateResourceFromStringWithNamespace(yaml, namespace string) error {