Fix port duplicate in container spec (#1223)

This commit is contained in:
Hang Yan
2019-12-29 11:32:33 +08:00
committed by GitHub
parent 25337eb82c
commit 0a2fa1a978
8 changed files with 17 additions and 13 deletions
+6 -1
View File
@@ -547,8 +547,12 @@ func (k *Kubernetes) CreatePVC(name string, mode string, size string, selectorVa
// ConfigPorts configures the container ports.
func (k *Kubernetes) ConfigPorts(name string, service kobject.ServiceConfig) []api.ContainerPort {
ports := []api.ContainerPort{}
exist := map[string]bool{}
for _, port := range service.Port {
// temp use as an id
if exist[string(port.ContainerPort)+string(port.Protocol)] {
continue
}
// If the default is already TCP, no need to include it.
if port.Protocol == api.ProtocolTCP {
ports = append(ports, api.ContainerPort{
@@ -562,6 +566,7 @@ func (k *Kubernetes) ConfigPorts(name string, service kobject.ServiceConfig) []a
HostIP: port.HostIP,
})
}
exist[string(port.ContainerPort)+string(port.Protocol)] = true
}