forked from LaconicNetwork/kompose
Merge pull request #999 from xianlubird/features/global-mode
Support compose global deploy mode to daemonset
This commit is contained in:
commit
b0debf7f03
@ -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"
|
// Check to see if Docker Compose v3 Deploy.Mode has been set to "global"
|
||||||
if service.DeployMode == "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.")
|
//default use daemonset
|
||||||
replica = 1
|
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" {
|
if opt.CreateD || opt.Controller == "deployment" {
|
||||||
objects = append(objects, k.InitD(name, service, replica))
|
objects = append(objects, k.InitD(name, service, replica))
|
||||||
|
|||||||
@ -541,11 +541,11 @@ convert::expect_success "$cmd" "/tmp/output-k8s.json"
|
|||||||
# Test deploy mode: global
|
# Test deploy mode: global
|
||||||
cmd="kompose convert --stdout -j -f $KOMPOSE_ROOT/script/test/fixtures/v3/docker-compose-deploy-mode.yaml"
|
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
|
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"
|
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
|
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
|
# Test support for cpu and memory limits + reservations
|
||||||
cmd="kompose convert --stdout -j -f $KOMPOSE_ROOT/script/test/fixtures/v3/docker-compose-memcpu.yaml"
|
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
|
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"
|
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
|
rm /tmp/output-k8s.json /tmp/output-os.json
|
||||||
exit $EXIT_STATUS
|
exit $EXIT_STATUS
|
||||||
|
|||||||
6
script/test/fixtures/controller/compose-global.yml
vendored
Normal file
6
script/test/fixtures/controller/compose-global.yml
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
version: '3'
|
||||||
|
services:
|
||||||
|
worker:
|
||||||
|
image: dockersamples/examplevotingapp_worker
|
||||||
|
deploy:
|
||||||
|
mode: global
|
||||||
45
script/test/fixtures/controller/output-k8s-global-deployment-template.json
vendored
Normal file
45
script/test/fixtures/controller/output-k8s-global-deployment-template.json
vendored
Normal 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": {}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
47
script/test/fixtures/controller/output-k8s-global-template.json
vendored
Normal file
47
script/test/fixtures/controller/output-k8s-global-template.json
vendored
Normal 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@ -36,7 +36,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"kind": "Deployment",
|
"kind": "DaemonSet",
|
||||||
"apiVersion": "extensions/v1beta1",
|
"apiVersion": "extensions/v1beta1",
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"name": "foo",
|
"name": "foo",
|
||||||
@ -51,7 +51,6 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"spec": {
|
"spec": {
|
||||||
"replicas": 1,
|
|
||||||
"template": {
|
"template": {
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"creationTimestamp": null,
|
"creationTimestamp": null,
|
||||||
@ -69,10 +68,13 @@
|
|||||||
],
|
],
|
||||||
"restartPolicy": "Always"
|
"restartPolicy": "Always"
|
||||||
}
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"strategy": {}
|
"status": {
|
||||||
},
|
"currentNumberScheduled": 0,
|
||||||
"status": {}
|
"numberMisscheduled": 0,
|
||||||
|
"desiredNumberScheduled": 0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@ -35,6 +35,47 @@
|
|||||||
"loadBalancer": {}
|
"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",
|
"kind": "DeploymentConfig",
|
||||||
"apiVersion": "v1",
|
"apiVersion": "v1",
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user