Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aledbf committed Nov 16, 2018
1 parent 85efafc commit 49b0e24
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 16 deletions.
39 changes: 24 additions & 15 deletions internal/ingress/controller/nginx.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ import (
)

const (
ngxHealthPath = "/healthz"
ngxHealthPath = "/healthz"
nginxStreamSocket = "/tmp/ingress-stream.sock"
)

var (
Expand Down Expand Up @@ -794,13 +795,6 @@ func configureDynamically(pcfg *ingress.Configuration, port int, isDynamicCertif
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)
for _, ep := range pcfg.TCPEndpoints {
key := fmt.Sprintf("tcp-%v-%v-%v", ep.Backend.Namespace, ep.Backend.Name, ep.Backend.Port.String())
Expand All @@ -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)
if err != nil {
return err
Expand All @@ -834,13 +850,6 @@ func configureDynamically(pcfg *ingress.Configuration, port int, isDynamicCertif
}
defer conn.Close()

if isDynamicCertificatesEnabled {
err = configureCertificates(pcfg, port)
if err != nil {
return err
}
}

return nil
}

Expand Down
24 changes: 23 additions & 1 deletion internal/ingress/controller/nginx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"net/http/httptest"
"strings"
"testing"
"time"

jsoniter "github.com/json-iterator/go"
apiv1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -147,6 +148,27 @@ func TestIsDynamicConfigurationEnough(t *testing.T) {
}

func TestConfigureDynamically(t *testing.T) {
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")
}
defer l.Close()

go func() {
for {
conn, err := l.Accept()
if err != nil {
continue
}

time.Sleep(100 * time.Millisecond)
defer conn.Close()
}
}()

target := &apiv1.ObjectReference{}

backends := []*ingress.Backend{{
Expand Down Expand Up @@ -207,7 +229,7 @@ func TestConfigureDynamically(t *testing.T) {
port := ts.Listener.Addr().(*net.TCPAddr).Port
defer ts.Close()

err := configureDynamically(commonConfig, port, false)
err = configureDynamically(commonConfig, port, false)
if err != nil {
t.Errorf("unexpected error posting dynamic configuration: %v", err)
}
Expand Down

0 comments on commit 49b0e24

Please sign in to comment.