Skip to content

Commit c13d74f

Browse files
committed
fix merging ports
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent 938b039 commit c13d74f

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

loader/merge.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,21 @@ func toServicePortConfigsMap(s interface{}) (map[interface{}]interface{}, error)
147147
return nil, errors.Errorf("not a servicePortConfig slice: %v", s)
148148
}
149149
m := map[interface{}]interface{}{}
150+
type port struct {
151+
target uint32
152+
published uint32
153+
ip string
154+
protocol string
155+
}
156+
150157
for _, p := range ports {
151-
k := p.Published
152-
if k == 0 {
153-
k = p.Target
158+
mergeKey := port{
159+
target: p.Target,
160+
published: p.Published,
161+
ip: p.HostIP,
162+
protocol: p.Protocol,
154163
}
155-
m[k] = p
164+
m[mergeKey] = p
156165
}
157166
return m, nil
158167
}

loader/merge_test.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -286,24 +286,30 @@ func TestLoadMultipleServicePorts(t *testing.T) {
286286
},
287287
},
288288
{
289-
name: "override_same_published",
289+
name: "override_distinct_protocols",
290290
portBase: map[string]interface{}{
291291
"ports": []interface{}{
292-
"8080:80",
292+
"8080:80/tcp",
293293
},
294294
},
295295
portOverride: map[string]interface{}{
296296
"ports": []interface{}{
297-
"8080:81",
297+
"8080:80/udp",
298298
},
299299
},
300300
expected: []types.ServicePortConfig{
301301
{
302302
Mode: "ingress",
303303
Published: 8080,
304-
Target: 81,
304+
Target: 80,
305305
Protocol: "tcp",
306306
},
307+
{
308+
Mode: "ingress",
309+
Published: 8080,
310+
Target: 80,
311+
Protocol: "udp",
312+
},
307313
},
308314
},
309315
{
@@ -947,6 +953,12 @@ func TestLoadMultipleConfigs(t *testing.T) {
947953
},
948954
},
949955
Ports: []types.ServicePortConfig{
956+
{
957+
Mode: "ingress",
958+
Target: 80,
959+
Published: 8080,
960+
Protocol: "tcp",
961+
},
950962
{
951963
Target: 81,
952964
Published: 8080,

0 commit comments

Comments
 (0)