From f18450d045785770999fc62407e9d1a3dcd6da4c Mon Sep 17 00:00:00 2001 From: Hang Yan Date: Thu, 8 Feb 2018 16:13:49 +0800 Subject: [PATCH] Fix custom pvc size in v2 compose not working error --- pkg/loader/compose/v1v2.go | 3 + script/test/cmd/tests.sh | 12 ++ .../named-volume/docker-compose.yml | 10 + .../named-volume/output-k8s-template.json | 120 ++++++++++++ .../named-volume/output-os-template.json | 171 ++++++++++++++++++ 5 files changed, 316 insertions(+) create mode 100644 script/test/fixtures/volume-mounts/named-volume/docker-compose.yml create mode 100644 script/test/fixtures/volume-mounts/named-volume/output-k8s-template.json create mode 100644 script/test/fixtures/volume-mounts/named-volume/output-os-template.json diff --git a/pkg/loader/compose/v1v2.go b/pkg/loader/compose/v1v2.go index c7ec3559..d0d78e16 100644 --- a/pkg/loader/compose/v1v2.go +++ b/pkg/loader/compose/v1v2.go @@ -230,6 +230,7 @@ func libComposeToKomposeMapping(composeObject *project.Project) (kobject.Kompose // canonical "Custom Labels" handler // Labels used to influence conversion of kompose will be handled // from here for docker-compose. Each loader will have such handler. + serviceConfig.Labels = make(map[string]string) for key, value := range composeServiceConfig.Labels { switch key { case "kompose.service.type": @@ -243,6 +244,8 @@ func libComposeToKomposeMapping(composeObject *project.Project) (kobject.Kompose serviceConfig.ExposeService = strings.ToLower(value) case "kompose.service.expose.tls-secret": serviceConfig.ExposeServiceTLS = value + default: + serviceConfig.Labels[key] = value } } if serviceConfig.ExposeService == "" && serviceConfig.ExposeServiceTLS != "" { diff --git a/script/test/cmd/tests.sh b/script/test/cmd/tests.sh index f6cb3f24..5c102284 100755 --- a/script/test/cmd/tests.sh +++ b/script/test/cmd/tests.sh @@ -149,6 +149,18 @@ cmd="kompose --provider=openshift -f $KOMPOSE_ROOT/script/test/fixtures/volume-m sed -e "s;%VERSION%;$version;g" -e "s;%CMD%;$cmd;g" $KOMPOSE_ROOT/script/test/fixtures/volume-mounts/simple-vol-mounts/output-os-template.json > /tmp/output-os.json convert::expect_success "kompose --provider=openshift -f $KOMPOSE_ROOT/script/test/fixtures/volume-mounts/simple-vol-mounts/docker-compose.yml convert --stdout -j" "/tmp/output-os.json" +###### +# Tests related to docker-compose file in /script/test/fixtures/volume-mounts/named-volume +# kubernetes test +cmd="kompose -f $KOMPOSE_ROOT/script/test/fixtures/volume-mounts/named-volume/docker-compose.yml convert --stdout -j" +sed -e "s;%VERSION%;$version;g" -e "s;%CMD%;$cmd;g" $KOMPOSE_ROOT/script/test/fixtures/volume-mounts/named-volume/output-k8s-template.json > /tmp/output-k8s.json +convert::expect_success "kompose -f $KOMPOSE_ROOT/script/test/fixtures/volume-mounts/named-volume/docker-compose.yml convert --stdout -j" "/tmp/output-k8s.json" + +# openshift test +cmd="kompose --provider=openshift -f $KOMPOSE_ROOT/script/test/fixtures/volume-mounts/named-volume/docker-compose.yml convert --stdout -j" +sed -e "s;%VERSION%;$version;g" -e "s;%CMD%;$cmd;g" $KOMPOSE_ROOT/script/test/fixtures/volume-mounts/named-volume/output-os-template.json > /tmp/output-os.json +convert::expect_success "kompose --provider=openshift -f $KOMPOSE_ROOT/script/test/fixtures/volume-mounts/named-volume/docker-compose.yml convert --stdout -j" "/tmp/output-os.json" + ###### # Tests related to docker-compose file in /script/test/fixtures/volume-mounts/volumes-from diff --git a/script/test/fixtures/volume-mounts/named-volume/docker-compose.yml b/script/test/fixtures/volume-mounts/named-volume/docker-compose.yml new file mode 100644 index 00000000..19b5c5aa --- /dev/null +++ b/script/test/fixtures/volume-mounts/named-volume/docker-compose.yml @@ -0,0 +1,10 @@ +version: '2' +services: + db: + image: postgres:10.1 + ports: + - "5432" + labels: + kompose.volume.size: 1Gi + volumes: + - db-data:/var/lib/postgresql/data \ No newline at end of file diff --git a/script/test/fixtures/volume-mounts/named-volume/output-k8s-template.json b/script/test/fixtures/volume-mounts/named-volume/output-k8s-template.json new file mode 100644 index 00000000..3f7bb467 --- /dev/null +++ b/script/test/fixtures/volume-mounts/named-volume/output-k8s-template.json @@ -0,0 +1,120 @@ +{ + "kind": "List", + "apiVersion": "v1", + "metadata": {}, + "items": [ + { + "kind": "Service", + "apiVersion": "v1", + "metadata": { + "name": "db", + "creationTimestamp": null, + "labels": { + "io.kompose.service": "db" + }, + "annotations": { + "kompose.cmd": "%CMD%", + "kompose.version": "%VERSION%", + "kompose.volume.size": "1Gi" + } + }, + "spec": { + "ports": [ + { + "name": "5432", + "port": 5432, + "targetPort": 5432 + } + ], + "selector": { + "io.kompose.service": "db" + } + }, + "status": { + "loadBalancer": {} + } + }, + { + "kind": "Deployment", + "apiVersion": "extensions/v1beta1", + "metadata": { + "name": "db", + "creationTimestamp": null, + "labels": { + "io.kompose.service": "db" + }, + "annotations": { + "kompose.cmd": "%CMD%", + "kompose.version": "%VERSION%", + "kompose.volume.size": "1Gi" + } + }, + "spec": { + "replicas": 1, + "template": { + "metadata": { + "creationTimestamp": null, + "labels": { + "io.kompose.service": "db" + } + }, + "spec": { + "volumes": [ + { + "name": "db-data", + "persistentVolumeClaim": { + "claimName": "db-data" + } + } + ], + "containers": [ + { + "name": "db", + "image": "postgres:10.1", + "ports": [ + { + "containerPort": 5432 + } + ], + "resources": {}, + "volumeMounts": [ + { + "name": "db-data", + "mountPath": "/var/lib/postgresql/data" + } + ] + } + ], + "restartPolicy": "Always" + } + }, + "strategy": { + "type": "Recreate" + } + }, + "status": {} + }, + { + "kind": "PersistentVolumeClaim", + "apiVersion": "v1", + "metadata": { + "name": "db-data", + "creationTimestamp": null, + "labels": { + "io.kompose.service": "db-data" + } + }, + "spec": { + "accessModes": [ + "ReadWriteOnce" + ], + "resources": { + "requests": { + "storage": "1Gi" + } + } + }, + "status": {} + } + ] +} diff --git a/script/test/fixtures/volume-mounts/named-volume/output-os-template.json b/script/test/fixtures/volume-mounts/named-volume/output-os-template.json new file mode 100644 index 00000000..057304b2 --- /dev/null +++ b/script/test/fixtures/volume-mounts/named-volume/output-os-template.json @@ -0,0 +1,171 @@ +{ + "kind": "List", + "apiVersion": "v1", + "metadata": {}, + "items": [ + { + "kind": "Service", + "apiVersion": "v1", + "metadata": { + "name": "db", + "creationTimestamp": null, + "labels": { + "io.kompose.service": "db" + }, + "annotations": { + "kompose.cmd": "%CMD%", + "kompose.version": "%VERSION%", + "kompose.volume.size": "1Gi" + } + }, + "spec": { + "ports": [ + { + "name": "5432", + "port": 5432, + "targetPort": 5432 + } + ], + "selector": { + "io.kompose.service": "db" + } + }, + "status": { + "loadBalancer": {} + } + }, + { + "kind": "DeploymentConfig", + "apiVersion": "v1", + "metadata": { + "name": "db", + "creationTimestamp": null, + "labels": { + "io.kompose.service": "db" + }, + "annotations": { + "kompose.cmd": "%CMD%", + "kompose.version": "%VERSION%", + "kompose.volume.size": "1Gi" + } + }, + "spec": { + "strategy": { + "type": "Recreate", + "resources": {} + }, + "triggers": [ + { + "type": "ConfigChange" + }, + { + "type": "ImageChange", + "imageChangeParams": { + "automatic": true, + "containerNames": [ + "db" + ], + "from": { + "kind": "ImageStreamTag", + "name": "db:10.1" + } + } + } + ], + "replicas": 1, + "test": false, + "selector": { + "io.kompose.service": "db" + }, + "template": { + "metadata": { + "creationTimestamp": null, + "labels": { + "io.kompose.service": "db" + } + }, + "spec": { + "volumes": [ + { + "name": "db-data", + "persistentVolumeClaim": { + "claimName": "db-data" + } + } + ], + "containers": [ + { + "name": "db", + "image": " ", + "ports": [ + { + "containerPort": 5432 + } + ], + "resources": {}, + "volumeMounts": [ + { + "name": "db-data", + "mountPath": "/var/lib/postgresql/data" + } + ] + } + ], + "restartPolicy": "Always" + } + } + }, + "status": {} + }, + { + "kind": "ImageStream", + "apiVersion": "v1", + "metadata": { + "name": "db", + "creationTimestamp": null, + "labels": { + "io.kompose.service": "db" + } + }, + "spec": { + "tags": [ + { + "name": "10.1", + "annotations": null, + "from": { + "kind": "DockerImage", + "name": "postgres:10.1" + }, + "generation": null, + "importPolicy": {} + } + ] + }, + "status": { + "dockerImageRepository": "" + } + }, + { + "kind": "PersistentVolumeClaim", + "apiVersion": "v1", + "metadata": { + "name": "db-data", + "creationTimestamp": null, + "labels": { + "io.kompose.service": "db-data" + } + }, + "spec": { + "accessModes": [ + "ReadWriteOnce" + ], + "resources": { + "requests": { + "storage": "1Gi" + } + } + }, + "status": {} + } + ] +}