forked from LaconicNetwork/kompose
support for volumes_from docker-compose construct
Now a user can provide volumes_from to share volumes from other service so here the PVC created for that service will be shared by service calling volumes_from
This commit is contained in:
parent
d9899b788d
commit
fd09efed43
@ -53,7 +53,6 @@ var unsupportedKey = map[string]int{
|
||||
"ShmSize": 0,
|
||||
"StopSignal": 0,
|
||||
"VolumeDriver": 0,
|
||||
"VolumesFrom": 0,
|
||||
"Uts": 0,
|
||||
"ReadOnly": 0,
|
||||
"StdinOpen": 0,
|
||||
@ -150,6 +149,7 @@ type ServiceConfig struct {
|
||||
Privileged bool
|
||||
Restart string
|
||||
User string
|
||||
VolumesFrom []string
|
||||
}
|
||||
|
||||
// EnvVar holds the environment variable struct of a container
|
||||
|
||||
@ -193,6 +193,7 @@ func (c *Compose) LoadFile(file string) kobject.KomposeObject {
|
||||
serviceConfig.Privileged = composeServiceConfig.Privileged
|
||||
serviceConfig.Restart = composeServiceConfig.Restart
|
||||
serviceConfig.User = composeServiceConfig.User
|
||||
serviceConfig.VolumesFrom = composeServiceConfig.VolumesFrom
|
||||
|
||||
komposeObject.ServiceConfigs[name] = serviceConfig
|
||||
}
|
||||
|
||||
@ -333,3 +333,53 @@ func SortServicesFirst(objs *[]runtime.Object) {
|
||||
ret = append(ret, others...)
|
||||
*objs = ret
|
||||
}
|
||||
|
||||
func findDependentVolumes(svcname string, komposeObject kobject.KomposeObject) (volumes []api.Volume, volumeMounts []api.VolumeMount) {
|
||||
// Get all the volumes and volumemounts this particular service is dependent on
|
||||
for _, dependentSvc := range komposeObject.ServiceConfigs[svcname].VolumesFrom {
|
||||
vols, volMounts := findDependentVolumes(dependentSvc, komposeObject)
|
||||
volumes = append(volumes, vols...)
|
||||
volumeMounts = append(volumeMounts, volMounts...)
|
||||
}
|
||||
// add the volumes info of this service
|
||||
volMounts, vols, _ := ConfigVolumes(svcname, komposeObject.ServiceConfigs[svcname])
|
||||
volumes = append(volumes, vols...)
|
||||
volumeMounts = append(volumeMounts, volMounts...)
|
||||
return
|
||||
}
|
||||
|
||||
func VolumesFrom(objects *[]runtime.Object, komposeObject kobject.KomposeObject) {
|
||||
|
||||
for _, obj := range *objects {
|
||||
switch t := obj.(type) {
|
||||
case *api.ReplicationController:
|
||||
svcName := t.ObjectMeta.Name
|
||||
for _, dependentSvc := range komposeObject.ServiceConfigs[svcName].VolumesFrom {
|
||||
volumes, volumeMounts := findDependentVolumes(dependentSvc, komposeObject)
|
||||
t.Spec.Template.Spec.Volumes = append(t.Spec.Template.Spec.Volumes, volumes...)
|
||||
t.Spec.Template.Spec.Containers[0].VolumeMounts = append(t.Spec.Template.Spec.Containers[0].VolumeMounts, volumeMounts...)
|
||||
}
|
||||
case *extensions.Deployment:
|
||||
svcName := t.ObjectMeta.Name
|
||||
for _, dependentSvc := range komposeObject.ServiceConfigs[svcName].VolumesFrom {
|
||||
volumes, volumeMounts := findDependentVolumes(dependentSvc, komposeObject)
|
||||
t.Spec.Template.Spec.Volumes = append(t.Spec.Template.Spec.Volumes, volumes...)
|
||||
t.Spec.Template.Spec.Containers[0].VolumeMounts = append(t.Spec.Template.Spec.Containers[0].VolumeMounts, volumeMounts...)
|
||||
}
|
||||
case *extensions.DaemonSet:
|
||||
svcName := t.ObjectMeta.Name
|
||||
for _, dependentSvc := range komposeObject.ServiceConfigs[svcName].VolumesFrom {
|
||||
volumes, volumeMounts := findDependentVolumes(dependentSvc, komposeObject)
|
||||
t.Spec.Template.Spec.Volumes = append(t.Spec.Template.Spec.Volumes, volumes...)
|
||||
t.Spec.Template.Spec.Containers[0].VolumeMounts = append(t.Spec.Template.Spec.Containers[0].VolumeMounts, volumeMounts...)
|
||||
}
|
||||
case *deployapi.DeploymentConfig:
|
||||
svcName := t.ObjectMeta.Name
|
||||
for _, dependentSvc := range komposeObject.ServiceConfigs[svcName].VolumesFrom {
|
||||
volumes, volumeMounts := findDependentVolumes(dependentSvc, komposeObject)
|
||||
t.Spec.Template.Spec.Volumes = append(t.Spec.Template.Spec.Volumes, volumes...)
|
||||
t.Spec.Template.Spec.Containers[0].VolumeMounts = append(t.Spec.Template.Spec.Containers[0].VolumeMounts, volumeMounts...)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -307,6 +307,8 @@ func (k *Kubernetes) Transform(komposeObject kobject.KomposeObject, opt kobject.
|
||||
|
||||
allobjects = append(allobjects, objects...)
|
||||
}
|
||||
// If docker-compose has a volumes_from directive it will be handled here
|
||||
VolumesFrom(&allobjects, komposeObject)
|
||||
// sort all object so Services are first
|
||||
SortServicesFirst(&allobjects)
|
||||
return allobjects
|
||||
|
||||
@ -160,6 +160,8 @@ func (k *OpenShift) Transform(komposeObject kobject.KomposeObject, opt kobject.C
|
||||
|
||||
allobjects = append(allobjects, objects...)
|
||||
}
|
||||
// If docker-compose has a volumes_from directive it will be handled here
|
||||
kubernetes.VolumesFrom(&allobjects, komposeObject)
|
||||
// sort all object so Services are first
|
||||
kubernetes.SortServicesFirst(&allobjects)
|
||||
return allobjects
|
||||
|
||||
@ -56,6 +56,15 @@ convert::expect_success "kompose --provider=openshift -f $KOMPOSE_ROOT/script/te
|
||||
# kubernetes test
|
||||
convert::expect_success "kompose -f $KOMPOSE_ROOT/script/test/fixtures/volume-mounts/simple-vol-mounts/docker-compose.yml convert --stdout" "$KOMPOSE_ROOT/script/test/fixtures/volume-mounts/simple-vol-mounts/output-k8s.json"
|
||||
# openshift test
|
||||
convert::expect_success "kompose --provider=openshift -f $KOMPOSE_ROOT/script/test/fixtures/volume-mounts/simple-vol-mounts/docker-compose.yml convert --stdout --dc" "$KOMPOSE_ROOT/script/test/fixtures/volume-mounts/simple-vol-mounts/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" "$KOMPOSE_ROOT/script/test/fixtures/volume-mounts/simple-vol-mounts/output-os.json"
|
||||
|
||||
|
||||
######
|
||||
# Tests related to docker-compose file in /script/test/fixtures/volume-mounts/volumes-from
|
||||
# kubernetes test
|
||||
convert::expect_success_and_warning "kompose -f $KOMPOSE_ROOT/script/test/fixtures/volume-mounts/volumes-from/docker-compose.yml convert --stdout" "$KOMPOSE_ROOT/script/test/fixtures/volume-mounts/volumes-from/output-k8s.json" "ignoring path on the host"
|
||||
# openshift test
|
||||
convert::expect_success_and_warning "kompose --provider=openshift -f $KOMPOSE_ROOT/script/test/fixtures/volume-mounts/volumes-from/docker-compose.yml convert --stdout" "$KOMPOSE_ROOT/script/test/fixtures/volume-mounts/volumes-from/output-os.json" "ignoring path on the host"
|
||||
|
||||
|
||||
exit $EXIT_STATUS
|
||||
|
||||
20
script/test/fixtures/volume-mounts/volumes-from/docker-compose.yml
vendored
Normal file
20
script/test/fixtures/volume-mounts/volumes-from/docker-compose.yml
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
version: "2"
|
||||
|
||||
services:
|
||||
web:
|
||||
image: centos/httpd
|
||||
volumes:
|
||||
- "./app:/src/app"
|
||||
ports:
|
||||
- "3030:3000"
|
||||
command: nodemon -L app/bin/www
|
||||
|
||||
nginx:
|
||||
restart: always
|
||||
image: nginx
|
||||
ports:
|
||||
- "80:80"
|
||||
volumes:
|
||||
- /www/public
|
||||
volumes_from:
|
||||
- web
|
||||
216
script/test/fixtures/volume-mounts/volumes-from/output-k8s.json
vendored
Normal file
216
script/test/fixtures/volume-mounts/volumes-from/output-k8s.json
vendored
Normal file
@ -0,0 +1,216 @@
|
||||
{
|
||||
"kind": "List",
|
||||
"apiVersion": "v1",
|
||||
"metadata": {},
|
||||
"items": [
|
||||
{
|
||||
"kind": "Service",
|
||||
"apiVersion": "v1",
|
||||
"metadata": {
|
||||
"name": "web",
|
||||
"creationTimestamp": null,
|
||||
"labels": {
|
||||
"service": "web"
|
||||
}
|
||||
},
|
||||
"spec": {
|
||||
"ports": [
|
||||
{
|
||||
"name": "3030",
|
||||
"protocol": "TCP",
|
||||
"port": 3030,
|
||||
"targetPort": 3000
|
||||
}
|
||||
],
|
||||
"selector": {
|
||||
"service": "web"
|
||||
}
|
||||
},
|
||||
"status": {
|
||||
"loadBalancer": {}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": "Service",
|
||||
"apiVersion": "v1",
|
||||
"metadata": {
|
||||
"name": "nginx",
|
||||
"creationTimestamp": null,
|
||||
"labels": {
|
||||
"service": "nginx"
|
||||
}
|
||||
},
|
||||
"spec": {
|
||||
"ports": [
|
||||
{
|
||||
"name": "80",
|
||||
"protocol": "TCP",
|
||||
"port": 80,
|
||||
"targetPort": 80
|
||||
}
|
||||
],
|
||||
"selector": {
|
||||
"service": "nginx"
|
||||
}
|
||||
},
|
||||
"status": {
|
||||
"loadBalancer": {}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": "Deployment",
|
||||
"apiVersion": "extensions/v1beta1",
|
||||
"metadata": {
|
||||
"name": "web",
|
||||
"creationTimestamp": null
|
||||
},
|
||||
"spec": {
|
||||
"replicas": 1,
|
||||
"template": {
|
||||
"metadata": {
|
||||
"creationTimestamp": null,
|
||||
"labels": {
|
||||
"service": "web"
|
||||
}
|
||||
},
|
||||
"spec": {
|
||||
"volumes": [
|
||||
{
|
||||
"name": "web-claim0",
|
||||
"persistentVolumeClaim": {
|
||||
"claimName": "web-claim0"
|
||||
}
|
||||
}
|
||||
],
|
||||
"containers": [
|
||||
{
|
||||
"name": "web",
|
||||
"image": "centos/httpd",
|
||||
"args": [
|
||||
"nodemon",
|
||||
"-L",
|
||||
"app/bin/www"
|
||||
],
|
||||
"ports": [
|
||||
{
|
||||
"containerPort": 3000,
|
||||
"protocol": "TCP"
|
||||
}
|
||||
],
|
||||
"resources": {},
|
||||
"volumeMounts": [
|
||||
{
|
||||
"name": "web-claim0",
|
||||
"mountPath": "/src/app"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"restartPolicy": "Always"
|
||||
}
|
||||
},
|
||||
"strategy": {}
|
||||
},
|
||||
"status": {}
|
||||
},
|
||||
{
|
||||
"kind": "PersistentVolumeClaim",
|
||||
"apiVersion": "v1",
|
||||
"metadata": {
|
||||
"name": "web-claim0",
|
||||
"creationTimestamp": null
|
||||
},
|
||||
"spec": {
|
||||
"accessModes": [
|
||||
"ReadWriteOnce"
|
||||
],
|
||||
"resources": {
|
||||
"requests": {
|
||||
"storage": "100Mi"
|
||||
}
|
||||
}
|
||||
},
|
||||
"status": {}
|
||||
},
|
||||
{
|
||||
"kind": "Deployment",
|
||||
"apiVersion": "extensions/v1beta1",
|
||||
"metadata": {
|
||||
"name": "nginx",
|
||||
"creationTimestamp": null
|
||||
},
|
||||
"spec": {
|
||||
"replicas": 1,
|
||||
"template": {
|
||||
"metadata": {
|
||||
"creationTimestamp": null,
|
||||
"labels": {
|
||||
"service": "nginx"
|
||||
}
|
||||
},
|
||||
"spec": {
|
||||
"volumes": [
|
||||
{
|
||||
"name": "nginx-claim0",
|
||||
"persistentVolumeClaim": {
|
||||
"claimName": "nginx-claim0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "web-claim0",
|
||||
"persistentVolumeClaim": {
|
||||
"claimName": "web-claim0"
|
||||
}
|
||||
}
|
||||
],
|
||||
"containers": [
|
||||
{
|
||||
"name": "nginx",
|
||||
"image": "nginx",
|
||||
"ports": [
|
||||
{
|
||||
"containerPort": 80,
|
||||
"protocol": "TCP"
|
||||
}
|
||||
],
|
||||
"resources": {},
|
||||
"volumeMounts": [
|
||||
{
|
||||
"name": "nginx-claim0",
|
||||
"mountPath": "/www/public"
|
||||
},
|
||||
{
|
||||
"name": "web-claim0",
|
||||
"mountPath": "/src/app"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"restartPolicy": "Always"
|
||||
}
|
||||
},
|
||||
"strategy": {}
|
||||
},
|
||||
"status": {}
|
||||
},
|
||||
{
|
||||
"kind": "PersistentVolumeClaim",
|
||||
"apiVersion": "v1",
|
||||
"metadata": {
|
||||
"name": "nginx-claim0",
|
||||
"creationTimestamp": null
|
||||
},
|
||||
"spec": {
|
||||
"accessModes": [
|
||||
"ReadWriteOnce"
|
||||
],
|
||||
"resources": {
|
||||
"requests": {
|
||||
"storage": "100Mi"
|
||||
}
|
||||
}
|
||||
},
|
||||
"status": {}
|
||||
}
|
||||
]
|
||||
}
|
||||
320
script/test/fixtures/volume-mounts/volumes-from/output-os.json
vendored
Normal file
320
script/test/fixtures/volume-mounts/volumes-from/output-os.json
vendored
Normal file
@ -0,0 +1,320 @@
|
||||
{
|
||||
"kind": "List",
|
||||
"apiVersion": "v1",
|
||||
"metadata": {},
|
||||
"items": [
|
||||
{
|
||||
"kind": "Service",
|
||||
"apiVersion": "v1",
|
||||
"metadata": {
|
||||
"name": "nginx",
|
||||
"creationTimestamp": null,
|
||||
"labels": {
|
||||
"service": "nginx"
|
||||
}
|
||||
},
|
||||
"spec": {
|
||||
"ports": [
|
||||
{
|
||||
"name": "80",
|
||||
"protocol": "TCP",
|
||||
"port": 80,
|
||||
"targetPort": 80
|
||||
}
|
||||
],
|
||||
"selector": {
|
||||
"service": "nginx"
|
||||
}
|
||||
},
|
||||
"status": {
|
||||
"loadBalancer": {}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": "Service",
|
||||
"apiVersion": "v1",
|
||||
"metadata": {
|
||||
"name": "web",
|
||||
"creationTimestamp": null,
|
||||
"labels": {
|
||||
"service": "web"
|
||||
}
|
||||
},
|
||||
"spec": {
|
||||
"ports": [
|
||||
{
|
||||
"name": "3030",
|
||||
"protocol": "TCP",
|
||||
"port": 3030,
|
||||
"targetPort": 3000
|
||||
}
|
||||
],
|
||||
"selector": {
|
||||
"service": "web"
|
||||
}
|
||||
},
|
||||
"status": {
|
||||
"loadBalancer": {}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": "DeploymentConfig",
|
||||
"apiVersion": "v1",
|
||||
"metadata": {
|
||||
"name": "nginx",
|
||||
"creationTimestamp": null,
|
||||
"labels": {
|
||||
"service": "nginx"
|
||||
}
|
||||
},
|
||||
"spec": {
|
||||
"strategy": {
|
||||
"resources": {}
|
||||
},
|
||||
"triggers": [
|
||||
{
|
||||
"type": "ConfigChange"
|
||||
},
|
||||
{
|
||||
"type": "ImageChange",
|
||||
"imageChangeParams": {
|
||||
"automatic": true,
|
||||
"containerNames": [
|
||||
"nginx"
|
||||
],
|
||||
"from": {
|
||||
"kind": "ImageStreamTag",
|
||||
"name": "nginx:latest"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"replicas": 1,
|
||||
"test": false,
|
||||
"selector": {
|
||||
"service": "nginx"
|
||||
},
|
||||
"template": {
|
||||
"metadata": {
|
||||
"creationTimestamp": null,
|
||||
"labels": {
|
||||
"service": "nginx"
|
||||
}
|
||||
},
|
||||
"spec": {
|
||||
"volumes": [
|
||||
{
|
||||
"name": "nginx-claim0",
|
||||
"persistentVolumeClaim": {
|
||||
"claimName": "nginx-claim0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "web-claim0",
|
||||
"persistentVolumeClaim": {
|
||||
"claimName": "web-claim0"
|
||||
}
|
||||
}
|
||||
],
|
||||
"containers": [
|
||||
{
|
||||
"name": "nginx",
|
||||
"image": " ",
|
||||
"ports": [
|
||||
{
|
||||
"containerPort": 80,
|
||||
"protocol": "TCP"
|
||||
}
|
||||
],
|
||||
"resources": {},
|
||||
"volumeMounts": [
|
||||
{
|
||||
"name": "nginx-claim0",
|
||||
"mountPath": "/www/public"
|
||||
},
|
||||
{
|
||||
"name": "web-claim0",
|
||||
"mountPath": "/src/app"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"restartPolicy": "Always"
|
||||
}
|
||||
}
|
||||
},
|
||||
"status": {}
|
||||
},
|
||||
{
|
||||
"kind": "ImageStream",
|
||||
"apiVersion": "v1",
|
||||
"metadata": {
|
||||
"name": "nginx",
|
||||
"creationTimestamp": null
|
||||
},
|
||||
"spec": {
|
||||
"tags": [
|
||||
{
|
||||
"name": "latest",
|
||||
"annotations": null,
|
||||
"from": {
|
||||
"kind": "DockerImage",
|
||||
"name": "nginx"
|
||||
},
|
||||
"generation": null,
|
||||
"importPolicy": {}
|
||||
}
|
||||
]
|
||||
},
|
||||
"status": {
|
||||
"dockerImageRepository": ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": "PersistentVolumeClaim",
|
||||
"apiVersion": "v1",
|
||||
"metadata": {
|
||||
"name": "nginx-claim0",
|
||||
"creationTimestamp": null
|
||||
},
|
||||
"spec": {
|
||||
"accessModes": [
|
||||
"ReadWriteOnce"
|
||||
],
|
||||
"resources": {
|
||||
"requests": {
|
||||
"storage": "100Mi"
|
||||
}
|
||||
}
|
||||
},
|
||||
"status": {}
|
||||
},
|
||||
{
|
||||
"kind": "DeploymentConfig",
|
||||
"apiVersion": "v1",
|
||||
"metadata": {
|
||||
"name": "web",
|
||||
"creationTimestamp": null,
|
||||
"labels": {
|
||||
"service": "web"
|
||||
}
|
||||
},
|
||||
"spec": {
|
||||
"strategy": {
|
||||
"resources": {}
|
||||
},
|
||||
"triggers": [
|
||||
{
|
||||
"type": "ConfigChange"
|
||||
},
|
||||
{
|
||||
"type": "ImageChange",
|
||||
"imageChangeParams": {
|
||||
"automatic": true,
|
||||
"containerNames": [
|
||||
"web"
|
||||
],
|
||||
"from": {
|
||||
"kind": "ImageStreamTag",
|
||||
"name": "web:latest"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"replicas": 1,
|
||||
"test": false,
|
||||
"selector": {
|
||||
"service": "web"
|
||||
},
|
||||
"template": {
|
||||
"metadata": {
|
||||
"creationTimestamp": null,
|
||||
"labels": {
|
||||
"service": "web"
|
||||
}
|
||||
},
|
||||
"spec": {
|
||||
"volumes": [
|
||||
{
|
||||
"name": "web-claim0",
|
||||
"persistentVolumeClaim": {
|
||||
"claimName": "web-claim0"
|
||||
}
|
||||
}
|
||||
],
|
||||
"containers": [
|
||||
{
|
||||
"name": "web",
|
||||
"image": " ",
|
||||
"args": [
|
||||
"nodemon",
|
||||
"-L",
|
||||
"app/bin/www"
|
||||
],
|
||||
"ports": [
|
||||
{
|
||||
"containerPort": 3000,
|
||||
"protocol": "TCP"
|
||||
}
|
||||
],
|
||||
"resources": {},
|
||||
"volumeMounts": [
|
||||
{
|
||||
"name": "web-claim0",
|
||||
"mountPath": "/src/app"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"restartPolicy": "Always"
|
||||
}
|
||||
}
|
||||
},
|
||||
"status": {}
|
||||
},
|
||||
{
|
||||
"kind": "ImageStream",
|
||||
"apiVersion": "v1",
|
||||
"metadata": {
|
||||
"name": "web",
|
||||
"creationTimestamp": null
|
||||
},
|
||||
"spec": {
|
||||
"tags": [
|
||||
{
|
||||
"name": "latest",
|
||||
"annotations": null,
|
||||
"from": {
|
||||
"kind": "DockerImage",
|
||||
"name": "centos/httpd"
|
||||
},
|
||||
"generation": null,
|
||||
"importPolicy": {}
|
||||
}
|
||||
]
|
||||
},
|
||||
"status": {
|
||||
"dockerImageRepository": ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": "PersistentVolumeClaim",
|
||||
"apiVersion": "v1",
|
||||
"metadata": {
|
||||
"name": "web-claim0",
|
||||
"creationTimestamp": null
|
||||
},
|
||||
"spec": {
|
||||
"accessModes": [
|
||||
"ReadWriteOnce"
|
||||
],
|
||||
"resources": {
|
||||
"requests": {
|
||||
"storage": "100Mi"
|
||||
}
|
||||
}
|
||||
},
|
||||
"status": {}
|
||||
}
|
||||
]
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user