Skip to content

Commit 051a639

Browse files
committed
TEST: Add e2e test for non ready endpoints
In order to test if controller is not using non ready endpoints we do the following in the corresponding e2e test: - Create non ready pods by configuring their readiness probe that to never succeed - Create one healthy pod - Add an HAProxy rule that will return 503 if there is more than one server in the test backend.
1 parent b2586a8 commit 051a639

File tree

4 files changed

+61
-13
lines changed

4 files changed

+61
-13
lines changed

deploy/tests/e2e/endpoints/config/endpoints.yaml.tmpl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ spec:
2222
- name: https
2323
containerPort: 8443
2424
protocol: TCP
25+
{{- if .NotReady}}
26+
readinessProbe:
27+
failureThreshold: 3
28+
periodSeconds: 1
29+
httpGet:
30+
port: 6666
31+
{{- end}}
2532
---
2633
kind: Service
2734
apiVersion: v1
@@ -46,6 +53,11 @@ metadata:
4653
name: http-echo
4754
annotations:
4855
ingress.class: haproxy
56+
{{- if .NotReady}}
57+
check: "false"
58+
backend-config-snippet: |
59+
http-request return status 503 if !{ nbsrv() eq 1 }
60+
{{- end}}
4961
spec:
5062
rules:
5163
- host: {{ .Host }}

deploy/tests/e2e/endpoints/http_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package endpoints
1919
import (
2020
"fmt"
2121
"io/ioutil"
22-
"net/http"
2322

2423
"github.com/haproxytech/kubernetes-ingress/deploy/tests/e2e"
2524
)
@@ -39,7 +38,7 @@ func (suite *EndpointsSuite) Test_HTTP_Reach() {
3938
res, cls, err := suite.client.Do()
4039
suite.NoError(err)
4140
defer cls()
42-
if res.StatusCode == http.StatusOK {
41+
if res.StatusCode == 200 {
4342
body, err := ioutil.ReadAll(res.Body)
4443
if err != nil {
4544
suite.Error(err)
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright 2019 HAProxy Technologies LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
//go:build e2e_sequential
16+
17+
package endpoints
18+
19+
import (
20+
"github.com/haproxytech/kubernetes-ingress/deploy/tests/e2e"
21+
)
22+
23+
func (suite *EndpointsSuite) Test_Non_Ready_Endpoints() {
24+
suite.tmplData.NotReady = true
25+
suite.tmplData.Replicas = 3
26+
suite.NoError(suite.test.Apply("config/endpoints.yaml.tmpl", suite.test.GetNS(), suite.tmplData))
27+
suite.Require().Eventually(func() bool {
28+
res, cls, err := suite.client.Do()
29+
if res == nil {
30+
suite.T().Log(err)
31+
return false
32+
}
33+
defer cls()
34+
return res.StatusCode == 200
35+
}, e2e.WaitDuration, e2e.TickDuration)
36+
}

deploy/tests/e2e/endpoints/suite_test.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ type EndpointsSuite struct {
3535
type tmplData struct {
3636
Replicas int
3737
Host string
38+
NotReady bool
3839
}
3940

4041
func (suite *EndpointsSuite) SetupSuite() {
4142
var err error
4243
suite.test, err = e2e.NewTest()
4344
suite.NoError(err)
4445
suite.tmplData = tmplData{
45-
Replicas: 1,
46-
Host: suite.test.GetNS() + ".test",
46+
Host: suite.test.GetNS() + ".test",
4747
}
4848
}
4949

@@ -62,10 +62,15 @@ func (suite *EndpointsSuite) BeforeTest(suiteName, testName string) {
6262
var err error
6363
test := suite.test
6464
switch testName {
65-
case "Test_HTTP_Reach":
66-
suite.client, err = e2e.NewHTTPClient(suite.tmplData.Host)
65+
case "Test_TCP_Reach":
66+
suite.client, err = e2e.NewHTTPSClient("tcp-service.test", 32766)
6767
suite.NoError(err)
68+
suite.tmplData.Replicas = 4
6869
suite.NoError(test.Apply("config/endpoints.yaml.tmpl", test.GetNS(), suite.tmplData))
70+
suite.NoError(test.Apply("config/tcp.yaml", "", nil))
71+
test.AddTearDown(func() error {
72+
return suite.test.Delete("config/tcp.yaml")
73+
})
6974
suite.Require().Eventually(func() bool {
7075
res, cls, err := suite.client.Do()
7176
if res == nil {
@@ -75,15 +80,11 @@ func (suite *EndpointsSuite) BeforeTest(suiteName, testName string) {
7580
defer cls()
7681
return res.StatusCode == http.StatusOK
7782
}, e2e.WaitDuration, e2e.TickDuration)
78-
case "Test_TCP_Reach":
79-
suite.client, err = e2e.NewHTTPSClient("tcp-service.test", 32766)
83+
default:
84+
suite.client, err = e2e.NewHTTPClient(suite.tmplData.Host)
8085
suite.NoError(err)
81-
suite.tmplData.Replicas = 4
86+
suite.tmplData.Replicas = 1
8287
suite.NoError(test.Apply("config/endpoints.yaml.tmpl", test.GetNS(), suite.tmplData))
83-
suite.NoError(test.Apply("config/tcp.yaml", "", nil))
84-
test.AddTearDown(func() error {
85-
return suite.test.Delete("config/tcp.yaml")
86-
})
8788
suite.Require().Eventually(func() bool {
8889
res, cls, err := suite.client.Do()
8990
if res == nil {

0 commit comments

Comments
 (0)