From 6eb1aed7ab4175f94526a39d0c5b69adb407ba44 Mon Sep 17 00:00:00 2001 From: Li Yi Date: Tue, 5 Jun 2018 14:18:40 +0800 Subject: [PATCH] Fix invalid port name with uppercase characters (#1029) * Fix invalid port name with uppercase characters Signed-off-by: Li Yi --- pkg/transformer/kubernetes/kubernetes.go | 2 +- pkg/transformer/kubernetes/kubernetes_test.go | 10 +++++++++- .../multiple-compose-files/output-k8s-template.json | 2 +- .../multiple-compose-files/output-os-template.json | 2 +- .../same-port-different-proto/output-k8s-template.json | 2 +- .../same-port-different-proto/output-os-template.json | 2 +- script/test/fixtures/v3/output-k8s-full-example.json | 2 +- script/test/fixtures/v3/output-os-full-example.json | 2 +- 8 files changed, 16 insertions(+), 8 deletions(-) diff --git a/pkg/transformer/kubernetes/kubernetes.go b/pkg/transformer/kubernetes/kubernetes.go index 5b0ba18b..745f4b3a 100644 --- a/pkg/transformer/kubernetes/kubernetes.go +++ b/pkg/transformer/kubernetes/kubernetes.go @@ -367,7 +367,7 @@ func (k *Kubernetes) ConfigServicePorts(name string, service kobject.ServiceConf if service.ServiceType == string(api.ServiceTypeLoadBalancer) { log.Fatalf("Service %s of type LoadBalancer cannot use TCP and UDP for the same port", name) } - name = fmt.Sprintf("%s-%s", name, port.Protocol) + name = fmt.Sprintf("%s-%s", name, strings.ToLower(string(port.Protocol))) } servicePort = api.ServicePort{ diff --git a/pkg/transformer/kubernetes/kubernetes_test.go b/pkg/transformer/kubernetes/kubernetes_test.go index 57241b78..20a8b982 100644 --- a/pkg/transformer/kubernetes/kubernetes_test.go +++ b/pkg/transformer/kubernetes/kubernetes_test.go @@ -29,6 +29,7 @@ import ( "github.com/pkg/errors" "k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/apis/extensions" + "strings" ) func newServiceConfig() kobject.ServiceConfig { @@ -36,7 +37,7 @@ func newServiceConfig() kobject.ServiceConfig { ContainerName: "name", Image: "image", Environment: []kobject.EnvVar{kobject.EnvVar{Name: "env", Value: "value"}}, - Port: []kobject.Ports{kobject.Ports{HostPort: 123, ContainerPort: 456}}, + Port: []kobject.Ports{kobject.Ports{HostPort: 123, ContainerPort: 456}, kobject.Ports{HostPort: 123, ContainerPort: 456, Protocol: api.ProtocolUDP}}, Command: []string{"cmd"}, WorkingDir: "dir", Args: []string{"arg1", "arg2"}, @@ -189,6 +190,13 @@ func checkService(config kobject.ServiceConfig, svc *api.Service, expectedLabels if !equalStringMaps(expectedLabels, svc.Spec.Selector) { return fmt.Errorf("Found unexpected selector: %#v vs. %#v", expectedLabels, svc.Spec.Selector) } + for _, port := range svc.Spec.Ports { + name := port.Name + expectedName := strings.ToLower(name) + if expectedName != name { + return fmt.Errorf("Found unexpected port name: %#v vs. %#v", expectedName, name) + } + } // TODO: finish this return nil } 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 d782c95f..0e6c5853 100644 --- a/script/test/fixtures/multiple-compose-files/output-k8s-template.json +++ b/script/test/fixtures/multiple-compose-files/output-k8s-template.json @@ -25,7 +25,7 @@ "targetPort": 9001 }, { - "name": "80-TCP", + "name": "80-tcp", "port": 80, "targetPort": 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 206fb4af..f494bc42 100644 --- a/script/test/fixtures/multiple-compose-files/output-os-template.json +++ b/script/test/fixtures/multiple-compose-files/output-os-template.json @@ -25,7 +25,7 @@ "targetPort": 9001 }, { - "name": "80-TCP", + "name": "80-tcp", "port": 80, "targetPort": 9001 } diff --git a/script/test/fixtures/same-port-different-proto/output-k8s-template.json b/script/test/fixtures/same-port-different-proto/output-k8s-template.json index 31afe35c..52978f6c 100644 --- a/script/test/fixtures/same-port-different-proto/output-k8s-template.json +++ b/script/test/fixtures/same-port-different-proto/output-k8s-template.json @@ -25,7 +25,7 @@ "targetPort": 6379 }, { - "name": "6379-UDP", + "name": "6379-udp", "protocol": "UDP", "port": 6379, "targetPort": 6379 diff --git a/script/test/fixtures/same-port-different-proto/output-os-template.json b/script/test/fixtures/same-port-different-proto/output-os-template.json index ef98a1c2..ef6bde25 100644 --- a/script/test/fixtures/same-port-different-proto/output-os-template.json +++ b/script/test/fixtures/same-port-different-proto/output-os-template.json @@ -25,7 +25,7 @@ "targetPort": 6379 }, { - "name": "6379-UDP", + "name": "6379-udp", "protocol": "UDP", "port": 6379, "targetPort": 6379 diff --git a/script/test/fixtures/v3/output-k8s-full-example.json b/script/test/fixtures/v3/output-k8s-full-example.json index aa62c86e..844ee922 100644 --- a/script/test/fixtures/v3/output-k8s-full-example.json +++ b/script/test/fixtures/v3/output-k8s-full-example.json @@ -28,7 +28,7 @@ "targetPort": 3000 }, { - "name": "3000-TCP", + "name": "3000-tcp", "port": 3000, "targetPort": 3000 }, diff --git a/script/test/fixtures/v3/output-os-full-example.json b/script/test/fixtures/v3/output-os-full-example.json index aa62c86e..844ee922 100644 --- a/script/test/fixtures/v3/output-os-full-example.json +++ b/script/test/fixtures/v3/output-os-full-example.json @@ -28,7 +28,7 @@ "targetPort": 3000 }, { - "name": "3000-TCP", + "name": "3000-tcp", "port": 3000, "targetPort": 3000 },