Fix tests
This commit is contained in:
parent
654eceda46
commit
af2dce901d
5 changed files with 55 additions and 26 deletions
|
@ -64,7 +64,8 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ngxHealthPath = "/healthz"
|
ngxHealthPath = "/healthz"
|
||||||
|
nginxStreamSocket = "/tmp/ingress-stream.sock"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -794,13 +795,6 @@ func configureDynamically(pcfg *ingress.Configuration, port int, isDynamicCertif
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
streamSocket := "/tmp/ingress-stream.sock"
|
|
||||||
conn, err := net.Dial("unix", streamSocket)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer conn.Close()
|
|
||||||
|
|
||||||
streams := make([]ingress.Backend, 0)
|
streams := make([]ingress.Backend, 0)
|
||||||
for _, ep := range pcfg.TCPEndpoints {
|
for _, ep := range pcfg.TCPEndpoints {
|
||||||
key := fmt.Sprintf("tcp-%v-%v-%v", ep.Backend.Namespace, ep.Backend.Name, ep.Backend.Port.String())
|
key := fmt.Sprintf("tcp-%v-%v-%v", ep.Backend.Namespace, ep.Backend.Name, ep.Backend.Port.String())
|
||||||
|
@ -819,6 +813,28 @@ func configureDynamically(pcfg *ingress.Configuration, port int, isDynamicCertif
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = updateStreamConfiguration(streams)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if isDynamicCertificatesEnabled {
|
||||||
|
err = configureCertificates(pcfg, port)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func updateStreamConfiguration(streams []ingress.Backend) error {
|
||||||
|
conn, err := net.Dial("unix", nginxStreamSocket)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer conn.Close()
|
||||||
|
|
||||||
buf, err := json.Marshal(streams)
|
buf, err := json.Marshal(streams)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -832,14 +848,6 @@ func configureDynamically(pcfg *ingress.Configuration, port int, isDynamicCertif
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer conn.Close()
|
|
||||||
|
|
||||||
if isDynamicCertificatesEnabled {
|
|
||||||
err = configureCertificates(pcfg, port)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@ import (
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
jsoniter "github.com/json-iterator/go"
|
jsoniter "github.com/json-iterator/go"
|
||||||
apiv1 "k8s.io/api/core/v1"
|
apiv1 "k8s.io/api/core/v1"
|
||||||
|
@ -146,7 +147,33 @@ func TestIsDynamicConfigurationEnough(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func mockUnixSocket(t *testing.T) net.Listener {
|
||||||
|
l, err := net.Listen("unix", nginxStreamSocket)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("unexpected error creating unix socket: %v", err)
|
||||||
|
}
|
||||||
|
if l == nil {
|
||||||
|
t.Fatalf("expected a listener but none returned")
|
||||||
|
}
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
for {
|
||||||
|
conn, err := l.Accept()
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
time.Sleep(100 * time.Millisecond)
|
||||||
|
defer conn.Close()
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
return l
|
||||||
|
}
|
||||||
func TestConfigureDynamically(t *testing.T) {
|
func TestConfigureDynamically(t *testing.T) {
|
||||||
|
l := mockUnixSocket(t)
|
||||||
|
defer l.Close()
|
||||||
|
|
||||||
target := &apiv1.ObjectReference{}
|
target := &apiv1.ObjectReference{}
|
||||||
|
|
||||||
backends := []*ingress.Backend{{
|
backends := []*ingress.Backend{{
|
||||||
|
|
|
@ -68,6 +68,7 @@ func (c1 *Configuration) Equal(c2 *Configuration) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(c1.UDPEndpoints) != len(c2.UDPEndpoints) {
|
if len(c1.UDPEndpoints) != len(c2.UDPEndpoints) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -83,10 +84,10 @@ func (c1 *Configuration) Equal(c2 *Configuration) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(c1.PassthroughBackends) != len(c2.PassthroughBackends) {
|
if len(c1.PassthroughBackends) != len(c2.PassthroughBackends) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, ptb1 := range c1.PassthroughBackends {
|
for _, ptb1 := range c1.PassthroughBackends {
|
||||||
found := false
|
found := false
|
||||||
for _, ptb2 := range c2.PassthroughBackends {
|
for _, ptb2 := range c2.PassthroughBackends {
|
||||||
|
|
|
@ -148,14 +148,7 @@ function _M.balance()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local ctx = ngx.ctx
|
ngx_balancer.set_more_tries(1)
|
||||||
if not ctx.has_run then
|
|
||||||
ctx.has_run = true
|
|
||||||
local _, err = ngx_balancer.set_more_tries(1)
|
|
||||||
if err then
|
|
||||||
ngx.log(ngx.ERR, "failed to set more tries: ", err)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local ok, err = ngx_balancer.set_current_peer(peer)
|
local ok, err = ngx_balancer.set_current_peer(peer)
|
||||||
if not ok then
|
if not ok then
|
||||||
|
|
|
@ -91,7 +91,7 @@ var _ = framework.IngressNginxDescribe("TCP Feature", func() {
|
||||||
resp, _, errs := gorequest.New().
|
resp, _, errs := gorequest.New().
|
||||||
Get(fmt.Sprintf("http://%v:%v", ip, port)).
|
Get(fmt.Sprintf("http://%v:%v", ip, port)).
|
||||||
End()
|
End()
|
||||||
Expect(len(errs)).Should(BeNumerically("==", 0))
|
Expect(len(errs)).Should(BeEmpty())
|
||||||
Expect(resp.StatusCode).Should(Equal(200))
|
Expect(resp.StatusCode).Should(Equal(200))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue