fix(dockerCompoe): compare srcIP and srcPort of mergeExistingWinPorts()
This commit is contained in:
parent
2c91222753
commit
f8b4fe9af6
@ -856,15 +856,33 @@ func (s *Service) mergeExistingWinPorts(ports []string) {
|
|||||||
case s.Ports == nil && ports == nil:
|
case s.Ports == nil && ports == nil:
|
||||||
return
|
return
|
||||||
default:
|
default:
|
||||||
for _, port := range ports {
|
LOOP:
|
||||||
if len(port) <= 0 {
|
for i := range ports {
|
||||||
continue
|
if len(ports[i]) <= 0 {
|
||||||
|
continue LOOP
|
||||||
}
|
}
|
||||||
|
|
||||||
src, dest, protocol := splitStringInPortMapping(port)
|
newPort := port(ports[i])
|
||||||
if !s.ExistsDestinationPort(dest) {
|
|
||||||
s.SetPort(src, dest, protocol)
|
for j := range s.Ports {
|
||||||
|
existingPort := port(s.Ports[j])
|
||||||
|
switch {
|
||||||
|
case newPort.existsSrcIP() && existingPort.existsSrcIP() &&
|
||||||
|
newPort.getSrc() == existingPort.getSrc():
|
||||||
|
continue LOOP
|
||||||
|
case !newPort.existsSrcIP() && existingPort.existsSrcIP() &&
|
||||||
|
newPort.getSrcPort() == existingPort.getSrcPort():
|
||||||
|
continue LOOP
|
||||||
|
case newPort.existsSrcIP() && !existingPort.existsSrcIP() &&
|
||||||
|
newPort.getSrcPort() == existingPort.getSrcPort():
|
||||||
|
continue LOOP
|
||||||
|
case !newPort.existsSrcIP() && !existingPort.existsSrcIP() &&
|
||||||
|
newPort.getSrcPort() == existingPort.getSrcPort():
|
||||||
|
continue LOOP
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
s.Ports = append(s.Ports, ports[i])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1183,6 +1183,43 @@ func TestService_MergeExistingWin(t *testing.T) {
|
|||||||
Ports: []string{"80:80"},
|
Ports: []string{"80:80"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
serviceDeploymentA: &dockerCompose.Service{
|
||||||
|
Ports: []string{
|
||||||
|
"0.0.0.0:15005:5005/tcp",
|
||||||
|
"0.0.0.0:18080:8080/tcp",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
serviceDeploymentB: &dockerCompose.Service{
|
||||||
|
Ports: []string{"0.0.0.0:6300:6300/tcp"},
|
||||||
|
},
|
||||||
|
expectedService: &dockerCompose.Service{
|
||||||
|
Ports: []string{
|
||||||
|
"0.0.0.0:15005:5005/tcp",
|
||||||
|
"0.0.0.0:18080:8080/tcp",
|
||||||
|
"0.0.0.0:6300:6300/tcp",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
serviceDeploymentA: &dockerCompose.Service{
|
||||||
|
Ports: []string{
|
||||||
|
"0.0.0.0:15005:5005/tcp",
|
||||||
|
"0.0.0.0:18080:8080/tcp",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
serviceDeploymentB: &dockerCompose.Service{
|
||||||
|
Ports: []string{
|
||||||
|
"15005:15005",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expectedService: &dockerCompose.Service{
|
||||||
|
Ports: []string{
|
||||||
|
"0.0.0.0:15005:5005/tcp",
|
||||||
|
"0.0.0.0:18080:8080/tcp",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
// Secrets
|
// Secrets
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user