diff --git a/pkg/transformer/kubernetes/kubernetes.go b/pkg/transformer/kubernetes/kubernetes.go index 688bb27e..e041cf2a 100644 --- a/pkg/transformer/kubernetes/kubernetes.go +++ b/pkg/transformer/kubernetes/kubernetes.go @@ -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)) diff --git a/script/test/cmd/tests.sh b/script/test/cmd/tests.sh index 8f8c9157..02f16369 100755 --- a/script/test/cmd/tests.sh +++ b/script/test/cmd/tests.sh @@ -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 diff --git a/script/test/fixtures/controller/compose-global.yml b/script/test/fixtures/controller/compose-global.yml new file mode 100644 index 00000000..c7f74348 --- /dev/null +++ b/script/test/fixtures/controller/compose-global.yml @@ -0,0 +1,6 @@ +version: '3' +services: + worker: + image: dockersamples/examplevotingapp_worker + deploy: + mode: global \ No newline at end of file diff --git a/script/test/fixtures/controller/output-k8s-global-deployment-template.json b/script/test/fixtures/controller/output-k8s-global-deployment-template.json new file mode 100644 index 00000000..11314ca0 --- /dev/null +++ b/script/test/fixtures/controller/output-k8s-global-deployment-template.json @@ -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": {} + } + ] +} \ No newline at end of file diff --git a/script/test/fixtures/controller/output-k8s-global-template.json b/script/test/fixtures/controller/output-k8s-global-template.json new file mode 100644 index 00000000..d3c59890 --- /dev/null +++ b/script/test/fixtures/controller/output-k8s-global-template.json @@ -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 + } + } + ] +} \ No newline at end of file diff --git a/script/test/fixtures/v3/output-deploy-mode-k8s-template.json b/script/test/fixtures/v3/output-deploy-mode-k8s-template.json index 6d646512..37fff9ea 100644 --- a/script/test/fixtures/v3/output-deploy-mode-k8s-template.json +++ b/script/test/fixtures/v3/output-deploy-mode-k8s-template.json @@ -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 + } } ] -} +} \ No newline at end of file diff --git a/script/test/fixtures/v3/output-deploy-mode-os-template.json b/script/test/fixtures/v3/output-deploy-mode-os-template.json index 57ea2aff..ee24990b 100644 --- a/script/test/fixtures/v3/output-deploy-mode-os-template.json +++ b/script/test/fixtures/v3/output-deploy-mode-os-template.json @@ -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", @@ -127,4 +168,4 @@ } } ] -} +} \ No newline at end of file