From 1c4ff966262a8e48e9856a26a109401b8fd6f4a1 Mon Sep 17 00:00:00 2001 From: Shivam Sandbhor Date: Sat, 13 Nov 2021 18:03:10 +0530 Subject: [PATCH] Infer storage type using label (#1456) Signed-off-by: Shivam Sandbhor --- docs/user-guide.md | 1 + pkg/app/app.go | 9 +- pkg/transformer/kubernetes/kubernetes.go | 14 +- script/test/cmd/tests_new.sh | 16 + .../docker-compose-withlabel.yml | 15 + .../output-k8s-withlabel.json | 202 +++++++++++ .../configmap-volume/output-os-withlabel.json | 314 ++++++++++++++++++ .../multiple-type-volumes/docker-compose.yaml | 18 + .../multiple-type-volumes/output-k8s.json | 200 +++++++++++ .../multiple-type-volumes/output-os.json | 312 +++++++++++++++++ .../fixtures/multiple-type-volumes/tls/a.crt | 1 + .../fixtures/multiple-type-volumes/tls/a.key | 1 + 12 files changed, 1099 insertions(+), 4 deletions(-) create mode 100644 script/test/fixtures/configmap-volume/docker-compose-withlabel.yml create mode 100644 script/test/fixtures/configmap-volume/output-k8s-withlabel.json create mode 100644 script/test/fixtures/configmap-volume/output-os-withlabel.json create mode 100644 script/test/fixtures/multiple-type-volumes/docker-compose.yaml create mode 100644 script/test/fixtures/multiple-type-volumes/output-k8s.json create mode 100644 script/test/fixtures/multiple-type-volumes/output-os.json create mode 100644 script/test/fixtures/multiple-type-volumes/tls/a.crt create mode 100644 script/test/fixtures/multiple-type-volumes/tls/a.key diff --git a/docs/user-guide.md b/docs/user-guide.md index b0d2e690..780766ed 100755 --- a/docs/user-guide.md +++ b/docs/user-guide.md @@ -175,6 +175,7 @@ The currently supported options are: | kompose.service.expose.tls-secret | secret name | | kompose.volume.size | kubernetes supported volume size | | kompose.volume.storage-class-name | kubernetes supported volume storageClassName | +| kompose.volume.type | use k8s volume type, eg "configMap", "persistentVolumeClaim", "emptyDir", "hostPath" | | kompose.controller.type | deployment / daemonset / replicationcontroller | | kompose.image-pull-policy | kubernetes pods imagePullPolicy | | kompose.image-pull-secret | kubernetes secret name for imagePullSecrets | diff --git a/pkg/app/app.go b/pkg/app/app.go index 2039e595..c7daf2e7 100644 --- a/pkg/app/app.go +++ b/pkg/app/app.go @@ -17,6 +17,7 @@ limitations under the License. package app import ( + "fmt" "strings" log "github.com/sirupsen/logrus" @@ -132,8 +133,12 @@ func ValidateFlags(args []string, cmd *cobra.Command, opt *kobject.ConvertOption log.Fatalf("YAML and JSON format cannot be provided at the same time") } - if opt.Volumes != "persistentVolumeClaim" && opt.Volumes != "emptyDir" && opt.Volumes != "hostPath" && opt.Volumes != "configMap" { - log.Fatal("Unknown Volume type: ", opt.Volumes, ", possible values are: persistentVolumeClaim, hostPath, configMap and emptyDir") + if _, ok := kubernetes.ValidVolumeSet[opt.Volumes]; !ok { + validVolumesTypes := make([]string, 0) + for validVolumeType := range kubernetes.ValidVolumeSet { + validVolumesTypes = append(validVolumesTypes, fmt.Sprintf("'%s'", validVolumeType)) + } + log.Fatal("Unknown Volume type: ", opt.Volumes, ", possible values are: ", strings.Join(validVolumesTypes, " ")) } } diff --git a/pkg/transformer/kubernetes/kubernetes.go b/pkg/transformer/kubernetes/kubernetes.go index ec9660c9..b2fd42f7 100644 --- a/pkg/transformer/kubernetes/kubernetes.go +++ b/pkg/transformer/kubernetes/kubernetes.go @@ -57,6 +57,8 @@ type Kubernetes struct { // PVCRequestSize (Persistent Volume Claim) has default size const PVCRequestSize = "100Mi" +var ValidVolumeSet = map[string]struct{}{"emptyDir": {}, "hostPath": {}, "configMap": {}, "persistentVolumeClaim": {}} + const ( // DeploymentController is controller type for Deployment DeploymentController = "deployment" @@ -837,11 +839,20 @@ func (k *Kubernetes) ConfigVolumes(name string, service kobject.ServiceConfig) ( useEmptyVolumes := k.Opt.EmptyVols useHostPath := k.Opt.Volumes == "hostPath" useConfigMap := k.Opt.Volumes == "configMap" - if k.Opt.Volumes == "emptyDir" { useEmptyVolumes = true } + // Override volume type if specified in service labels. + if vt, ok := service.Labels["kompose.volume.type"]; ok { + if _, okk := ValidVolumeSet[vt]; !okk { + return nil, nil, nil, nil, fmt.Errorf("invalid volume type %s specified in label 'kompose.volume.type' in service %s", vt, service.Name) + } + useEmptyVolumes = vt == "emptyDir" + useHostPath = vt == "hostPath" + useConfigMap = vt == "configMap" + } + // config volumes from secret if present secretsVolumeMounts, secretsVolumes := k.ConfigSecretVolumes(name, service) volumeMounts = append(volumeMounts, secretsVolumeMounts...) @@ -852,7 +863,6 @@ func (k *Kubernetes) ConfigVolumes(name string, service kobject.ServiceConfig) ( for _, volume := range service.Volumes { // check if ro/rw mode is defined, default rw readonly := len(volume.Mode) > 0 && volume.Mode == "ro" - if volume.VolumeName == "" { if useEmptyVolumes { volumeName = strings.Replace(volume.PVCName, "claim", "empty", 1) diff --git a/script/test/cmd/tests_new.sh b/script/test/cmd/tests_new.sh index 980b9cf0..f63e5ad7 100755 --- a/script/test/cmd/tests_new.sh +++ b/script/test/cmd/tests_new.sh @@ -134,6 +134,14 @@ os_output="$KOMPOSE_ROOT/script/test/fixtures/configmap-volume/output-os.json" convert::expect_success_and_warning "$k8s_cmd" "$k8s_output" convert::expect_success "$os_cmd" "$os_output" +# test configmap volume using service label +k8s_cmd="kompose -f $KOMPOSE_ROOT/script/test/fixtures/configmap-volume/docker-compose-withlabel.yml convert --stdout -j --with-kompose-annotation=false" +os_cmd="kompose --provider=openshift -f $KOMPOSE_ROOT/script/test/fixtures/configmap-volume/docker-compose-withlabel.yml convert --stdout -j --with-kompose-annotation=false" +k8s_output="$KOMPOSE_ROOT/script/test/fixtures/configmap-volume/output-k8s-withlabel.json" +os_output="$KOMPOSE_ROOT/script/test/fixtures/configmap-volume/output-os-withlabel.json" +convert::expect_success_and_warning "$k8s_cmd" "$k8s_output" +convert::expect_success "$os_cmd" "$os_output" + # Test that emptyDir works k8s_cmd="kompose -f $KOMPOSE_ROOT/script/test/fixtures/change-in-volume/docker-compose.yml convert --with-kompose-annotation=false --stdout -j --volumes emptyDir" k8s_output="$KOMPOSE_ROOT/script/test/fixtures/change-in-volume/output-k8s-empty-vols-template.json" @@ -187,3 +195,11 @@ k8s_output="$KOMPOSE_ROOT/script/test/fixtures/statefulset/output-k8s.json" ocp_output="$KOMPOSE_ROOT/script/test/fixtures/statefulset/output-os.json" convert::expect_success "$k8s_cmd" "$k8s_output" convert::expect_success "$ocp_cmd" "$ocp_output" + +# test specifying volume type using service label +k8s_cmd="kompose -f $KOMPOSE_ROOT/script/test/fixtures/multiple-type-volumes/docker-compose.yaml convert --stdout -j --with-kompose-annotation=false" +os_cmd="kompose --provider=openshift -f $KOMPOSE_ROOT/script/test/fixtures/multiple-type-volumes/docker-compose.yaml convert --stdout -j --with-kompose-annotation=false" +k8s_output="$KOMPOSE_ROOT/script/test/fixtures/multiple-type-volumes/output-k8s.json" +os_output="$KOMPOSE_ROOT/script/test/fixtures/multiple-type-volumes/output-os.json" +convert::expect_success_and_warning "$k8s_cmd" "$k8s_output" +convert::expect_success "$os_cmd" "$os_output" \ No newline at end of file diff --git a/script/test/fixtures/configmap-volume/docker-compose-withlabel.yml b/script/test/fixtures/configmap-volume/docker-compose-withlabel.yml new file mode 100644 index 00000000..09e72be0 --- /dev/null +++ b/script/test/fixtures/configmap-volume/docker-compose-withlabel.yml @@ -0,0 +1,15 @@ +version: "3" +services: + web: + image: nginx + volumes: + - ./tls:/etc/tls + - ./tls/a.key:/etc/test-a-key.key + labels: + kompose.volume.type: configMap + db: + image: mysql + volumes: + - ./configs.tar:/data/configs.tar + labels: + kompose.volume.type: configMap diff --git a/script/test/fixtures/configmap-volume/output-k8s-withlabel.json b/script/test/fixtures/configmap-volume/output-k8s-withlabel.json new file mode 100644 index 00000000..dd994eaf --- /dev/null +++ b/script/test/fixtures/configmap-volume/output-k8s-withlabel.json @@ -0,0 +1,202 @@ +{ + "kind": "List", + "apiVersion": "v1", + "metadata": {}, + "items": [ + { + "kind": "Deployment", + "apiVersion": "apps/v1", + "metadata": { + "name": "db", + "creationTimestamp": null, + "labels": { + "io.kompose.service": "db" + }, + "annotations": { + "kompose.volume.type": "configMap" + } + }, + "spec": { + "replicas": 1, + "selector": { + "matchLabels": { + "io.kompose.service": "db" + } + }, + "template": { + "metadata": { + "creationTimestamp": null, + "labels": { + "io.kompose.service": "db" + }, + "annotations": { + "kompose.volume.type": "configMap" + } + }, + "spec": { + "volumes": [ + { + "name": "db-cm0", + "configMap": { + "name": "db-cm0", + "items": [ + { + "key": "configs.tar", + "path": "configs.tar" + } + ] + } + } + ], + "containers": [ + { + "name": "db", + "image": "mysql", + "resources": {}, + "volumeMounts": [ + { + "name": "db-cm0", + "mountPath": "/data/configs.tar", + "subPath": "configs.tar" + } + ] + } + ], + "restartPolicy": "Always" + } + }, + "strategy": { + "type": "Recreate" + } + }, + "status": {} + }, + { + "kind": "ConfigMap", + "apiVersion": "v1", + "metadata": { + "name": "db-cm0", + "creationTimestamp": null, + "labels": { + "io.kompose.service": "db" + }, + "annotations": { + "use-subpath": "true" + } + }, + "binaryData": { + "configs.tar": "SDRzSUFId3pMVjhBQSsxV3pXc1RRUlFmQ3lMdVJRL2lRVkNHVmFsSVBtWm12N0tXRkFvRksxSU1UU29GVjhLWVRHc2tYK3h1WkV1SjlPaS80TkdiWjIrQ2wrSk4vQ3M4OTZ4WFo3K3lTWGFEc1NZcEpmdExabWJmNC9mbXZielpOeThsNm13eFdtZG12dFpwN3pjT0xEQjdJSVEwUllGQTh4Q3RLQUJHQkdKSnd4S1JzS0xKRUJGRVpCVkFadzZ4eE5DemJHcnlVTXl1MVdVbU0ra0Uzdk1uTzVYZDhvYXgyV25SUmh2dVdzd2N5WlgvVStCZ3ZTREFCWGpRcUJleHJoTkZ3YXFHQks3cGVScFoxeVFkUzdJZ0lkaXlHeTFXeElxdWFycFdJQ2lueWhqcC9Lc0w1LzBMVXZ3UGdxclB6OU5IV1AvSC9ObFdQNzF6MTdmZlRuK2hDT1AxajVBQ29ETFBvRUlzZWYySDUxOGE5SUZjdFU1dG1udGpkZG96OHNIem9jcnk1UHNmY1dIMC9JbWt5T245dndoTWMvOFRMZkgreHdVbHZmd3ZPc0w2bjMzVlJ3anIveGdrMy84eWtjZnJIeEgrL3cvTlBKSUVMSG45ZzhzM3I0QVZBTFpwRFQ0cnd6MFl3TldCcTN3UVBuN3l3ZVZMTjZiYmNxTlMyZkdmUEl1dmZPeU5VVllDL1hVQWJ0VTZyUnp0ZHBzczE2U1czYk5ZbmIrSzdHNnBISEIvOExFRndMV0kxNksxSmxlZWttelZKYnkzbjk3M3FYY2Uvbjc5NE9Qai91ZnZINm9uWDA1dW56VXB5NE40LzUvOVBYQ0cvcy9GdFA4dkFtbi9YMjZFOVQrLzd2L1gvbzlsTkY3L1dNVlMydjhYZ1JjQ2hFZUMyL0ZGeHhFZlFZd3lvZVRKN2lwT3BmSWVNKzY4Rmd3SERxWTFMR2RITmQ0MG9nL1VlY2NRTTlEd3RqVDQzdjZUVTNWOFJYL1l0ZWZidDh1dXIzUHF2WndoK2diUXA3c2ZPT1ExTXhYWkR3NW1qRVEyRHpHaVJ6dTdVVTNlUFRtZUFOeldjR0syc1p3RjgzaWdtU1RIM0hpVEhnNmJRY2ZMYldETEpXaTBvLzJQM0xrZitmTHlEWXR3ZGVoMEJoNVh4ODdmZjROODJYMkpQTEgvajV3WUswNmpOYnZSYWROWFRiYk5xTlV6V2VXd3l4S3NTRklBNGxBdUJ0a1hPYVV2dkR6dk1reVJJa1dLaGVNUENNUUc3Z0FjQUFBPQ==" + } + }, + { + "kind": "Deployment", + "apiVersion": "apps/v1", + "metadata": { + "name": "web", + "creationTimestamp": null, + "labels": { + "io.kompose.service": "web" + }, + "annotations": { + "kompose.volume.type": "configMap" + } + }, + "spec": { + "replicas": 1, + "selector": { + "matchLabels": { + "io.kompose.service": "web" + } + }, + "template": { + "metadata": { + "creationTimestamp": null, + "labels": { + "io.kompose.service": "web" + }, + "annotations": { + "kompose.volume.type": "configMap" + } + }, + "spec": { + "volumes": [ + { + "name": "web-cm0", + "configMap": { + "name": "web-cm0" + } + }, + { + "name": "web-cm1", + "configMap": { + "name": "web-cm1", + "items": [ + { + "key": "a.key", + "path": "test-a-key.key" + } + ] + } + } + ], + "containers": [ + { + "name": "web", + "image": "nginx", + "resources": {}, + "volumeMounts": [ + { + "name": "web-cm0", + "mountPath": "/etc/tls" + }, + { + "name": "web-cm1", + "mountPath": "/etc/test-a-key.key", + "subPath": "test-a-key.key" + } + ] + } + ], + "restartPolicy": "Always" + } + }, + "strategy": { + "type": "Recreate" + } + }, + "status": {} + }, + { + "kind": "ConfigMap", + "apiVersion": "v1", + "metadata": { + "name": "web-cm0", + "creationTimestamp": null, + "labels": { + "io.kompose.service": "web" + } + }, + "data": { + "a.crt": "test-crt-data...", + "a.key": "test-key-data...." + } + }, + { + "kind": "ConfigMap", + "apiVersion": "v1", + "metadata": { + "name": "web-cm1", + "creationTimestamp": null, + "labels": { + "io.kompose.service": "web" + }, + "annotations": { + "use-subpath": "true" + } + }, + "data": { + "a.key": "test-key-data...." + } + } + ] +} diff --git a/script/test/fixtures/configmap-volume/output-os-withlabel.json b/script/test/fixtures/configmap-volume/output-os-withlabel.json new file mode 100644 index 00000000..67067d05 --- /dev/null +++ b/script/test/fixtures/configmap-volume/output-os-withlabel.json @@ -0,0 +1,314 @@ +{ + "kind": "List", + "apiVersion": "v1", + "metadata": {}, + "items": [ + { + "kind": "DeploymentConfig", + "apiVersion": "v1", + "metadata": { + "name": "db", + "creationTimestamp": null, + "labels": { + "io.kompose.service": "db" + }, + "annotations": { + "kompose.volume.type": "configMap" + } + }, + "spec": { + "strategy": { + "type": "Recreate", + "resources": {} + }, + "triggers": [ + { + "type": "ConfigChange" + }, + { + "type": "ImageChange", + "imageChangeParams": { + "automatic": true, + "containerNames": [ + "db" + ], + "from": { + "kind": "ImageStreamTag", + "name": "db:latest" + } + } + } + ], + "replicas": 1, + "test": false, + "selector": { + "io.kompose.service": "db" + }, + "template": { + "metadata": { + "creationTimestamp": null, + "labels": { + "io.kompose.service": "db" + } + }, + "spec": { + "volumes": [ + { + "name": "db-cm0", + "configMap": { + "name": "db-cm0", + "items": [ + { + "key": "configs.tar", + "path": "configs.tar" + } + ] + } + } + ], + "containers": [ + { + "name": "db", + "image": " ", + "resources": {}, + "volumeMounts": [ + { + "name": "db-cm0", + "mountPath": "/data/configs.tar", + "subPath": "configs.tar" + } + ] + } + ], + "restartPolicy": "Always" + } + } + }, + "status": { + "latestVersion": 0, + "observedGeneration": 0, + "replicas": 0, + "updatedReplicas": 0, + "availableReplicas": 0, + "unavailableReplicas": 0 + } + }, + { + "kind": "ImageStream", + "apiVersion": "v1", + "metadata": { + "name": "db", + "creationTimestamp": null, + "labels": { + "io.kompose.service": "db" + } + }, + "spec": { + "lookupPolicy": { + "local": false + }, + "tags": [ + { + "name": "", + "annotations": null, + "from": { + "kind": "DockerImage", + "name": "mysql" + }, + "generation": null, + "importPolicy": {}, + "referencePolicy": { + "type": "" + } + } + ] + }, + "status": { + "dockerImageRepository": "" + } + }, + { + "kind": "ConfigMap", + "apiVersion": "v1", + "metadata": { + "name": "db-cm0", + "creationTimestamp": null, + "labels": { + "io.kompose.service": "db" + }, + "annotations": { + "use-subpath": "true" + } + }, + "binaryData": { + "configs.tar": "SDRzSUFId3pMVjhBQSsxV3pXc1RRUlFmQ3lMdVJRL2lRVkNHVmFsSVBtWm12N0tXRkFvRksxSU1UU29GVjhLWVRHc2tYK3h1WkV1SjlPaS80TkdiWjIrQ2wrSk4vQ3M4OTZ4WFo3K3lTWGFEc1NZcEpmdExabWJmNC9mbXZielpOeThsNm13eFdtZG12dFpwN3pjT0xEQjdJSVEwUllGQTh4Q3RLQUJHQkdKSnd4S1JzS0xKRUJGRVpCVkFadzZ4eE5DemJHcnlVTXl1MVdVbU0ra0Uzdk1uTzVYZDhvYXgyV25SUmh2dVdzd2N5WlgvVStCZ3ZTREFCWGpRcUJleHJoTkZ3YXFHQks3cGVScFoxeVFkUzdJZ0lkaXlHeTFXeElxdWFycFdJQ2lueWhqcC9Lc0w1LzBMVXZ3UGdxclB6OU5IV1AvSC9ObFdQNzF6MTdmZlRuK2hDT1AxajVBQ29ETFBvRUlzZWYySDUxOGE5SUZjdFU1dG1udGpkZG96OHNIem9jcnk1UHNmY1dIMC9JbWt5T245dndoTWMvOFRMZkgreHdVbHZmd3ZPc0w2bjMzVlJ3anIveGdrMy84eWtjZnJIeEgrL3cvTlBKSUVMSG45ZzhzM3I0QVZBTFpwRFQ0cnd6MFl3TldCcTN3UVBuN3l3ZVZMTjZiYmNxTlMyZkdmUEl1dmZPeU5VVllDL1hVQWJ0VTZyUnp0ZHBzczE2U1czYk5ZbmIrSzdHNnBISEIvOExFRndMV0kxNksxSmxlZWttelZKYnkzbjk3M3FYY2Uvbjc5NE9Qai91ZnZINm9uWDA1dW56VXB5NE40LzUvOVBYQ0cvcy9GdFA4dkFtbi9YMjZFOVQrLzd2L1gvbzlsTkY3L1dNVlMydjhYZ1JjQ2hFZUMyL0ZGeHhFZlFZd3lvZVRKN2lwT3BmSWVNKzY4Rmd3SERxWTFMR2RITmQ0MG9nL1VlY2NRTTlEd3RqVDQzdjZUVTNWOFJYL1l0ZWZidDh1dXIzUHF2WndoK2diUXA3c2ZPT1ExTXhYWkR3NW1qRVEyRHpHaVJ6dTdVVTNlUFRtZUFOeldjR0syc1p3RjgzaWdtU1RIM0hpVEhnNmJRY2ZMYldETEpXaTBvLzJQM0xrZitmTHlEWXR3ZGVoMEJoNVh4ODdmZjROODJYMkpQTEgvajV3WUswNmpOYnZSYWROWFRiYk5xTlV6V2VXd3l4S3NTRklBNGxBdUJ0a1hPYVV2dkR6dk1reVJJa1dLaGVNUENNUUc3Z0FjQUFBPQ==" + } + }, + { + "kind": "DeploymentConfig", + "apiVersion": "v1", + "metadata": { + "name": "web", + "creationTimestamp": null, + "labels": { + "io.kompose.service": "web" + }, + "annotations": { + "kompose.volume.type": "configMap" + } + }, + "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-cm0", + "configMap": { + "name": "web-cm0" + } + }, + { + "name": "web-cm1", + "configMap": { + "name": "web-cm1", + "items": [ + { + "key": "a.key", + "path": "test-a-key.key" + } + ] + } + } + ], + "containers": [ + { + "name": "web", + "image": " ", + "resources": {}, + "volumeMounts": [ + { + "name": "web-cm0", + "mountPath": "/etc/tls" + }, + { + "name": "web-cm1", + "mountPath": "/etc/test-a-key.key", + "subPath": "test-a-key.key" + } + ] + } + ], + "restartPolicy": "Always" + } + } + }, + "status": { + "latestVersion": 0, + "observedGeneration": 0, + "replicas": 0, + "updatedReplicas": 0, + "availableReplicas": 0, + "unavailableReplicas": 0 + } + }, + { + "kind": "ImageStream", + "apiVersion": "v1", + "metadata": { + "name": "web", + "creationTimestamp": null, + "labels": { + "io.kompose.service": "web" + } + }, + "spec": { + "lookupPolicy": { + "local": false + }, + "tags": [ + { + "name": "", + "annotations": null, + "from": { + "kind": "DockerImage", + "name": "nginx" + }, + "generation": null, + "importPolicy": {}, + "referencePolicy": { + "type": "" + } + } + ] + }, + "status": { + "dockerImageRepository": "" + } + }, + { + "kind": "ConfigMap", + "apiVersion": "v1", + "metadata": { + "name": "web-cm0", + "creationTimestamp": null, + "labels": { + "io.kompose.service": "web" + } + }, + "data": { + "a.crt": "test-crt-data...", + "a.key": "test-key-data...." + } + }, + { + "kind": "ConfigMap", + "apiVersion": "v1", + "metadata": { + "name": "web-cm1", + "creationTimestamp": null, + "labels": { + "io.kompose.service": "web" + }, + "annotations": { + "use-subpath": "true" + } + }, + "data": { + "a.key": "test-key-data...." + } + } + ] +} diff --git a/script/test/fixtures/multiple-type-volumes/docker-compose.yaml b/script/test/fixtures/multiple-type-volumes/docker-compose.yaml new file mode 100644 index 00000000..b3eda768 --- /dev/null +++ b/script/test/fixtures/multiple-type-volumes/docker-compose.yaml @@ -0,0 +1,18 @@ +version: "3" +services: + web: + image: nginx + volumes: + - ./tls:/etc/tls + - ./tls/a.key:/etc/test-a-key.key + labels: + kompose.volume.type: configMap + db: + image: mysql + volumes: + - db-data:/var/lib/mysql + labels: + kompose.volume.type: persistentVolumeClaim + +volumes: + db-data: diff --git a/script/test/fixtures/multiple-type-volumes/output-k8s.json b/script/test/fixtures/multiple-type-volumes/output-k8s.json new file mode 100644 index 00000000..46b765f5 --- /dev/null +++ b/script/test/fixtures/multiple-type-volumes/output-k8s.json @@ -0,0 +1,200 @@ +{ + "kind": "List", + "apiVersion": "v1", + "metadata": {}, + "items": [ + { + "kind": "Deployment", + "apiVersion": "apps/v1", + "metadata": { + "name": "db", + "creationTimestamp": null, + "labels": { + "io.kompose.service": "db" + }, + "annotations": { + "kompose.volume.type": "persistentVolumeClaim" + } + }, + "spec": { + "replicas": 1, + "selector": { + "matchLabels": { + "io.kompose.service": "db" + } + }, + "template": { + "metadata": { + "creationTimestamp": null, + "labels": { + "io.kompose.service": "db" + }, + "annotations": { + "kompose.volume.type": "persistentVolumeClaim" + } + }, + "spec": { + "volumes": [ + { + "name": "db-data", + "persistentVolumeClaim": { + "claimName": "db-data" + } + } + ], + "containers": [ + { + "name": "db", + "image": "mysql", + "resources": {}, + "volumeMounts": [ + { + "name": "db-data", + "mountPath": "/var/lib/mysql" + } + ] + } + ], + "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": "100Mi" + } + } + }, + "status": {} + }, + { + "kind": "Deployment", + "apiVersion": "apps/v1", + "metadata": { + "name": "web", + "creationTimestamp": null, + "labels": { + "io.kompose.service": "web" + }, + "annotations": { + "kompose.volume.type": "configMap" + } + }, + "spec": { + "replicas": 1, + "selector": { + "matchLabels": { + "io.kompose.service": "web" + } + }, + "template": { + "metadata": { + "creationTimestamp": null, + "labels": { + "io.kompose.service": "web" + }, + "annotations": { + "kompose.volume.type": "configMap" + } + }, + "spec": { + "volumes": [ + { + "name": "web-cm0", + "configMap": { + "name": "web-cm0" + } + }, + { + "name": "web-cm1", + "configMap": { + "name": "web-cm1", + "items": [ + { + "key": "a.key", + "path": "test-a-key.key" + } + ] + } + } + ], + "containers": [ + { + "name": "web", + "image": "nginx", + "resources": {}, + "volumeMounts": [ + { + "name": "web-cm0", + "mountPath": "/etc/tls" + }, + { + "name": "web-cm1", + "mountPath": "/etc/test-a-key.key", + "subPath": "test-a-key.key" + } + ] + } + ], + "restartPolicy": "Always" + } + }, + "strategy": { + "type": "Recreate" + } + }, + "status": {} + }, + { + "kind": "ConfigMap", + "apiVersion": "v1", + "metadata": { + "name": "web-cm0", + "creationTimestamp": null, + "labels": { + "io.kompose.service": "web" + } + }, + "data": { + "a.crt": "test-crt-data...", + "a.key": "test-key-data...." + } + }, + { + "kind": "ConfigMap", + "apiVersion": "v1", + "metadata": { + "name": "web-cm1", + "creationTimestamp": null, + "labels": { + "io.kompose.service": "web" + }, + "annotations": { + "use-subpath": "true" + } + }, + "data": { + "a.key": "test-key-data...." + } + } + ] +} diff --git a/script/test/fixtures/multiple-type-volumes/output-os.json b/script/test/fixtures/multiple-type-volumes/output-os.json new file mode 100644 index 00000000..f2fcf529 --- /dev/null +++ b/script/test/fixtures/multiple-type-volumes/output-os.json @@ -0,0 +1,312 @@ +{ + "kind": "List", + "apiVersion": "v1", + "metadata": {}, + "items": [ + { + "kind": "DeploymentConfig", + "apiVersion": "v1", + "metadata": { + "name": "db", + "creationTimestamp": null, + "labels": { + "io.kompose.service": "db" + }, + "annotations": { + "kompose.volume.type": "persistentVolumeClaim" + } + }, + "spec": { + "strategy": { + "type": "Recreate", + "resources": {} + }, + "triggers": [ + { + "type": "ConfigChange" + }, + { + "type": "ImageChange", + "imageChangeParams": { + "automatic": true, + "containerNames": [ + "db" + ], + "from": { + "kind": "ImageStreamTag", + "name": "db:latest" + } + } + } + ], + "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": " ", + "resources": {}, + "volumeMounts": [ + { + "name": "db-data", + "mountPath": "/var/lib/mysql" + } + ] + } + ], + "restartPolicy": "Always" + } + } + }, + "status": { + "latestVersion": 0, + "observedGeneration": 0, + "replicas": 0, + "updatedReplicas": 0, + "availableReplicas": 0, + "unavailableReplicas": 0 + } + }, + { + "kind": "ImageStream", + "apiVersion": "v1", + "metadata": { + "name": "db", + "creationTimestamp": null, + "labels": { + "io.kompose.service": "db" + } + }, + "spec": { + "lookupPolicy": { + "local": false + }, + "tags": [ + { + "name": "", + "annotations": null, + "from": { + "kind": "DockerImage", + "name": "mysql" + }, + "generation": null, + "importPolicy": {}, + "referencePolicy": { + "type": "" + } + } + ] + }, + "status": { + "dockerImageRepository": "" + } + }, + { + "kind": "PersistentVolumeClaim", + "apiVersion": "v1", + "metadata": { + "name": "db-data", + "creationTimestamp": null, + "labels": { + "io.kompose.service": "db-data" + } + }, + "spec": { + "accessModes": [ + "ReadWriteOnce" + ], + "resources": { + "requests": { + "storage": "100Mi" + } + } + }, + "status": {} + }, + { + "kind": "DeploymentConfig", + "apiVersion": "v1", + "metadata": { + "name": "web", + "creationTimestamp": null, + "labels": { + "io.kompose.service": "web" + }, + "annotations": { + "kompose.volume.type": "configMap" + } + }, + "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-cm0", + "configMap": { + "name": "web-cm0" + } + }, + { + "name": "web-cm1", + "configMap": { + "name": "web-cm1", + "items": [ + { + "key": "a.key", + "path": "test-a-key.key" + } + ] + } + } + ], + "containers": [ + { + "name": "web", + "image": " ", + "resources": {}, + "volumeMounts": [ + { + "name": "web-cm0", + "mountPath": "/etc/tls" + }, + { + "name": "web-cm1", + "mountPath": "/etc/test-a-key.key", + "subPath": "test-a-key.key" + } + ] + } + ], + "restartPolicy": "Always" + } + } + }, + "status": { + "latestVersion": 0, + "observedGeneration": 0, + "replicas": 0, + "updatedReplicas": 0, + "availableReplicas": 0, + "unavailableReplicas": 0 + } + }, + { + "kind": "ImageStream", + "apiVersion": "v1", + "metadata": { + "name": "web", + "creationTimestamp": null, + "labels": { + "io.kompose.service": "web" + } + }, + "spec": { + "lookupPolicy": { + "local": false + }, + "tags": [ + { + "name": "", + "annotations": null, + "from": { + "kind": "DockerImage", + "name": "nginx" + }, + "generation": null, + "importPolicy": {}, + "referencePolicy": { + "type": "" + } + } + ] + }, + "status": { + "dockerImageRepository": "" + } + }, + { + "kind": "ConfigMap", + "apiVersion": "v1", + "metadata": { + "name": "web-cm0", + "creationTimestamp": null, + "labels": { + "io.kompose.service": "web" + } + }, + "data": { + "a.crt": "test-crt-data...", + "a.key": "test-key-data...." + } + }, + { + "kind": "ConfigMap", + "apiVersion": "v1", + "metadata": { + "name": "web-cm1", + "creationTimestamp": null, + "labels": { + "io.kompose.service": "web" + }, + "annotations": { + "use-subpath": "true" + } + }, + "data": { + "a.key": "test-key-data...." + } + } + ] +} diff --git a/script/test/fixtures/multiple-type-volumes/tls/a.crt b/script/test/fixtures/multiple-type-volumes/tls/a.crt new file mode 100644 index 00000000..6fc24b77 --- /dev/null +++ b/script/test/fixtures/multiple-type-volumes/tls/a.crt @@ -0,0 +1 @@ +test-crt-data... \ No newline at end of file diff --git a/script/test/fixtures/multiple-type-volumes/tls/a.key b/script/test/fixtures/multiple-type-volumes/tls/a.key new file mode 100644 index 00000000..1a0782b1 --- /dev/null +++ b/script/test/fixtures/multiple-type-volumes/tls/a.key @@ -0,0 +1 @@ +test-key-data.... \ No newline at end of file