Skip to content

Commit 04b436f

Browse files
committed
Merge pull request #14 from finn-no/handle-missing-path
Handle missing Path in HTTPIngressPath
2 parents 4b57637 + 5f0c332 commit 04b436f

File tree

4 files changed

+42
-2
lines changed

4 files changed

+42
-2
lines changed

nginx-controller/Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ PREFIX = nginxdemos/nginx-ingress
66
nginx-ingress:
77
CGO_ENABLED=0 GOOS=linux godep go build -a -installsuffix cgo -ldflags '-w' -o nginx-ingress *.go
88

9-
container: nginx-ingress
9+
test:
10+
godep go test ./...
11+
12+
container: nginx-ingress test
1013
docker build -t $(PREFIX):$(TAG) .
1114

1215
push: container

nginx-controller/controller/controller.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ func (lbc *LoadBalancerController) updateNGINX(name string, ing *extensions.Ingr
317317
var locations []nginx.Location
318318

319319
for _, path := range rule.HTTP.Paths {
320-
loc := nginx.Location{Path: path.Path}
320+
loc := nginx.Location{Path: pathOrDefault(path.Path)}
321321
upsName := getNameForUpstream(ing, rule.Host, path.Backend.ServiceName)
322322

323323
if ups, ok := upstreams[upsName]; ok {
@@ -333,6 +333,14 @@ func (lbc *LoadBalancerController) updateNGINX(name string, ing *extensions.Ingr
333333
lbc.nginx.AddOrUpdateIngress(name, nginx.IngressNGINXConfig{Upstreams: upstreamMapToSlice(upstreams), Servers: servers})
334334
}
335335

336+
func pathOrDefault(path string) string {
337+
if path == "" {
338+
return "/"
339+
} else {
340+
return path
341+
}
342+
}
343+
336344
func endpointsToUpstreamServers(endps api.Endpoints, servicePort int) []nginx.UpstreamServer {
337345
var upsServers []nginx.UpstreamServer
338346
for _, subset := range endps.Subsets {
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package controller
2+
3+
import (
4+
"testing"
5+
)
6+
7+
func TestPathOrDefaultReturnDefault(t *testing.T) {
8+
path := ""
9+
expected := "/"
10+
if pathOrDefault(path) != expected {
11+
t.Errorf("pathOrDefault(%q) should return %q", path, expected)
12+
}
13+
}
14+
15+
func TestPathOrDefaultReturnActual(t *testing.T) {
16+
path := "/path/to/resource"
17+
if pathOrDefault(path) != path {
18+
t.Errorf("pathOrDefault(%q) should return %q", path, path)
19+
}
20+
}

nginx-controller/nginx/nginx.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package nginx
22

33
import (
4+
"bytes"
45
"html/template"
56
"os"
67
"os/exec"
@@ -180,16 +181,24 @@ func (nginx *NGINXController) createCertsDir() {
180181
}
181182

182183
func shellOut(cmd string) {
184+
var stdout bytes.Buffer
185+
var stderr bytes.Buffer
186+
183187
glog.Infof("executing %s", cmd)
184188

185189
command := exec.Command("sh", "-c", cmd)
190+
command.Stdout = &stdout
191+
command.Stderr = &stderr
192+
186193
err := command.Start()
187194
if err != nil {
188195
glog.Fatalf("Failed to execute %v, err: %v", cmd, err)
189196
}
190197

191198
err = command.Wait()
192199
if err != nil {
200+
glog.Errorf("Command %v stdout: %q", cmd, stdout.String())
201+
glog.Errorf("Command %v stderr: %q", cmd, stderr.String())
193202
glog.Fatalf("Command %v finished with error: %v", cmd, err)
194203
}
195204
}

0 commit comments

Comments
 (0)