Skip to content

Commit

Permalink
fix driver:local in prefixing volumes
Browse files Browse the repository at this point in the history
If we have a docker-file with root level volumes and we do a kompose up
using that docker-file, libcompose will add an additional _ followed by
the current directory name. Since kubernetes doesn't allow _ in the
objects created so kompose up will fail to deploy it. As a solution we
replace _ to - and we can then deploy it successfully.
  • Loading branch information
Abhishek committed Apr 26, 2017
1 parent f1d2268 commit 7eccb37
Show file tree
Hide file tree
Showing 5 changed files with 776 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pkg/loader/compose/compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,8 @@ func (c *Compose) LoadFile(files []string) (kobject.KomposeObject, error) {

if composeServiceConfig.Volumes != nil {
for _, volume := range composeServiceConfig.Volumes.Volumes {
serviceConfig.Volumes = append(serviceConfig.Volumes, volume.String())
v := normalizeServiceNames(volume.String())
serviceConfig.Volumes = append(serviceConfig.Volumes, v)
}
}

Expand Down
8 changes: 8 additions & 0 deletions script/test/cmd/tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,14 @@ convert::expect_success "kompose --provider openshift -f $KOMPOSE_ROOT/script/te
# when kompose.service.expose="<hostname>" and multiple ports in docker compose file (first port should be selected)
convert::expect_success "kompose --provider openshift -f $KOMPOSE_ROOT/script/test/fixtures/expose-service/compose-files/docker-compose-expose-hostname-multiple-ports.yml convert --stdout -j" "$KOMPOSE_ROOT/script/test/fixtures/expose-service/provider-files/openshift-expose-hostname-multiple-ports.json"


# Test the change in the service name
# Kubernetes Test
convert::expect_success_and_warning "kompose -f $KOMPOSE_ROOT/script/test/fixtures/service-name-change/docker-compose.yml convert --stdout -j" "$KOMPOSE_ROOT/script/test/fixtures/service-name-change/output-k8s.json" "Unsupported root level volumes key - ignoring"
# Openshift Test
convert::expect_success_and_warning "kompose --provider openshift -f $KOMPOSE_ROOT/script/test/fixtures/service-name-change/docker-compose.yml convert --stdout -j" "$KOMPOSE_ROOT/script/test/fixtures/service-name-change/output-os.json" "Unsupported root level volumes key - ignoring"


######
# Test the output file behavior of kompose convert
# Default behavior without -o
Expand Down
36 changes: 36 additions & 0 deletions script/test/fixtures/service-name-change/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
version: '2'
services:
mariadb:
image: 'bitnami/mariadb:latest'
volumes:
- 'mariadb-data:/bitnami/mariadb'
environment:
- MARIADB_USER=bn_wordpress
- MARIADB_DATABASE=bitnami_wordpress
- ALLOW_EMPTY_PASSWORD=yes
wordpress:
image: 'bitnami/wordpress:latest'
ports:
- '80:80'
- '443:443'
volumes:
- 'wordpress-data:/bitnami/wordpress'
- 'apache-data:/bitnami/apache'
- 'php-data:/bitnami/php'
depends_on:
- mariadb
environment:
- MARIADB_HOST=mariadb
- MARIADB_PORT=3306
- WORDPRESS_DATABASE_USER=bn_wordpress
- WORDPRESS_DATABASE_NAME=bitnami_wordpress
- ALLOW_EMPTY_PASSWORD=yes
volumes:
mariadb-data:
driver: local
wordpress-data:
driver: local
apache-data:
driver: local
php-data:
driver: local
311 changes: 311 additions & 0 deletions script/test/fixtures/service-name-change/output-k8s.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,311 @@
{
"kind": "List",
"apiVersion": "v1",
"metadata": {},
"items": [
{
"kind": "Service",
"apiVersion": "v1",
"metadata": {
"name": "mariadb",
"creationTimestamp": null,
"labels": {
"io.kompose.service": "mariadb"
}
},
"spec": {
"ports": [
{
"name": "headless",
"port": 55555,
"targetPort": 0
}
],
"selector": {
"io.kompose.service": "mariadb"
},
"clusterIP": "None"
},
"status": {
"loadBalancer": {}
}
},
{
"kind": "Service",
"apiVersion": "v1",
"metadata": {
"name": "wordpress",
"creationTimestamp": null,
"labels": {
"io.kompose.service": "wordpress"
}
},
"spec": {
"ports": [
{
"name": "80",
"port": 80,
"targetPort": 80
},
{
"name": "443",
"port": 443,
"targetPort": 443
}
],
"selector": {
"io.kompose.service": "wordpress"
}
},
"status": {
"loadBalancer": {}
}
},
{
"kind": "Deployment",
"apiVersion": "extensions/v1beta1",
"metadata": {
"name": "mariadb",
"creationTimestamp": null
},
"spec": {
"replicas": 1,
"template": {
"metadata": {
"creationTimestamp": null,
"labels": {
"io.kompose.service": "mariadb"
}
},
"spec": {
"volumes": [
{
"name": "servicenamechange-mariadb-data",
"persistentVolumeClaim": {
"claimName": "servicenamechange-mariadb-data"
}
}
],
"containers": [
{
"name": "mariadb",
"image": "bitnami/mariadb:latest",
"env": [
{
"name": "MARIADB_USER",
"value": "bn_wordpress"
},
{
"name": "MARIADB_DATABASE",
"value": "bitnami_wordpress"
},
{
"name": "ALLOW_EMPTY_PASSWORD",
"value": "yes"
}
],
"resources": {},
"volumeMounts": [
{
"name": "servicenamechange-mariadb-data",
"mountPath": "/bitnami/mariadb"
}
]
}
],
"restartPolicy": "Always"
}
},
"strategy": {
"type": "Recreate"
}
},
"status": {}
},
{
"kind": "PersistentVolumeClaim",
"apiVersion": "v1",
"metadata": {
"name": "servicenamechange-mariadb-data",
"creationTimestamp": null,
"labels": {
"io.kompose.service": "servicenamechange-mariadb-data"
}
},
"spec": {
"accessModes": [
"ReadWriteOnce"
],
"resources": {
"requests": {
"storage": "100Mi"
}
}
},
"status": {}
},
{
"kind": "Deployment",
"apiVersion": "extensions/v1beta1",
"metadata": {
"name": "wordpress",
"creationTimestamp": null
},
"spec": {
"replicas": 1,
"template": {
"metadata": {
"creationTimestamp": null,
"labels": {
"io.kompose.service": "wordpress"
}
},
"spec": {
"volumes": [
{
"name": "servicenamechange-wordpress-data",
"persistentVolumeClaim": {
"claimName": "servicenamechange-wordpress-data"
}
},
{
"name": "servicenamechange-apache-data",
"persistentVolumeClaim": {
"claimName": "servicenamechange-apache-data"
}
},
{
"name": "servicenamechange-php-data",
"persistentVolumeClaim": {
"claimName": "servicenamechange-php-data"
}
}
],
"containers": [
{
"name": "wordpress",
"image": "bitnami/wordpress:latest",
"ports": [
{
"containerPort": 80
},
{
"containerPort": 443
}
],
"env": [
{
"name": "MARIADB_HOST",
"value": "mariadb"
},
{
"name": "MARIADB_PORT",
"value": "3306"
},
{
"name": "WORDPRESS_DATABASE_USER",
"value": "bn_wordpress"
},
{
"name": "WORDPRESS_DATABASE_NAME",
"value": "bitnami_wordpress"
},
{
"name": "ALLOW_EMPTY_PASSWORD",
"value": "yes"
}
],
"resources": {},
"volumeMounts": [
{
"name": "servicenamechange-wordpress-data",
"mountPath": "/bitnami/wordpress"
},
{
"name": "servicenamechange-apache-data",
"mountPath": "/bitnami/apache"
},
{
"name": "servicenamechange-php-data",
"mountPath": "/bitnami/php"
}
]
}
],
"restartPolicy": "Always"
}
},
"strategy": {
"type": "Recreate"
}
},
"status": {}
},
{
"kind": "PersistentVolumeClaim",
"apiVersion": "v1",
"metadata": {
"name": "servicenamechange-wordpress-data",
"creationTimestamp": null,
"labels": {
"io.kompose.service": "servicenamechange-wordpress-data"
}
},
"spec": {
"accessModes": [
"ReadWriteOnce"
],
"resources": {
"requests": {
"storage": "100Mi"
}
}
},
"status": {}
},
{
"kind": "PersistentVolumeClaim",
"apiVersion": "v1",
"metadata": {
"name": "servicenamechange-apache-data",
"creationTimestamp": null,
"labels": {
"io.kompose.service": "servicenamechange-apache-data"
}
},
"spec": {
"accessModes": [
"ReadWriteOnce"
],
"resources": {
"requests": {
"storage": "100Mi"
}
}
},
"status": {}
},
{
"kind": "PersistentVolumeClaim",
"apiVersion": "v1",
"metadata": {
"name": "servicenamechange-php-data",
"creationTimestamp": null,
"labels": {
"io.kompose.service": "servicenamechange-php-data"
}
},
"spec": {
"accessModes": [
"ReadWriteOnce"
],
"resources": {
"requests": {
"storage": "100Mi"
}
}
},
"status": {}
}
]
}
Loading

0 comments on commit 7eccb37

Please sign in to comment.