Skip to content

Commit

Permalink
Add tcp e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
aledbf committed Nov 16, 2018
1 parent 168f30d commit 85efafc
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 4 deletions.
12 changes: 8 additions & 4 deletions internal/ingress/controller/nginx.go
Original file line number Diff line number Diff line change
Expand Up @@ -801,18 +801,18 @@ 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),
})
}
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),
Expand All @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions rootfs/etc/nginx/lua/tcp_udp_configuration.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
1 change: 1 addition & 0 deletions test/e2e/e2e.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
97 changes: 97 additions & 0 deletions test/e2e/tcpudp/tcp.go
Original file line number Diff line number Diff line change
@@ -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"
"time"

"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 update status field after client-go reconnection", 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")

time.Sleep(1 * time.Hour)

f.WaitForNginxConfiguration(
func(cfg string) bool {
return strings.Contains(cfg, fmt.Sprintf(`ngx.var.proxy_upstream_name="tcp-%v-echoheaders-80"`, f.IngressController.Namespace))
})

ip := f.GetNginxIP()
resp, _, errs := gorequest.New().
Get(fmt.Sprintf("http://%v:8080", ip)).
End()
Expect(len(errs)).Should(BeNumerically("==", 0))
Expect(resp.StatusCode).Should(Equal(200))
})
})

0 comments on commit 85efafc

Please sign in to comment.