Add tcp e2e test

This commit is contained in:
Manuel Alejandro de Brito Fontes 2018-11-16 17:33:56 -03:00
parent 168f30d1ec
commit 654eceda46
No known key found for this signature in database
GPG key ID: 786136016A8BA02A
4 changed files with 110 additions and 4 deletions

View file

@ -801,10 +801,10 @@ func configureDynamically(pcfg *ingress.Configuration, port int, isDynamicCertif
}
defer conn.Close()
var streams []*ingress.Backend
streams := make([]ingress.Backend, 0)
for _, ep := range pcfg.TCPEndpoints {
key := fmt.Sprintf("tcp-%v-%v-%v", ep.Backend.Namespace, ep.Backend.Name, ep.Backend.Port.String())
streams = append(streams, &ingress.Backend{
streams = append(streams, ingress.Backend{
Name: key,
Endpoints: ep.Endpoints,
Port: intstr.FromInt(ep.Port),
@ -812,7 +812,7 @@ func configureDynamically(pcfg *ingress.Configuration, port int, isDynamicCertif
}
for _, ep := range pcfg.UDPEndpoints {
key := fmt.Sprintf("udp-%v-%v-%v", ep.Backend.Namespace, ep.Backend.Name, ep.Backend.Port.String())
streams = append(streams, &ingress.Backend{
streams = append(streams, ingress.Backend{
Name: key,
Endpoints: ep.Endpoints,
Port: intstr.FromInt(ep.Port),
@ -828,7 +828,11 @@ func configureDynamically(pcfg *ingress.Configuration, port int, isDynamicCertif
if err != nil {
return err
}
fmt.Fprintf(conn, "\r\n")
_, err = fmt.Fprintf(conn, "\r\n")
if err != nil {
return err
}
defer conn.Close()
if isDynamicCertificatesEnabled {
err = configureCertificates(pcfg, port)

View file

@ -25,6 +25,10 @@ function _M.call()
return
end
if backends == nil or backends == "" then
return
end
local success, err_conf = tcp_udp_configuration_data:set("backends", backends)
if not success then
ngx.log(ngx.ERR, "dynamic-configuration: error updating configuration: " .. tostring(err_conf))

View file

@ -39,6 +39,7 @@ import (
_ "k8s.io/ingress-nginx/test/e2e/settings"
_ "k8s.io/ingress-nginx/test/e2e/ssl"
_ "k8s.io/ingress-nginx/test/e2e/status"
_ "k8s.io/ingress-nginx/test/e2e/tcpudp"
)
// RunE2ETests checks configuration parameters (specified through flags) and then runs

97
test/e2e/tcpudp/tcp.go Normal file
View file

@ -0,0 +1,97 @@
/*
Copyright 2018 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package settings
import (
"fmt"
"strings"
"github.com/parnurzeal/gorequest"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"k8s.io/ingress-nginx/test/e2e/framework"
)
var _ = framework.IngressNginxDescribe("TCP Feature", func() {
f := framework.NewDefaultFramework("tcp")
BeforeEach(func() {
})
AfterEach(func() {
})
It("should expose a TCP service", func() {
f.NewEchoDeploymentWithReplicas(1)
config, err := f.KubeClientSet.
CoreV1().
ConfigMaps(f.IngressController.Namespace).
Get("tcp-services", metav1.GetOptions{})
Expect(err).To(BeNil(), "unexpected error obtaining tcp-services configmap")
Expect(config).NotTo(BeNil(), "expected a configmap but none returned")
if config.Data == nil {
config.Data = map[string]string{}
}
config.Data["8080"] = fmt.Sprintf("%v/http-svc:80", f.IngressController.Namespace)
_, err = f.KubeClientSet.
CoreV1().
ConfigMaps(f.IngressController.Namespace).
Update(config)
Expect(err).NotTo(HaveOccurred(), "unexpected error updating configmap")
svc, err := f.KubeClientSet.
CoreV1().
Services(f.IngressController.Namespace).
Get("ingress-nginx", metav1.GetOptions{})
Expect(err).To(BeNil(), "unexpected error obtaining ingress-nginx service")
Expect(svc).NotTo(BeNil(), "expected a service but none returned")
svc.Spec.Ports = append(svc.Spec.Ports, corev1.ServicePort{
Name: "http-svc",
Port: 8080,
TargetPort: intstr.FromInt(8080),
})
_, err = f.KubeClientSet.
CoreV1().
Services(f.IngressController.Namespace).
Update(svc)
Expect(err).NotTo(HaveOccurred(), "unexpected error updating service")
f.WaitForNginxConfiguration(
func(cfg string) bool {
return strings.Contains(cfg, fmt.Sprintf(`ngx.var.proxy_upstream_name="tcp-%v-http-svc-80"`, f.IngressController.Namespace))
})
ip := f.GetNginxIP()
port, err := f.GetNginxPort("http-svc")
Expect(err).NotTo(HaveOccurred(), "unexpected error obtaning service port")
resp, _, errs := gorequest.New().
Get(fmt.Sprintf("http://%v:%v", ip, port)).
End()
Expect(len(errs)).Should(BeNumerically("==", 0))
Expect(resp.StatusCode).Should(Equal(200))
})
})