Skip to content

Commit 4817261

Browse files
author
Philipp Hossner
committed
BUG: Make ingress pathType "Exact" always override pathType "Prefix"
1 parent 04d271c commit 4817261

File tree

5 files changed

+31
-13
lines changed

5 files changed

+31
-13
lines changed

deploy/tests/e2e/client.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ func runtimeCommand(command string) (result []byte, err error) {
193193
if err != nil {
194194
return
195195
}
196-
result = make([]byte, 1024)
196+
result = make([]byte, 2048)
197197
_, err = conn.Read(result)
198198
conn.Close()
199199
return
@@ -208,7 +208,7 @@ func GetHAProxyMapCount(mapName string) (count int, err error) {
208208
scanner := bufio.NewScanner(bytes.NewReader(result))
209209
for scanner.Scan() {
210210
line := scanner.Text()
211-
if strings.Contains(line, mapName) {
211+
if strings.Contains(line, mapName+".map") {
212212
r := regexp.MustCompile("entry_cnt=[0-9]*")
213213
match := r.FindString(line)
214214
nbr := strings.Split(match, "=")[1]

deploy/tests/e2e/map-updates/update_test.go

+15-5
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,27 @@ func (suite *MapUpdateSuite) Test_Update() {
3030
suite.tmplData.Paths = append(suite.tmplData.Paths, strconv.Itoa(i))
3131
}
3232
oldInfo, err := e2e.GetGlobalHAProxyInfo()
33-
oldCount, err := e2e.GetHAProxyMapCount("path-prefix")
33+
oldCountExact, err := e2e.GetHAProxyMapCount("path-exact")
34+
suite.Require().NoError(err)
35+
oldCountPrefixExact, err := e2e.GetHAProxyMapCount("path-prefix-exact")
36+
suite.Require().NoError(err)
37+
oldCountPrefix, err := e2e.GetHAProxyMapCount("path-prefix")
3438
suite.Require().NoError(err)
3539
suite.Require().NoError(suite.test.Apply("config/ingress.yaml.tmpl", suite.test.GetNS(), suite.tmplData))
3640
suite.Require().Eventually(func() bool {
3741
newInfo, err := e2e.GetGlobalHAProxyInfo()
3842
suite.Require().NoError(err)
39-
count, err := e2e.GetHAProxyMapCount("path-prefix")
43+
countExact, err := e2e.GetHAProxyMapCount("path-exact")
44+
suite.Require().NoError(err)
45+
countPrefixExact, err := e2e.GetHAProxyMapCount("path-prefix-exact")
46+
suite.Require().NoError(err)
47+
countPrefix, err := e2e.GetHAProxyMapCount("path-prefix")
4048
suite.Require().NoError(err)
41-
numOfAddedEntries := count - oldCount + 1 // We add one because there's already an entry at the begining which will be removed
42-
suite.T().Logf("oldInfo.Pid(%s) == newInfo.Pid(%s) && additional path-prefix.count(%d) == %d", oldInfo.Pid, newInfo.Pid, numOfAddedEntries, n)
43-
return oldInfo.Pid == newInfo.Pid && numOfAddedEntries == n
49+
numOfAddedEntriesExact := countExact - oldCountExact
50+
numOfAddedEntriesPrefixExact := countPrefixExact - oldCountPrefixExact
51+
numOfAddedEntriesPrefix := countPrefix - oldCountPrefix + 1 // We add one because there's already an entry at the beginning which will be removed
52+
suite.T().Logf("oldInfo.Pid(%s) == newInfo.Pid(%s) && additional path-exact.count(%d) == %d && additional path-prefix-exact.count(%d) == %d && additional path-prefix.count(%d) == %d", oldInfo.Pid, newInfo.Pid, numOfAddedEntriesExact, 0, numOfAddedEntriesPrefixExact, n, numOfAddedEntriesPrefix, n)
53+
return oldInfo.Pid == newInfo.Pid && numOfAddedEntriesExact == 0 && numOfAddedEntriesPrefixExact == n && numOfAddedEntriesPrefix == n
4454
}, e2e.WaitDuration, e2e.TickDuration)
4555
})
4656
}

pkg/controller/controller.go

+6
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,12 @@ func (c *HAProxyController) setupHAProxyRules() error {
307307
Scope: "txn",
308308
Expression: fmt.Sprintf("var(txn.host_match),concat(,txn.path,),map(%s)", maps.GetPath(route.PATH_EXACT)),
309309
}, false),
310+
c.haproxy.AddRule(frontend, rules.ReqSetVar{
311+
Name: "path_match",
312+
Scope: "txn",
313+
Expression: fmt.Sprintf("var(txn.host_match),concat(,txn.path,),map(%s)", maps.GetPath(route.PATH_PREFIX_EXACT)),
314+
CondTest: "!{ var(txn.path_match) -m found }",
315+
}, false),
310316
c.haproxy.AddRule(frontend, rules.ReqSetVar{
311317
Name: "path_match",
312318
Scope: "txn",

pkg/haproxy/main.go

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ func New(osArgs utils.OSArgs, env env.Env, cfgFile []byte, p process.Process, cl
5353
route.SNI,
5454
route.HOST,
5555
route.PATH_EXACT,
56+
route.PATH_PREFIX_EXACT,
5657
route.PATH_PREFIX,
5758
}
5859
if h.Maps, err = maps.New(env.MapsDir, persistentMaps); err != nil {

pkg/route/route.go

+7-6
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@ const (
3333
FrontendHTTP = "http"
3434
FrontendHTTPS = "https"
3535
// Routing Maps
36-
SNI maps.Name = "sni"
37-
HOST maps.Name = "host"
38-
PATH_EXACT maps.Name = "path-exact"
39-
PATH_PREFIX maps.Name = "path-prefix"
36+
SNI maps.Name = "sni"
37+
HOST maps.Name = "host"
38+
PATH_EXACT maps.Name = "path-exact"
39+
PATH_PREFIX_EXACT maps.Name = "path-prefix-exact"
40+
PATH_PREFIX maps.Name = "path-prefix"
4041
)
4142

4243
var (
@@ -87,11 +88,11 @@ func AddHostPathRoute(route Route, mapFiles maps.Maps) error {
8788
mapFiles.MapAppend(PATH_PREFIX, route.Host+"/"+"\t\t\t"+value)
8889
case route.Path.PathTypeMatch == store.PATH_TYPE_PREFIX:
8990
path = strings.TrimSuffix(path, "/")
90-
mapFiles.MapAppend(PATH_EXACT, route.Host+path+"\t\t\t"+value)
91+
mapFiles.MapAppend(PATH_PREFIX_EXACT, route.Host+path+"\t\t\t"+value)
9192
mapFiles.MapAppend(PATH_PREFIX, route.Host+path+"/"+"\t\t\t"+value)
9293
case route.Path.PathTypeMatch == store.PATH_TYPE_IMPLEMENTATION_SPECIFIC:
9394
path = strings.TrimSuffix(path, "/")
94-
mapFiles.MapAppend(PATH_EXACT, route.Host+path+"\t\t\t"+value)
95+
mapFiles.MapAppend(PATH_PREFIX_EXACT, route.Host+path+"\t\t\t"+value)
9596
mapFiles.MapAppend(PATH_PREFIX, route.Host+path+"\t\t\t"+value)
9697
default:
9798
return fmt.Errorf("unknown path type '%s' with backend '%s'", route.Path.PathTypeMatch, route.BackendName)

0 commit comments

Comments
 (0)