Skip to content

Commit

Permalink
fix(info.go): omitting wildcard paths from controller cache (argoproj…
Browse files Browse the repository at this point in the history
…#4479)

edge case where /* should not be appended to path
  • Loading branch information
igaskin authored Oct 5, 2020
1 parent 5af0c5a commit 3848f64
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
2 changes: 1 addition & 1 deletion controller/cache/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func populateIngressInfo(un *unstructured.Unstructured, res *ResourceInfo) {

subPath := ""
if nestedPath, ok, err := unstructured.NestedString(path, "path"); ok && err == nil {
subPath = nestedPath
subPath = strings.TrimSuffix(nestedPath, "*")
}
externalURL += subPath
urlsSet[externalURL] = true
Expand Down
55 changes: 55 additions & 0 deletions controller/cache/info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,37 @@ var (
ingress:
- ip: 107.178.210.11`)

testIngressWildCardPath = strToUnstructured(`
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: helm-guestbook
namespace: default
uid: "4"
spec:
backend:
serviceName: not-found-service
servicePort: 443
rules:
- host: helm-guestbook.com
http:
paths:
- backend:
serviceName: helm-guestbook
servicePort: 443
path: /*
- backend:
serviceName: helm-guestbook
servicePort: https
path: /*
tls:
- host: helm-guestbook.com
secretName: my-tls-secret
status:
loadBalancer:
ingress:
- ip: 107.178.210.11`)

testIngressWithoutTls = strToUnstructured(`
apiVersion: extensions/v1beta1
kind: Ingress
Expand Down Expand Up @@ -159,6 +190,30 @@ func TestGetIngressInfo(t *testing.T) {
}, info.NetworkingInfo)
}

func TestGetIngressInfoWildCardPath(t *testing.T) {
info := &ResourceInfo{}
populateNodeInfo(testIngressWildCardPath, info)
assert.Equal(t, 0, len(info.Info))
sort.Slice(info.NetworkingInfo.TargetRefs, func(i, j int) bool {
return strings.Compare(info.NetworkingInfo.TargetRefs[j].Name, info.NetworkingInfo.TargetRefs[i].Name) < 0
})
assert.Equal(t, &v1alpha1.ResourceNetworkingInfo{
Ingress: []v1.LoadBalancerIngress{{IP: "107.178.210.11"}},
TargetRefs: []v1alpha1.ResourceRef{{
Namespace: "default",
Group: "",
Kind: kube.ServiceKind,
Name: "not-found-service",
}, {
Namespace: "default",
Group: "",
Kind: kube.ServiceKind,
Name: "helm-guestbook",
}},
ExternalURLs: []string{"https://helm-guestbook.com/"},
}, info.NetworkingInfo)
}

func TestGetIngressInfoWithoutTls(t *testing.T) {
info := &ResourceInfo{}
populateNodeInfo(testIngressWithoutTls, info)
Expand Down

0 comments on commit 3848f64

Please sign in to comment.