Skip to content

Commit

Permalink
Adding back the function getIngressPort() with some minor changes and…
Browse files Browse the repository at this point in the history
… updating the function GetURL() to accomodate the port as <hostname>:<port>/<paths>
  • Loading branch information
ChandraPrakash committed Nov 22, 2018
1 parent 7bc7e9b commit c34462c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
28 changes: 18 additions & 10 deletions pkg/kube/wrappers/ingress-wrapper.go
Expand Up @@ -5,6 +5,7 @@ import (
"net/url"
"path"
"strings"
"reflect"

"github.com/stakater/IngressMonitorController/pkg/constants"
"k8s.io/api/extensions/v1beta1"
Expand Down Expand Up @@ -60,15 +61,20 @@ func (iw *IngressWrapper) getIngressSubPathWithPort() string {
return port + subPath
}

// 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
// }
// }
// 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 {
if reflect.TypeOf(rule.HTTP.Paths[0].Backend.ServicePort) == "string" {
return "80"
}
else {
return rule.HTTP.Paths[0].Backend.ServicePort.StrVal
}
}
}
return ""
}

func (iw *IngressWrapper) getIngressSubPath() string {
rule := iw.Ingress.Spec.Rules[0]
Expand Down Expand Up @@ -113,7 +119,9 @@ func (iw *IngressWrapper) GetURL() string {
u.Path = value
} else {
// Append port + ingressSubPath
u.Path = path.Join(u.Path, iw.getIngressSubPathWithPort())
ingressSubPathWithPort := iw.getIngressSubPathWithPort()
u.Path = u.Path + ":" + strings.Split(ingressSubPathWithPort, "/")[0]
u.Path = path.Join(u.Path, strings.Join(strings.Split(iw,getIngressSubPathWithPort(), "/")[1:], "/"))

// Find pod by backtracking ingress -> service -> pod
healthEndpoint, exists := iw.tryGetHealthEndpointFromIngress()
Expand Down
10 changes: 9 additions & 1 deletion pkg/kube/wrappers/ingress-wrapper_test.go
Expand Up @@ -100,7 +100,15 @@ 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 {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit c34462c

Please sign in to comment.