Skip to content

Commit 01b3274

Browse files
authored
[DLX] Support root path when resolving URL (#81)
### 📝 Description This PR handles the case where the closest common prefix of a request and the existing ingress is the root path (i.e. `\`). --- ### 🛠️ Changes Made - Add a retry Get with the root as a path --- ### ✅ Checklist - [x] I have tested the changes in this PR --- ### 🧪 Testing - Dev QA - Verified on my setup: a function with ingress / was successfully scaled from zero when invoked with /a/b (screenshot attached). - Added unit tests for all scenarios outlined in the HLD, which also validate this fix. --- ### 🔗 References - Ticket link: https://iguazio.atlassian.net/browse/NUC-596 - Design docs links: https://iguazio.atlassian.net/wiki/spaces/PLAT/pages/372080641/DLX+decoupling+ingress-nginx+annotations+HLD#Create-in-memory-cache - External links: --- ### 🚨 Breaking Changes? - [ ] Yes (explain below) - [x] No <!-- If yes, describe what needs to be changed downstream: --> --- ### 🔍️ Additional Notes - Nuclio should be updated once this CR will be merged and tagged ### 📸 Screenshots / Logs <img width="1934" height="948" alt="image" src="https://github.com/user-attachments/assets/aa794829-8a6a-4e95-a413-dc5a905225a4" />
1 parent 134e0b6 commit 01b3274

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

pkg/ingresscache/ingresscache.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,12 @@ func (ic *IngressCache) Get(host, path string) ([]string, error) {
100100

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

106111
return result.ToSliceString(), nil

pkg/ingresscache/ingresscache_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ func (suite *IngressCacheTestSuite) SetupTest() {
5353

5454
func (suite *IngressCacheTestSuite) TestGet() {
5555
suite.T().Parallel()
56+
initialStatePrefixTests := []ingressCacheTestInitialState{
57+
{"example.com", "/", []string{"test-target-name-1"}},
58+
{"example.com", "/path/to", []string{"test-target-name-2"}},
59+
}
5660
for _, testCase := range []struct {
5761
name string
5862
initialState []ingressCacheTestInitialState
@@ -99,6 +103,31 @@ func (suite *IngressCacheTestSuite) TestGet() {
99103
initialState: []ingressCacheTestInitialState{
100104
{"example.com", "/test/path", []string{"test-target-name-1"}},
101105
},
106+
}, {
107+
name: "Get root path",
108+
args: testIngressCacheArgs{"example.com", "/", []string{"test-target-name-1"}},
109+
expectedResult: []string{"test-target-name-1"},
110+
initialState: initialStatePrefixTests,
111+
}, {
112+
name: "Get root path as closest prefix match",
113+
args: testIngressCacheArgs{"example.com", "/path", []string{"test-target-name-1"}},
114+
expectedResult: []string{"test-target-name-1"},
115+
initialState: initialStatePrefixTests,
116+
}, {
117+
name: "Get root path as closest prefix match with trailing slash",
118+
args: testIngressCacheArgs{"example.com", "/path/", []string{"test-target-name-1"}},
119+
expectedResult: []string{"test-target-name-1"},
120+
initialState: initialStatePrefixTests,
121+
}, {
122+
name: "Get path with exact match",
123+
args: testIngressCacheArgs{"example.com", "/path/to", []string{"test-target-name-2"}},
124+
expectedResult: []string{"test-target-name-2"},
125+
initialState: initialStatePrefixTests,
126+
}, {
127+
name: "Get closest prefix match with a longer path",
128+
args: testIngressCacheArgs{"example.com", "/path/to/another", []string{"test-target-name-2"}},
129+
expectedResult: []string{"test-target-name-2"},
130+
initialState: initialStatePrefixTests,
102131
},
103132
} {
104133
suite.Run(testCase.name, func() {

0 commit comments

Comments
 (0)