Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion pkg/ingresscache/ingresscache.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,12 @@ func (ic *IngressCache) Get(host, path string) ([]string, error) {

result, err := ingressHostsTree.Get(path)
if err != nil {
return nil, errors.Wrap(err, "failed to get the targets from the ingress host tree")
// If the specific path lookup fails, retry with root ("/").
// Needed because the trie can’t resolve prefixes when "/" is both delimiter and root path.
result, err = ingressHostsTree.Get("/")
if err != nil {
return nil, errors.Wrap(err, "failed to get the targets from the ingress host tree")
}
}

return result.ToSliceString(), nil
Expand Down
29 changes: 29 additions & 0 deletions pkg/ingresscache/ingresscache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ func (suite *IngressCacheTestSuite) SetupTest() {

func (suite *IngressCacheTestSuite) TestGet() {
suite.T().Parallel()
initialStatePrefixTests := []ingressCacheTestInitialState{
{"example.com", "/", []string{"test-target-name-1"}},
{"example.com", "/path/to", []string{"test-target-name-2"}},
}
for _, testCase := range []struct {
name string
initialState []ingressCacheTestInitialState
Expand Down Expand Up @@ -99,6 +103,31 @@ func (suite *IngressCacheTestSuite) TestGet() {
initialState: []ingressCacheTestInitialState{
{"example.com", "/test/path", []string{"test-target-name-1"}},
},
}, {
name: "Get root path",
args: testIngressCacheArgs{"example.com", "/", []string{"test-target-name-1"}},
expectedResult: []string{"test-target-name-1"},
initialState: initialStatePrefixTests,
}, {
name: "Get root path as closest prefix match",
args: testIngressCacheArgs{"example.com", "/path", []string{"test-target-name-1"}},
expectedResult: []string{"test-target-name-1"},
initialState: initialStatePrefixTests,
}, {
name: "Get root path as closest prefix match with trailing slash",
args: testIngressCacheArgs{"example.com", "/path/", []string{"test-target-name-1"}},
expectedResult: []string{"test-target-name-1"},
initialState: initialStatePrefixTests,
}, {
name: "Get path with exact match",
args: testIngressCacheArgs{"example.com", "/path/to", []string{"test-target-name-2"}},
expectedResult: []string{"test-target-name-2"},
initialState: initialStatePrefixTests,
}, {
name: "Get closest prefix match with a longer path",
args: testIngressCacheArgs{"example.com", "/path/to/another", []string{"test-target-name-2"}},
expectedResult: []string{"test-target-name-2"},
initialState: initialStatePrefixTests,
},
} {
suite.Run(testCase.name, func() {
Expand Down