Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
kahootali authored Dec 31, 2018
2 parents 90180f1 + e28bfe2 commit 4b546ad
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 13 deletions.
28 changes: 25 additions & 3 deletions pkg/kube/wrappers/ingress-wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"log"
"net/url"
"path"
"reflect"
"strings"

"github.com/stakater/IngressMonitorController/pkg/constants"
"k8s.io/api/extensions/v1beta1"
Expand Down Expand Up @@ -56,14 +58,30 @@ func (iw *IngressWrapper) getIngressSubPathWithPort() string {
port := iw.getIngressPort()
subPath := iw.getIngressSubPath()

return port + subPath
if port != "" {
if subPath != "" {
return port + subPath
} else {
return port + "/"
}
} else {
if subPath != "" {
return subPath
} else {
return ""
}
}
}

func (iw *IngressWrapper) getIngressPort() string {
rule := iw.Ingress.Spec.Rules[0]
if rule.HTTP != nil {
if rule.HTTP.Paths != nil && len(rule.HTTP.Paths) > 0 {
return rule.HTTP.Paths[0].Backend.ServicePort.StrVal
if reflect.TypeOf(rule.HTTP.Paths[0].Backend.ServicePort).Kind() == reflect.String {
return ""
} else {
return rule.HTTP.Paths[0].Backend.ServicePort.StrVal
}
}
}
return ""
Expand All @@ -73,7 +91,11 @@ func (iw *IngressWrapper) getIngressSubPath() string {
rule := iw.Ingress.Spec.Rules[0]
if rule.HTTP != nil {
if rule.HTTP.Paths != nil && len(rule.HTTP.Paths) > 0 {
return rule.HTTP.Paths[0].Path
if strings.ContainsAny(rule.HTTP.Paths[0].Path, "*") {
return strings.TrimRight(rule.HTTP.Paths[0].Path, "*")
} else {
return rule.HTTP.Paths[0].Path
}
}
}
return ""
Expand Down
16 changes: 12 additions & 4 deletions pkg/kube/wrappers/ingress-wrapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

const (
testUrl = "testurl.stackator.com/"
testUrl = "testurl.stackator.com"
)

func createIngressObjectWithPath(ingressName string, namespace string, url string, path string) *v1beta1.Ingress {
Expand Down Expand Up @@ -72,7 +72,7 @@ func TestIngressWrapper_getURL(t *testing.T) {
namespace: "test",
kubeClient: getTestKubeClient(),
},
want: "http://testurl.stackator.com/",
want: "http://testurl.stackator.com",
},
{
name: "TestGetUrlWithForceHTTPSAnnotation",
Expand All @@ -81,7 +81,7 @@ func TestIngressWrapper_getURL(t *testing.T) {
namespace: "test",
kubeClient: getTestKubeClient(),
},
want: "https://testurl.stackator.com/",
want: "https://testurl.stackator.com",
},
{
name: "TestGetUrlWithForceHTTPSAnnotationOff",
Expand All @@ -90,7 +90,7 @@ func TestIngressWrapper_getURL(t *testing.T) {
namespace: "test",
kubeClient: getTestKubeClient(),
},
want: "http://testurl.stackator.com/",
want: "http://testurl.stackator.com",
},
{
name: "TestGetUrlWithOverridePathAnnotation",
Expand All @@ -100,6 +100,14 @@ func TestIngressWrapper_getURL(t *testing.T) {
kubeClient: getTestKubeClient(),
},
want: "http://testurl.stackator.com/overriden-path",
}, {
name: "TestGetUrlWithWildCardInPath",
fields: fields{
ingress: createIngressObjectWithPath("testIngress", "test", testUrl, "/*"),
namespace: "test",
kubeClient: getTestKubeClient(),
},
want: "http://testurl.stackator.com/",
},
}
for _, tt := range tests {
Expand Down
16 changes: 10 additions & 6 deletions pkg/kube/wrappers/routeWrapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import (
"k8s.io/client-go/kubernetes"
)

const (
routeTestUrl = "testurl.stackator.com/"
)

func createRouteObjectWithPath(routeName string, namespace string, url string, path string) *routev1.Route {
route := util.CreateRouteObject(routeName, namespace, url)
route.Spec.Path = path
Expand Down Expand Up @@ -35,7 +39,7 @@ func TestRouteWrapper_getURL(t *testing.T) {
{
name: "TestGetUrlWithEmptyPath",
fields: fields{
route: createRouteObjectWithPath("testRoute", "test", testUrl, "/"),
route: createRouteObjectWithPath("testRoute", "test", routeTestUrl, "/"),
namespace: "test",
kubeClient: getTestKubeClient(),
},
Expand All @@ -44,7 +48,7 @@ func TestRouteWrapper_getURL(t *testing.T) {
{
name: "TestGetUrlWithHelloPath",
fields: fields{
route: createRouteObjectWithPath("testRoute", "test", testUrl, "/hello"),
route: createRouteObjectWithPath("testRoute", "test", routeTestUrl, "/hello"),
namespace: "test",
kubeClient: getTestKubeClient(),
},
Expand All @@ -53,7 +57,7 @@ func TestRouteWrapper_getURL(t *testing.T) {
{
name: "TestGetUrlWithNoPath",
fields: fields{
route: util.CreateRouteObject("testRoute", "test", testUrl),
route: util.CreateRouteObject("testRoute", "test", routeTestUrl),
namespace: "test",
kubeClient: getTestKubeClient(),
},
Expand All @@ -62,7 +66,7 @@ func TestRouteWrapper_getURL(t *testing.T) {
{
name: "TestGetUrlWithForceHTTPSAnnotation",
fields: fields{
route: createRouteObjectWithAnnotations("testRoute", "test", testUrl, map[string]string{"monitor.stakater.com/forceHttps": "true"}),
route: createRouteObjectWithAnnotations("testRoute", "test", routeTestUrl, map[string]string{"monitor.stakater.com/forceHttps": "true"}),
namespace: "test",
kubeClient: getTestKubeClient(),
},
Expand All @@ -71,7 +75,7 @@ func TestRouteWrapper_getURL(t *testing.T) {
{
name: "TestGetUrlWithForceHTTPSAnnotationOff",
fields: fields{
route: createRouteObjectWithAnnotations("testRoute", "test", testUrl, map[string]string{"monitor.stakater.com/forceHttps": "false"}),
route: createRouteObjectWithAnnotations("testRoute", "test", routeTestUrl, map[string]string{"monitor.stakater.com/forceHttps": "false"}),
namespace: "test",
kubeClient: getTestKubeClient(),
},
Expand All @@ -80,7 +84,7 @@ func TestRouteWrapper_getURL(t *testing.T) {
{
name: "TestGetUrlWithOverridePathAnnotation",
fields: fields{
route: createRouteObjectWithAnnotations("testRoute", "test", testUrl, map[string]string{"monitor.stakater.com/overridePath": "/overriden-path"}),
route: createRouteObjectWithAnnotations("testRoute", "test", routeTestUrl, map[string]string{"monitor.stakater.com/overridePath": "/overriden-path"}),
namespace: "test",
kubeClient: getTestKubeClient(),
},
Expand Down

0 comments on commit 4b546ad

Please sign in to comment.