Merge pull request #999 from xianlubird/features/global-mode

Support compose global deploy mode to daemonset
This commit is contained in:
Hang Yan 2018-05-07 16:00:33 +08:00 committed by GitHub
commit b0debf7f03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 167 additions and 11 deletions

View File

@ -626,8 +626,14 @@ func (k *Kubernetes) CreateKubernetesObjects(name string, service kobject.Servic
// Check to see if Docker Compose v3 Deploy.Mode has been set to "global"
if service.DeployMode == "global" {
log.Warning("Global mode not yet supported, containers will only be replicated once throughout the cluster. DaemonSet support will be added in the future.")
replica = 1
//default use daemonset
if opt.Controller == "" {
opt.CreateD = false
opt.CreateDS = true
} else if opt.Controller != "daemonset" {
log.Warnf("Global deploy mode service is best converted to daemonset, now it convert to %s", opt.Controller)
}
}
if opt.CreateD || opt.Controller == "deployment" {
objects = append(objects, k.InitD(name, service, replica))

View File

@ -541,11 +541,11 @@ convert::expect_success "$cmd" "/tmp/output-k8s.json"
# Test deploy mode: global
cmd="kompose convert --stdout -j -f $KOMPOSE_ROOT/script/test/fixtures/v3/docker-compose-deploy-mode.yaml"
sed -e "s;%VERSION%;$version;g" -e "s;%CMD%;$cmd;g" "$KOMPOSE_ROOT/script/test/fixtures/v3/output-deploy-mode-k8s-template.json" > /tmp/output-k8s.json
convert::expect_success_and_warning "$cmd" "/tmp/output-k8s.json"
convert::expect_success "$cmd" "/tmp/output-k8s.json"
cmd="kompose convert --stdout -j --provider=openshift -f $KOMPOSE_ROOT/script/test/fixtures/v3/docker-compose-deploy-mode.yaml"
sed -e "s;%VERSION%;$version;g" -e "s;%CMD%;$cmd;g" "$KOMPOSE_ROOT/script/test/fixtures/v3/output-deploy-mode-os-template.json" > /tmp/output-os.json
convert::expect_success_and_warning "$cmd" "/tmp/output-os.json"
convert::expect_success "$cmd" "/tmp/output-os.json"
# Test support for cpu and memory limits + reservations
cmd="kompose convert --stdout -j -f $KOMPOSE_ROOT/script/test/fixtures/v3/docker-compose-memcpu.yaml"
@ -732,5 +732,14 @@ cmd="kompose convert --provider=openshift --stdout -j -f $KOMPOSE_ROOT/examples/
sed -e "s;%VERSION%;$version;g" -e "s;%CMD%;$cmd;g" $KOMPOSE_ROOT/script/test/fixtures/examples/output-gitlab-os.json > /tmp/output-os.json
convert::expect_success_and_warning "$cmd" "/tmp/output-os.json"
## Test compose v3 global deploy
cmd="kompose convert --stdout -j -f $KOMPOSE_ROOT/script/test/fixtures/controller/compose-global.yml"
sed -e "s;%VERSION%;$version;g" -e "s;%CMD%;$cmd;g" $KOMPOSE_ROOT/script/test/fixtures/controller/output-k8s-global-template.json > /tmp/output-k8s.json
convert::expect_success "$cmd" "/tmp/output-k8s.json"
cmd="kompose convert --controller deployment --stdout -j -f $KOMPOSE_ROOT/script/test/fixtures/controller/compose-global.yml"
sed -e "s;%VERSION%;$version;g" -e "s;%CMD%;$cmd;g" $KOMPOSE_ROOT/script/test/fixtures/controller/output-k8s-global-deployment-template.json > /tmp/output-k8s.json
convert::expect_success_and_warning "$cmd" "/tmp/output-k8s.json"
rm /tmp/output-k8s.json /tmp/output-os.json
exit $EXIT_STATUS

View File

@ -0,0 +1,6 @@
version: '3'
services:
worker:
image: dockersamples/examplevotingapp_worker
deploy:
mode: global

View File

@ -0,0 +1,45 @@
{
"kind": "List",
"apiVersion": "v1",
"metadata": {},
"items": [
{
"kind": "Deployment",
"apiVersion": "extensions/v1beta1",
"metadata": {
"name": "worker",
"creationTimestamp": null,
"labels": {
"io.kompose.service": "worker"
},
"annotations": {
"kompose.cmd": "%CMD%",
"kompose.version": "%VERSION%"
}
},
"spec": {
"replicas": 1,
"template": {
"metadata": {
"creationTimestamp": null,
"labels": {
"io.kompose.service": "worker"
}
},
"spec": {
"containers": [
{
"name": "worker",
"image": "dockersamples/examplevotingapp_worker",
"resources": {}
}
],
"restartPolicy": "Always"
}
},
"strategy": {}
},
"status": {}
}
]
}

View File

@ -0,0 +1,47 @@
{
"kind": "List",
"apiVersion": "v1",
"metadata": {},
"items": [
{
"kind": "DaemonSet",
"apiVersion": "extensions/v1beta1",
"metadata": {
"name": "worker",
"creationTimestamp": null,
"labels": {
"io.kompose.service": "worker"
},
"annotations": {
"kompose.cmd": "%CMD%",
"kompose.version": "%VERSION%"
}
},
"spec": {
"template": {
"metadata": {
"creationTimestamp": null,
"labels": {
"io.kompose.service": "worker"
}
},
"spec": {
"containers": [
{
"name": "worker",
"image": "dockersamples/examplevotingapp_worker",
"resources": {}
}
],
"restartPolicy": "Always"
}
}
},
"status": {
"currentNumberScheduled": 0,
"numberMisscheduled": 0,
"desiredNumberScheduled": 0
}
}
]
}

View File

@ -36,7 +36,7 @@
}
},
{
"kind": "Deployment",
"kind": "DaemonSet",
"apiVersion": "extensions/v1beta1",
"metadata": {
"name": "foo",
@ -51,7 +51,6 @@
}
},
"spec": {
"replicas": 1,
"template": {
"metadata": {
"creationTimestamp": null,
@ -69,10 +68,13 @@
],
"restartPolicy": "Always"
}
}
},
"strategy": {}
},
"status": {}
"status": {
"currentNumberScheduled": 0,
"numberMisscheduled": 0,
"desiredNumberScheduled": 0
}
}
]
}

View File

@ -35,6 +35,47 @@
"loadBalancer": {}
}
},
{
"kind": "DaemonSet",
"apiVersion": "extensions/v1beta1",
"metadata": {
"name": "foo",
"creationTimestamp": null,
"labels": {
"io.kompose.service": "foo"
},
"annotations": {
"kompose.cmd": "%CMD%",
"kompose.service.type": "headless",
"kompose.version": "%VERSION%"
}
},
"spec": {
"template": {
"metadata": {
"creationTimestamp": null,
"labels": {
"io.kompose.service": "foo"
}
},
"spec": {
"containers": [
{
"name": "foo",
"image": "redis",
"resources": {}
}
],
"restartPolicy": "Always"
}
}
},
"status": {
"currentNumberScheduled": 0,
"numberMisscheduled": 0,
"desiredNumberScheduled": 0
}
},
{
"kind": "DeploymentConfig",
"apiVersion": "v1",