diff --git a/pkg/transformer/kubernetes/kubernetes.go b/pkg/transformer/kubernetes/kubernetes.go index 1565652d..8cbfe476 100755 --- a/pkg/transformer/kubernetes/kubernetes.go +++ b/pkg/transformer/kubernetes/kubernetes.go @@ -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 } diff --git a/script/test/fixtures/multiple-compose-files/output-k8s-template.json b/script/test/fixtures/multiple-compose-files/output-k8s-template.json index a2c66cea..7d354a60 100644 --- a/script/test/fixtures/multiple-compose-files/output-k8s-template.json +++ b/script/test/fixtures/multiple-compose-files/output-k8s-template.json @@ -135,9 +135,6 @@ "imagePullPolicy": "", "name": "etherpad", "ports": [ - { - "containerPort": 9001 - }, { "containerPort": 9001 } diff --git a/script/test/fixtures/multiple-compose-files/output-os-template.json b/script/test/fixtures/multiple-compose-files/output-os-template.json index f494bc42..8cebca69 100644 --- a/script/test/fixtures/multiple-compose-files/output-os-template.json +++ b/script/test/fixtures/multiple-compose-files/output-os-template.json @@ -127,9 +127,6 @@ "name": "etherpad", "image": " ", "ports": [ - { - "containerPort": 9001 - }, { "containerPort": 9001 } diff --git a/script/test/fixtures/ports-with-proto/docker-compose.yml b/script/test/fixtures/ports-with-proto/docker-compose.yml index c508f86d..67eee1aa 100644 --- a/script/test/fixtures/ports-with-proto/docker-compose.yml +++ b/script/test/fixtures/ports-with-proto/docker-compose.yml @@ -5,6 +5,7 @@ services: image: tuna/docker-counter23 ports: - "5000:5000/tcp" + - "5001:5000/tcp" links: - redis networks: diff --git a/script/test/fixtures/ports-with-proto/output-k8s-template.json b/script/test/fixtures/ports-with-proto/output-k8s-template.json index 6821761c..baed7d23 100644 --- a/script/test/fixtures/ports-with-proto/output-k8s-template.json +++ b/script/test/fixtures/ports-with-proto/output-k8s-template.json @@ -59,6 +59,11 @@ "name": "5000", "port": 5000, "targetPort": 5000 + }, + { + "name": "5001", + "port": 5001, + "targetPort": 5000 } ], "selector": { diff --git a/script/test/fixtures/ports-with-proto/output-os-template.json b/script/test/fixtures/ports-with-proto/output-os-template.json index 80897a49..beaa84fa 100644 --- a/script/test/fixtures/ports-with-proto/output-os-template.json +++ b/script/test/fixtures/ports-with-proto/output-os-template.json @@ -59,6 +59,11 @@ "name": "5000", "port": 5000, "targetPort": 5000 + }, + { + "name": "5001", + "port": 5001, + "targetPort": 5000 } ], "selector": { diff --git a/script/test/fixtures/v3/output-k8s-full-example.json b/script/test/fixtures/v3/output-k8s-full-example.json index cb936ca6..912f62c5 100644 --- a/script/test/fixtures/v3/output-k8s-full-example.json +++ b/script/test/fixtures/v3/output-k8s-full-example.json @@ -229,9 +229,6 @@ ], "workingDir": "/code", "ports": [ - { - "containerPort": 3000 - }, { "containerPort": 3000 }, diff --git a/script/test/fixtures/v3/output-os-full-example.json b/script/test/fixtures/v3/output-os-full-example.json index 2f45c828..8d72db1b 100644 --- a/script/test/fixtures/v3/output-os-full-example.json +++ b/script/test/fixtures/v3/output-os-full-example.json @@ -229,9 +229,6 @@ ], "workingDir": "/code", "ports": [ - { - "containerPort": 3000 - }, { "containerPort": 3000 },