From c40bb4bb3acb47824a23fca22d6c246c1d5adfc3 Mon Sep 17 00:00:00 2001 From: Abhishek Date: Wed, 14 Jun 2017 11:46:17 +0530 Subject: [PATCH] change volume name with generated deployment file if volumes in docker file is defined as volumes: - .:/code Then the PVC created by kompose will containes .(dot) in it. .-persistentvolumeclaim.yaml --- pkg/transformer/utils.go | 2 +- script/test/cmd/tests.sh | 7 + .../change-in-volume/docker-compose.yml | 13 + .../fixtures/change-in-volume/output-k8s.json | 175 +++++++++++ .../fixtures/change-in-volume/output-os.json | 278 ++++++++++++++++++ 5 files changed, 474 insertions(+), 1 deletion(-) create mode 100644 script/test/fixtures/change-in-volume/docker-compose.yml create mode 100644 script/test/fixtures/change-in-volume/output-k8s.json create mode 100644 script/test/fixtures/change-in-volume/output-os.json diff --git a/pkg/transformer/utils.go b/pkg/transformer/utils.go index 7cb4285c..2b4f32e7 100644 --- a/pkg/transformer/utils.go +++ b/pkg/transformer/utils.go @@ -97,7 +97,7 @@ func ParseVolume(volume string) (name, host, container, mode string, err error) } func isPath(substring string) bool { - return strings.Contains(substring, "/") + return strings.Contains(substring, "/") || substring == "." } // ConfigLabels configures label diff --git a/script/test/cmd/tests.sh b/script/test/cmd/tests.sh index 2ec00aab..000ae20d 100755 --- a/script/test/cmd/tests.sh +++ b/script/test/cmd/tests.sh @@ -233,6 +233,13 @@ export $(cat $KOMPOSE_ROOT/script/test/fixtures/buildargs/envs) convert::expect_success_and_warning "kompose --provider openshift -f $KOMPOSE_ROOT/script/test/fixtures/buildargs/docker-compose.yml convert --stdout -j" "/tmp/output-buildarg-os.json" "$warning" rm /tmp/output-buildarg-os.json +#### +# Test related to change in pvc name if volume used is in the current directory +# kubernetes test +convert::expect_success_and_warning "kompose convert -f $KOMPOSE_ROOT/script/test/fixtures/change-in-volume/docker-compose.yml --stdout -j" "$KOMPOSE_ROOT/script/test/fixtures/change-in-volume/output-k8s.json" "Volume mount on the host "\"."\" isn't supported - ignoring path on the host" +# openshift test +convert::expect_success_and_warning "kompose convert --provider=openshift -f $KOMPOSE_ROOT/script/test/fixtures/change-in-volume/docker-compose.yml --stdout -j" "$KOMPOSE_ROOT/script/test/fixtures/change-in-volume/output-os.json" "Volume mount on the host "\"."\" isn't supported - ignoring path on the host" + # Test related to support docker-compose.yaml beside docker-compose.yml # Store the original path CURRENT_DIR=$(pwd) diff --git a/script/test/fixtures/change-in-volume/docker-compose.yml b/script/test/fixtures/change-in-volume/docker-compose.yml new file mode 100644 index 00000000..58db102a --- /dev/null +++ b/script/test/fixtures/change-in-volume/docker-compose.yml @@ -0,0 +1,13 @@ +version: '2' +services: + web: + image: flask_web + command: python app.py + ports: + - "5000:5000" + volumes: + - .:/code + links: + - redis + redis: + image: redis diff --git a/script/test/fixtures/change-in-volume/output-k8s.json b/script/test/fixtures/change-in-volume/output-k8s.json new file mode 100644 index 00000000..ea27825b --- /dev/null +++ b/script/test/fixtures/change-in-volume/output-k8s.json @@ -0,0 +1,175 @@ +{ + "kind": "List", + "apiVersion": "v1", + "metadata": {}, + "items": [ + { + "kind": "Service", + "apiVersion": "v1", + "metadata": { + "name": "redis", + "creationTimestamp": null, + "labels": { + "io.kompose.service": "redis" + } + }, + "spec": { + "ports": [ + { + "name": "headless", + "port": 55555, + "targetPort": 0 + } + ], + "selector": { + "io.kompose.service": "redis" + }, + "clusterIP": "None" + }, + "status": { + "loadBalancer": {} + } + }, + { + "kind": "Service", + "apiVersion": "v1", + "metadata": { + "name": "web", + "creationTimestamp": null, + "labels": { + "io.kompose.service": "web" + } + }, + "spec": { + "ports": [ + { + "name": "5000", + "port": 5000, + "targetPort": 5000 + } + ], + "selector": { + "io.kompose.service": "web" + } + }, + "status": { + "loadBalancer": {} + } + }, + { + "kind": "Deployment", + "apiVersion": "extensions/v1beta1", + "metadata": { + "name": "redis", + "creationTimestamp": null, + "labels": { + "io.kompose.service": "redis" + } + }, + "spec": { + "replicas": 1, + "template": { + "metadata": { + "creationTimestamp": null, + "labels": { + "io.kompose.service": "redis" + } + }, + "spec": { + "containers": [ + { + "name": "redis", + "image": "redis", + "resources": {} + } + ], + "restartPolicy": "Always" + } + }, + "strategy": {} + }, + "status": {} + }, + { + "kind": "Deployment", + "apiVersion": "extensions/v1beta1", + "metadata": { + "name": "web", + "creationTimestamp": null, + "labels": { + "io.kompose.service": "web" + } + }, + "spec": { + "replicas": 1, + "template": { + "metadata": { + "creationTimestamp": null, + "labels": { + "io.kompose.service": "web" + } + }, + "spec": { + "volumes": [ + { + "name": "web-claim0", + "persistentVolumeClaim": { + "claimName": "web-claim0" + } + } + ], + "containers": [ + { + "name": "web", + "image": "flask_web", + "args": [ + "python", + "app.py" + ], + "ports": [ + { + "containerPort": 5000 + } + ], + "resources": {}, + "volumeMounts": [ + { + "name": "web-claim0", + "mountPath": "/code" + } + ] + } + ], + "restartPolicy": "Always" + } + }, + "strategy": { + "type": "Recreate" + } + }, + "status": {} + }, + { + "kind": "PersistentVolumeClaim", + "apiVersion": "v1", + "metadata": { + "name": "web-claim0", + "creationTimestamp": null, + "labels": { + "io.kompose.service": "web-claim0" + } + }, + "spec": { + "accessModes": [ + "ReadWriteOnce" + ], + "resources": { + "requests": { + "storage": "100Mi" + } + } + }, + "status": {} + } + ] +} diff --git a/script/test/fixtures/change-in-volume/output-os.json b/script/test/fixtures/change-in-volume/output-os.json new file mode 100644 index 00000000..a7587327 --- /dev/null +++ b/script/test/fixtures/change-in-volume/output-os.json @@ -0,0 +1,278 @@ +{ + "kind": "List", + "apiVersion": "v1", + "metadata": {}, + "items": [ + { + "kind": "Service", + "apiVersion": "v1", + "metadata": { + "name": "redis", + "creationTimestamp": null, + "labels": { + "io.kompose.service": "redis" + } + }, + "spec": { + "ports": [ + { + "name": "headless", + "port": 55555, + "targetPort": 0 + } + ], + "selector": { + "io.kompose.service": "redis" + }, + "clusterIP": "None" + }, + "status": { + "loadBalancer": {} + } + }, + { + "kind": "Service", + "apiVersion": "v1", + "metadata": { + "name": "web", + "creationTimestamp": null, + "labels": { + "io.kompose.service": "web" + } + }, + "spec": { + "ports": [ + { + "name": "5000", + "port": 5000, + "targetPort": 5000 + } + ], + "selector": { + "io.kompose.service": "web" + } + }, + "status": { + "loadBalancer": {} + } + }, + { + "kind": "DeploymentConfig", + "apiVersion": "v1", + "metadata": { + "name": "redis", + "creationTimestamp": null, + "labels": { + "io.kompose.service": "redis" + } + }, + "spec": { + "strategy": { + "resources": {} + }, + "triggers": [ + { + "type": "ConfigChange" + }, + { + "type": "ImageChange", + "imageChangeParams": { + "automatic": true, + "containerNames": [ + "redis" + ], + "from": { + "kind": "ImageStreamTag", + "name": "redis:latest" + } + } + } + ], + "replicas": 1, + "test": false, + "selector": { + "io.kompose.service": "redis" + }, + "template": { + "metadata": { + "creationTimestamp": null, + "labels": { + "io.kompose.service": "redis" + } + }, + "spec": { + "containers": [ + { + "name": "redis", + "image": " ", + "resources": {} + } + ], + "restartPolicy": "Always" + } + } + }, + "status": {} + }, + { + "kind": "ImageStream", + "apiVersion": "v1", + "metadata": { + "name": "redis", + "creationTimestamp": null, + "labels": { + "io.kompose.service": "redis" + } + }, + "spec": { + "tags": [ + { + "name": "latest", + "annotations": null, + "from": { + "kind": "DockerImage", + "name": "redis" + }, + "generation": null, + "importPolicy": {} + } + ] + }, + "status": { + "dockerImageRepository": "" + } + }, + { + "kind": "DeploymentConfig", + "apiVersion": "v1", + "metadata": { + "name": "web", + "creationTimestamp": null, + "labels": { + "io.kompose.service": "web" + } + }, + "spec": { + "strategy": { + "type": "Recreate", + "resources": {} + }, + "triggers": [ + { + "type": "ConfigChange" + }, + { + "type": "ImageChange", + "imageChangeParams": { + "automatic": true, + "containerNames": [ + "web" + ], + "from": { + "kind": "ImageStreamTag", + "name": "web:latest" + } + } + } + ], + "replicas": 1, + "test": false, + "selector": { + "io.kompose.service": "web" + }, + "template": { + "metadata": { + "creationTimestamp": null, + "labels": { + "io.kompose.service": "web" + } + }, + "spec": { + "volumes": [ + { + "name": "web-claim0", + "persistentVolumeClaim": { + "claimName": "web-claim0" + } + } + ], + "containers": [ + { + "name": "web", + "image": " ", + "args": [ + "python", + "app.py" + ], + "ports": [ + { + "containerPort": 5000 + } + ], + "resources": {}, + "volumeMounts": [ + { + "name": "web-claim0", + "mountPath": "/code" + } + ] + } + ], + "restartPolicy": "Always" + } + } + }, + "status": {} + }, + { + "kind": "ImageStream", + "apiVersion": "v1", + "metadata": { + "name": "web", + "creationTimestamp": null, + "labels": { + "io.kompose.service": "web" + } + }, + "spec": { + "tags": [ + { + "name": "latest", + "annotations": null, + "from": { + "kind": "DockerImage", + "name": "flask_web" + }, + "generation": null, + "importPolicy": {} + } + ] + }, + "status": { + "dockerImageRepository": "" + } + }, + { + "kind": "PersistentVolumeClaim", + "apiVersion": "v1", + "metadata": { + "name": "web-claim0", + "creationTimestamp": null, + "labels": { + "io.kompose.service": "web-claim0" + } + }, + "spec": { + "accessModes": [ + "ReadWriteOnce" + ], + "resources": { + "requests": { + "storage": "100Mi" + } + } + }, + "status": {} + } + ] +}