From e7f05588bf8bd645000612faa136b1b6aa0d5bb6 Mon Sep 17 00:00:00 2001 From: Hang Yan Date: Sun, 5 Jan 2020 19:30:41 +0800 Subject: [PATCH] Support deploy update_config (#1232) --- docs/conversion.md | 2 +- pkg/kobject/kobject.go | 88 ++++- pkg/loader/compose/v3.go | 4 + pkg/transformer/kubernetes/kubernetes.go | 9 + pkg/transformer/openshift/openshift.go | 10 + script/test/cmd/tests.sh | 31 +- .../placement/docker-compose-array.yml | 8 - .../fixtures/placement/docker-compose.yml | 10 - .../placement/output-k8s-array-template.json | 60 --- .../placement/output-k8s-template.json | 61 --- .../placement/output-os-array-template.json | 100 ----- .../placement/output-os-template.json | 101 ----- .../v3/docker-compose-deploy-mode.yaml | 12 - .../fixtures/v3/docker-compose-deploy.yaml | 34 ++ ...s-template.json => output-deploy-k8s.json} | 152 ++++--- .../v3/output-deploy-mode-k8s-template.json | 84 ---- script/test/fixtures/v3/output-deploy-os.json | 374 ++++++++++++++++++ 17 files changed, 602 insertions(+), 538 deletions(-) delete mode 100644 script/test/fixtures/placement/docker-compose-array.yml delete mode 100644 script/test/fixtures/placement/docker-compose.yml delete mode 100644 script/test/fixtures/placement/output-k8s-array-template.json delete mode 100644 script/test/fixtures/placement/output-k8s-template.json delete mode 100644 script/test/fixtures/placement/output-os-array-template.json delete mode 100644 script/test/fixtures/placement/output-os-template.json delete mode 100644 script/test/fixtures/v3/docker-compose-deploy-mode.yaml create mode 100644 script/test/fixtures/v3/docker-compose-deploy.yaml rename script/test/fixtures/v3/{output-deploy-mode-os-template.json => output-deploy-k8s.json} (58%) delete mode 100644 script/test/fixtures/v3/output-deploy-mode-k8s-template.json create mode 100644 script/test/fixtures/v3/output-deploy-os.json diff --git a/docs/conversion.md b/docs/conversion.md index e52302f8..1a8e87f5 100644 --- a/docs/conversion.md +++ b/docs/conversion.md @@ -32,7 +32,7 @@ __Glossary:__ | deploy: mode | - | - | ✓ | | | | deploy: replicas | - | - | ✓ | Deployment.Spec.Replicas / DeploymentConfig.Spec.Replicas | | | deploy: placement | - | - | ✓ | Pod.Spec.NodeSelector | | -| deploy: update_config | - | - | n | | | +| deploy: update_config | - | - | ✓ | Workload.Spec.Strategy | Deployment / DeploymentConfig | | deploy: resources | - | - | ✓ | Containers.Resources.Limits.Memory / Containers.Resources.Limits.CPU | Support for memory as well as cpu | | deploy: restart_policy | - | - | ✓ | Pod generation | This generated a Pod, see the [user guide on restart](http://kompose.io/user-guide/#restart) | | deploy: labels | - | - | ✓ | Workload.Metadata.Labels | Only applied to workload resource | | diff --git a/pkg/kobject/kobject.go b/pkg/kobject/kobject.go index eff29876..1ca950ed 100644 --- a/pkg/kobject/kobject.go +++ b/pkg/kobject/kobject.go @@ -19,9 +19,14 @@ package kobject import ( dockerCliTypes "github.com/docker/cli/cli/compose/types" "github.com/docker/libcompose/yaml" + deployapi "github.com/openshift/origin/pkg/deploy/api" "github.com/pkg/errors" + "github.com/spf13/cast" "k8s.io/kubernetes/pkg/api" + "k8s.io/kubernetes/pkg/apis/extensions" + "k8s.io/kubernetes/pkg/util/intstr" "path/filepath" + "time" ) // KomposeObject holds the generic struct of Kompose transformation @@ -114,15 +119,16 @@ type ServiceConfig struct { MemReservation yaml.MemStringorInt `compose:""` DeployMode string `compose:""` // DeployLabels mapping to kubernetes labels - DeployLabels map[string]string `compose:""` - TmpFs []string `compose:"tmpfs"` - Dockerfile string `compose:"dockerfile"` - Replicas int `compose:"replicas"` - GroupAdd []int64 `compose:"group_add"` - Volumes []Volumes `compose:""` - Secrets []dockerCliTypes.ServiceSecretConfig - HealthChecks HealthCheck `compose:""` - Placement map[string]string `compose:""` + DeployLabels map[string]string `compose:""` + DeployUpdateConfig dockerCliTypes.UpdateConfig `compose:""` + TmpFs []string `compose:"tmpfs"` + Dockerfile string `compose:"dockerfile"` + Replicas int `compose:"replicas"` + GroupAdd []int64 `compose:"group_add"` + Volumes []Volumes `compose:""` + Secrets []dockerCliTypes.ServiceSecretConfig + HealthChecks HealthCheck `compose:""` + Placement map[string]string `compose:""` //This is for long LONG SYNTAX link(https://docs.docker.com/compose/compose-file/#long-syntax) Configs []dockerCliTypes.ServiceConfigObjConfig `compose:""` //This is for SHORT SYNTAX link(https://docs.docker.com/compose/compose-file/#configs) @@ -188,3 +194,67 @@ func (s *ServiceConfig) GetConfigMapKeyFromMeta(name string) (string, error) { return filepath.Base(config.File), nil } + +// GetUpdateStrategy from compose update_config +// 1. only apply to Deployment, but the check is not happened here +// 2. only support `parallelism` and `order` +// return nil if not support +func (s *ServiceConfig) GetKubernetesUpdateStrategy() *extensions.RollingUpdateDeployment { + config := s.DeployUpdateConfig + r := extensions.RollingUpdateDeployment{} + if config.Order == "stop-first" { + if config.Parallelism != nil { + r.MaxUnavailable = intstr.FromInt(cast.ToInt(*config.Parallelism)) + + } + r.MaxSurge = intstr.FromInt(0) + return &r + } + + if config.Order == "start-first" { + if config.Parallelism != nil { + r.MaxSurge = intstr.FromInt(cast.ToInt(*config.Parallelism)) + } + r.MaxUnavailable = intstr.FromInt(0) + return &r + } + return nil + +} + +func (s *ServiceConfig) GetOCUpdateStrategy() *deployapi.RollingDeploymentStrategyParams { + config := s.DeployUpdateConfig + r := deployapi.RollingDeploymentStrategyParams{} + + delay := time.Second * 1 + if config.Delay != 0 { + delay = config.Delay + } + + interval := cast.ToInt64(delay.Seconds()) + + if config.Order == "stop-first" { + if config.Parallelism != nil { + r.MaxUnavailable = intstr.FromInt(cast.ToInt(*config.Parallelism)) + } + r.MaxSurge = intstr.FromInt(0) + r.UpdatePeriodSeconds = &interval + return &r + } + + if config.Order == "start-first" { + if config.Parallelism != nil { + r.MaxSurge = intstr.FromInt(cast.ToInt(*config.Parallelism)) + } + r.MaxUnavailable = intstr.FromInt(0) + r.UpdatePeriodSeconds = &interval + return &r + } + + if cast.ToInt64(config.Delay) != 0 { + r.UpdatePeriodSeconds = &interval + return &r + } + + return nil +} diff --git a/pkg/loader/compose/v3.go b/pkg/loader/compose/v3.go index fd7d0e53..e2b4a5ab 100755 --- a/pkg/loader/compose/v3.go +++ b/pkg/loader/compose/v3.go @@ -351,6 +351,10 @@ func dockerComposeToKomposeMapping(composeObject *types.Config) (kobject.Kompose // placement: serviceConfig.Placement = loadV3Placement(composeServiceConfig.Deploy.Placement.Constraints) + if composeServiceConfig.Deploy.UpdateConfig != nil { + serviceConfig.DeployUpdateConfig = *composeServiceConfig.Deploy.UpdateConfig + } + // TODO: Build is not yet supported, see: // https://github.com/docker/cli/blob/master/cli/compose/types/types.go#L9 // We will have to *manually* add this / parse. diff --git a/pkg/transformer/kubernetes/kubernetes.go b/pkg/transformer/kubernetes/kubernetes.go index c3a6e6f5..9ae6be43 100755 --- a/pkg/transformer/kubernetes/kubernetes.go +++ b/pkg/transformer/kubernetes/kubernetes.go @@ -411,6 +411,15 @@ func (k *Kubernetes) InitD(name string, service kobject.ServiceConfig, replicas } dc.Spec.Template.Labels = transformer.ConfigLabels(name) + update := service.GetKubernetesUpdateStrategy() + if update != nil { + dc.Spec.Strategy = extensions.DeploymentStrategy{ + Type: extensions.RollingUpdateDeploymentStrategyType, + RollingUpdate: update, + } + log.Debugf("Set deployment '%s' rolling update: MaxSurge: %s, MaxUnavailable: %s", name, update.MaxSurge.String(), update.MaxUnavailable.String()) + } + return dc } diff --git a/pkg/transformer/openshift/openshift.go b/pkg/transformer/openshift/openshift.go index 9fdd4a11..9c3b992f 100644 --- a/pkg/transformer/openshift/openshift.go +++ b/pkg/transformer/openshift/openshift.go @@ -232,6 +232,16 @@ func (o *OpenShift) initDeploymentConfig(name string, service kobject.ServiceCon }, }, } + + update := service.GetOCUpdateStrategy() + if update != nil { + dc.Spec.Strategy = deployapi.DeploymentStrategy{ + Type: deployapi.DeploymentStrategyTypeRolling, + RollingParams: update, + } + log.Debugf("Set deployment '%s' rolling update: MaxSurge: %s, MaxUnavailable: %s", name, update.MaxSurge.String(), update.MaxUnavailable.String()) + } + return dc } diff --git a/script/test/cmd/tests.sh b/script/test/cmd/tests.sh index 5cd034d7..4c218abf 100755 --- a/script/test/cmd/tests.sh +++ b/script/test/cmd/tests.sh @@ -652,12 +652,12 @@ convert::expect_success "$cmd" "/tmp/output-oc.json" # Test V3 Support of Docker Compose # 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 +cmd="kompose convert --stdout -j -f $KOMPOSE_ROOT/script/test/fixtures/v3/docker-compose-deploy.yaml" +sed -e "s;%VERSION%;$version;g" -e "s;%CMD%;$cmd;g" "$KOMPOSE_ROOT/script/test/fixtures/v3/output-deploy-k8s.json" > /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 +cmd="kompose convert --stdout -j --provider=openshift -f $KOMPOSE_ROOT/script/test/fixtures/v3/docker-compose-deploy.yaml" +sed -e "s;%VERSION%;$version;g" -e "s;%CMD%;$cmd;g" "$KOMPOSE_ROOT/script/test/fixtures/v3/output-deploy-os.json" > /tmp/output-os.json convert::expect_success "$cmd" "/tmp/output-os.json" # Test support for cpu and memory limits + reservations @@ -735,29 +735,6 @@ cmd="kompose convert -f $KOMPOSE_ROOT/script/test/fixtures/controller/docker-com sed -e "s;%VERSION%;$version;g" -e "s;%CMD%;$cmd;g" $KOMPOSE_ROOT/script/test/fixtures/controller/output-k8s-rc-template.json > /tmp/output-k8s.json convert::expect_success "$cmd" "/tmp/output-k8s.json" -# Test the `placement` key in v3 - -# Kubernetes -cmd="kompose convert --stdout -j -f $KOMPOSE_ROOT/script/test/fixtures/placement/docker-compose.yml" -sed -e "s;%VERSION%;$version;g" -e "s;%CMD%;$cmd;g" $KOMPOSE_ROOT/script/test/fixtures/placement/output-k8s-template.json > /tmp/output-k8s.json -convert::expect_success "$cmd" "/tmp/output-k8s.json" - -## OpenShift -cmd="kompose convert --provider=openshift --stdout -j -f $KOMPOSE_ROOT/script/test/fixtures/placement/docker-compose.yml" -sed -e "s;%VERSION%;$version;g" -e "s;%CMD%;$cmd;g" $KOMPOSE_ROOT/script/test/fixtures/placement/output-os-template.json > /tmp/output-os.json -convert::expect_success "$cmd" "/tmp/output-os.json" - -# Test the `placement` key with constraints in array in v3 - -# Kubernetes -cmd="kompose convert --stdout -j -f $KOMPOSE_ROOT/script/test/fixtures/placement/docker-compose-array.yml" -sed -e "s;%VERSION%;$version;g" -e "s;%CMD%;$cmd;g" $KOMPOSE_ROOT/script/test/fixtures/placement/output-k8s-array-template.json > /tmp/output-k8s.json -convert::expect_success "$cmd" "/tmp/output-k8s.json" - -## OpenShift -cmd="kompose convert --provider=openshift --stdout -j -f $KOMPOSE_ROOT/script/test/fixtures/placement/docker-compose-array.yml" -sed -e "s;%VERSION%;$version;g" -e "s;%CMD%;$cmd;g" $KOMPOSE_ROOT/script/test/fixtures/placement/output-os-array-template.json > /tmp/output-os.json -convert::expect_success "$cmd" "/tmp/output-os.json" # Test the "full example" from https://raw.githubusercontent.com/aanand/compose-file/master/loader/example1.env diff --git a/script/test/fixtures/placement/docker-compose-array.yml b/script/test/fixtures/placement/docker-compose-array.yml deleted file mode 100644 index b7af3b39..00000000 --- a/script/test/fixtures/placement/docker-compose-array.yml +++ /dev/null @@ -1,8 +0,0 @@ -version: '3' -services: - db: - image: postgres - deploy: - placement: - constraints: [node.hostname == machine] - diff --git a/script/test/fixtures/placement/docker-compose.yml b/script/test/fixtures/placement/docker-compose.yml deleted file mode 100644 index 5b48d155..00000000 --- a/script/test/fixtures/placement/docker-compose.yml +++ /dev/null @@ -1,10 +0,0 @@ -version: '3' -services: - db: - image: postgres - deploy: - placement: - constraints: - - node.hostname == machine - - engine.labels.operatingsystem == ubuntu 14.04 - diff --git a/script/test/fixtures/placement/output-k8s-array-template.json b/script/test/fixtures/placement/output-k8s-array-template.json deleted file mode 100644 index 53cff666..00000000 --- a/script/test/fixtures/placement/output-k8s-array-template.json +++ /dev/null @@ -1,60 +0,0 @@ -{ - "kind": "List", - "apiVersion": "v1", - "metadata": {}, - "items": [ - { - "apiVersion": "apps/v1", - "kind": "Deployment", - "metadata": { - "annotations": { - "kompose.cmd": "%CMD%", - "kompose.version": "%VERSION%" - }, - "creationTimestamp": null, - "labels": { - "io.kompose.service": "db" - }, - "name": "db" - }, - "spec": { - "replicas": 1, - "selector": { - "matchLabels": { - "io.kompose.service": "db" - } - }, - "strategy": {}, - "template": { - "metadata": { - "annotations": { - "kompose.cmd": "%CMD%", - "kompose.version": "%VERSION%" - }, - "creationTimestamp": null, - "labels": { - "io.kompose.service": "db" - } - }, - "spec": { - "containers": [ - { - "image": "postgres", - "imagePullPolicy": "", - "name": "db", - "resources": {} - } - ], - "nodeSelector": { - "kubernetes.io/hostname": "machine" - }, - "restartPolicy": "Always", - "serviceAccountName": "", - "volumes": null - } - } - }, - "status": {} - } - ] -} diff --git a/script/test/fixtures/placement/output-k8s-template.json b/script/test/fixtures/placement/output-k8s-template.json deleted file mode 100644 index 04cb369f..00000000 --- a/script/test/fixtures/placement/output-k8s-template.json +++ /dev/null @@ -1,61 +0,0 @@ -{ - "kind": "List", - "apiVersion": "v1", - "metadata": {}, - "items": [ - { - "apiVersion": "apps/v1", - "kind": "Deployment", - "metadata": { - "annotations": { - "kompose.cmd": "%CMD%", - "kompose.version": "%VERSION%" - }, - "creationTimestamp": null, - "labels": { - "io.kompose.service": "db" - }, - "name": "db" - }, - "spec": { - "replicas": 1, - "selector": { - "matchLabels": { - "io.kompose.service": "db" - } - }, - "strategy": {}, - "template": { - "metadata": { - "annotations": { - "kompose.cmd": "%CMD%", - "kompose.version": "%VERSION%" - }, - "creationTimestamp": null, - "labels": { - "io.kompose.service": "db" - } - }, - "spec": { - "containers": [ - { - "image": "postgres", - "imagePullPolicy": "", - "name": "db", - "resources": {} - } - ], - "nodeSelector": { - "beta.kubernetes.io/os": "ubuntu 14.04", - "kubernetes.io/hostname": "machine" - }, - "restartPolicy": "Always", - "serviceAccountName": "", - "volumes": null - } - } - }, - "status": {} - } - ] -} diff --git a/script/test/fixtures/placement/output-os-array-template.json b/script/test/fixtures/placement/output-os-array-template.json deleted file mode 100644 index a85c95d6..00000000 --- a/script/test/fixtures/placement/output-os-array-template.json +++ /dev/null @@ -1,100 +0,0 @@ -{ - "kind": "List", - "apiVersion": "v1", - "metadata": {}, - "items": [ - { - "kind": "DeploymentConfig", - "apiVersion": "v1", - "metadata": { - "name": "db", - "creationTimestamp": null, - "labels": { - "io.kompose.service": "db" - }, - "annotations": { - "kompose.cmd": "%CMD%", - "kompose.version": "%VERSION%" - } - }, - "spec": { - "strategy": { - "resources": {} - }, - "triggers": [ - { - "type": "ConfigChange" - }, - { - "type": "ImageChange", - "imageChangeParams": { - "automatic": true, - "containerNames": [ - "db" - ], - "from": { - "kind": "ImageStreamTag", - "name": "db:latest" - } - } - } - ], - "replicas": 1, - "test": false, - "selector": { - "io.kompose.service": "db" - }, - "template": { - "metadata": { - "creationTimestamp": null, - "labels": { - "io.kompose.service": "db" - } - }, - "spec": { - "containers": [ - { - "name": "db", - "image": " ", - "resources": {} - } - ], - "restartPolicy": "Always", - "nodeSelector": { - "kubernetes.io/hostname": "machine" - } - } - } - }, - "status": {} - }, - { - "kind": "ImageStream", - "apiVersion": "v1", - "metadata": { - "name": "db", - "creationTimestamp": null, - "labels": { - "io.kompose.service": "db" - } - }, - "spec": { - "tags": [ - { - "name": "latest", - "annotations": null, - "from": { - "kind": "DockerImage", - "name": "postgres" - }, - "generation": null, - "importPolicy": {} - } - ] - }, - "status": { - "dockerImageRepository": "" - } - } - ] -} diff --git a/script/test/fixtures/placement/output-os-template.json b/script/test/fixtures/placement/output-os-template.json deleted file mode 100644 index e44760b6..00000000 --- a/script/test/fixtures/placement/output-os-template.json +++ /dev/null @@ -1,101 +0,0 @@ -{ - "kind": "List", - "apiVersion": "v1", - "metadata": {}, - "items": [ - { - "kind": "DeploymentConfig", - "apiVersion": "v1", - "metadata": { - "name": "db", - "creationTimestamp": null, - "labels": { - "io.kompose.service": "db" - }, - "annotations": { - "kompose.cmd": "%CMD%", - "kompose.version": "%VERSION%" - } - }, - "spec": { - "strategy": { - "resources": {} - }, - "triggers": [ - { - "type": "ConfigChange" - }, - { - "type": "ImageChange", - "imageChangeParams": { - "automatic": true, - "containerNames": [ - "db" - ], - "from": { - "kind": "ImageStreamTag", - "name": "db:latest" - } - } - } - ], - "replicas": 1, - "test": false, - "selector": { - "io.kompose.service": "db" - }, - "template": { - "metadata": { - "creationTimestamp": null, - "labels": { - "io.kompose.service": "db" - } - }, - "spec": { - "containers": [ - { - "name": "db", - "image": " ", - "resources": {} - } - ], - "restartPolicy": "Always", - "nodeSelector": { - "beta.kubernetes.io/os": "ubuntu 14.04", - "kubernetes.io/hostname": "machine" - } - } - } - }, - "status": {} - }, - { - "kind": "ImageStream", - "apiVersion": "v1", - "metadata": { - "name": "db", - "creationTimestamp": null, - "labels": { - "io.kompose.service": "db" - } - }, - "spec": { - "tags": [ - { - "name": "latest", - "annotations": null, - "from": { - "kind": "DockerImage", - "name": "postgres" - }, - "generation": null, - "importPolicy": {} - } - ] - }, - "status": { - "dockerImageRepository": "" - } - } - ] -} diff --git a/script/test/fixtures/v3/docker-compose-deploy-mode.yaml b/script/test/fixtures/v3/docker-compose-deploy-mode.yaml deleted file mode 100644 index 1be9f38c..00000000 --- a/script/test/fixtures/v3/docker-compose-deploy-mode.yaml +++ /dev/null @@ -1,12 +0,0 @@ -version: "3" - -services: - foo: - labels: - kompose.service.type: headless - deploy: - mode: global - replicas: 6 - labels: - com.example.description: "This label will appear on the web service" - image: redis diff --git a/script/test/fixtures/v3/docker-compose-deploy.yaml b/script/test/fixtures/v3/docker-compose-deploy.yaml new file mode 100644 index 00000000..fa7ed37c --- /dev/null +++ b/script/test/fixtures/v3/docker-compose-deploy.yaml @@ -0,0 +1,34 @@ +version: "3.7" +services: + vote: # test placement and update_config + image: dockersamples/examplevotingapp_vote:before + depends_on: + - redis + deploy: + replicas: 2 + placement: + constraints: [node.hostname == machine] + update_config: + parallelism: 2 + delay: 10s + order: stop-first + db: # test placement + image: postgres + deploy: + placement: + constraints: + - node.hostname == machine + - engine.labels.operatingsystem == ubuntu 14.04 + foo: # test labels + labels: + kompose.service.type: headless + deploy: + mode: global + replicas: 6 + update_config: + parallelism: 2 + delay: 10s + order: stop-first + labels: + com.example.description: "This label will appear on the web service" + image: redis diff --git a/script/test/fixtures/v3/output-deploy-mode-os-template.json b/script/test/fixtures/v3/output-deploy-k8s.json similarity index 58% rename from script/test/fixtures/v3/output-deploy-mode-os-template.json rename to script/test/fixtures/v3/output-deploy-k8s.json index de028572..f9b17628 100644 --- a/script/test/fixtures/v3/output-deploy-mode-os-template.json +++ b/script/test/fixtures/v3/output-deploy-k8s.json @@ -35,6 +35,60 @@ "loadBalancer": {} } }, + { + "apiVersion": "apps/v1", + "kind": "Deployment", + "metadata": { + "annotations": { + "kompose.cmd": "%CMD%", + "kompose.version": "%VERSION%" + }, + "creationTimestamp": null, + "labels": { + "io.kompose.service": "db" + }, + "name": "db" + }, + "spec": { + "replicas": 1, + "selector": { + "matchLabels": { + "io.kompose.service": "db" + } + }, + "strategy": {}, + "template": { + "metadata": { + "annotations": { + "kompose.cmd": "%CMD%", + "kompose.version": "%VERSION%" + }, + "creationTimestamp": null, + "labels": { + "io.kompose.service": "db" + } + }, + "spec": { + "containers": [ + { + "image": "postgres", + "imagePullPolicy": "", + "name": "db", + "resources": {} + } + ], + "nodeSelector": { + "beta.kubernetes.io/os": "ubuntu 14.04", + "kubernetes.io/hostname": "machine" + }, + "restartPolicy": "Always", + "serviceAccountName": "", + "volumes": null + } + } + }, + "status": {} + }, { "apiVersion": "apps/v1", "kind": "DaemonSet", @@ -81,95 +135,63 @@ } }, { - "kind": "DeploymentConfig", - "apiVersion": "v1", + "apiVersion": "apps/v1", + "kind": "Deployment", "metadata": { - "name": "foo", - "creationTimestamp": null, - "labels": { - "io.kompose.service": "foo" - }, "annotations": { "kompose.cmd": "%CMD%", - "kompose.service.type": "headless", "kompose.version": "%VERSION%" - } + }, + "creationTimestamp": null, + "labels": { + "io.kompose.service": "vote" + }, + "name": "vote" }, "spec": { - "strategy": { - "resources": {} - }, - "triggers": [ - { - "type": "ConfigChange" - }, - { - "type": "ImageChange", - "imageChangeParams": { - "automatic": true, - "containerNames": [ - "foo" - ], - "from": { - "kind": "ImageStreamTag", - "name": "foo:latest" - } - } - } - ], - "replicas": 1, - "test": false, + "replicas": 2, "selector": { - "io.kompose.service": "foo" + "matchLabels": { + "io.kompose.service": "vote" + } + }, + "strategy": { + "rollingUpdate": { + "maxSurge": 0, + "maxUnavailable": 2 + }, + "type": "RollingUpdate" }, "template": { "metadata": { + "annotations": { + "kompose.cmd": "%CMD%", + "kompose.version": "%VERSION%" + }, "creationTimestamp": null, "labels": { - "io.kompose.service": "foo" + "io.kompose.service": "vote" } }, "spec": { "containers": [ { - "name": "foo", - "image": " ", + "image": "dockersamples/examplevotingapp_vote:before", + "imagePullPolicy": "", + "name": "vote", "resources": {} } ], - "restartPolicy": "Always" + "nodeSelector": { + "kubernetes.io/hostname": "machine" + }, + "restartPolicy": "Always", + "serviceAccountName": "", + "volumes": null } } }, "status": {} - }, - { - "kind": "ImageStream", - "apiVersion": "v1", - "metadata": { - "name": "foo", - "creationTimestamp": null, - "labels": { - "io.kompose.service": "foo" - } - }, - "spec": { - "tags": [ - { - "name": "latest", - "annotations": null, - "from": { - "kind": "DockerImage", - "name": "redis" - }, - "generation": null, - "importPolicy": {} - } - ] - }, - "status": { - "dockerImageRepository": "" - } } ] } diff --git a/script/test/fixtures/v3/output-deploy-mode-k8s-template.json b/script/test/fixtures/v3/output-deploy-mode-k8s-template.json deleted file mode 100644 index c4b8da49..00000000 --- a/script/test/fixtures/v3/output-deploy-mode-k8s-template.json +++ /dev/null @@ -1,84 +0,0 @@ -{ - "kind": "List", - "apiVersion": "v1", - "metadata": {}, - "items": [ - { - "kind": "Service", - "apiVersion": "v1", - "metadata": { - "name": "foo", - "creationTimestamp": null, - "labels": { - "io.kompose.service": "foo" - }, - "annotations": { - "kompose.cmd": "%CMD%", - "kompose.service.type": "headless", - "kompose.version": "%VERSION%" - } - }, - "spec": { - "ports": [ - { - "name": "headless", - "port": 55555, - "targetPort": 0 - } - ], - "selector": { - "io.kompose.service": "foo" - }, - "clusterIP": "None" - }, - "status": { - "loadBalancer": {} - } - }, - { - "apiVersion": "apps/v1", - "kind": "DaemonSet", - "metadata": { - "annotations": { - "kompose.cmd": "%CMD%", - "kompose.service.type": "headless", - "kompose.version": "%VERSION%" - }, - "creationTimestamp": null, - "labels": { - "com.example.description": "This label will appear on the web service", - "io.kompose.service": "foo" - }, - "name": "foo" - }, - "spec": { - "template": { - "metadata": { - "creationTimestamp": null, - "labels": { - "io.kompose.service": "foo" - } - }, - "spec": { - "containers": [ - { - "image": "redis", - "imagePullPolicy": "", - "name": "foo", - "resources": {} - } - ], - "restartPolicy": "Always", - "serviceAccountName": "", - "volumes": null - } - } - }, - "status": { - "currentNumberScheduled": 0, - "desiredNumberScheduled": 0, - "numberMisscheduled": 0 - } - } - ] -} diff --git a/script/test/fixtures/v3/output-deploy-os.json b/script/test/fixtures/v3/output-deploy-os.json new file mode 100644 index 00000000..096b4d4d --- /dev/null +++ b/script/test/fixtures/v3/output-deploy-os.json @@ -0,0 +1,374 @@ +{ + "kind": "List", + "apiVersion": "v1", + "metadata": {}, + "items": [ + { + "kind": "Service", + "apiVersion": "v1", + "metadata": { + "name": "foo", + "creationTimestamp": null, + "labels": { + "io.kompose.service": "foo" + }, + "annotations": { + "kompose.cmd": "%CMD%", + "kompose.service.type": "headless", + "kompose.version": "%VERSION%" + } + }, + "spec": { + "ports": [ + { + "name": "headless", + "port": 55555, + "targetPort": 0 + } + ], + "selector": { + "io.kompose.service": "foo" + }, + "clusterIP": "None" + }, + "status": { + "loadBalancer": {} + } + }, + { + "kind": "DeploymentConfig", + "apiVersion": "v1", + "metadata": { + "name": "db", + "creationTimestamp": null, + "labels": { + "io.kompose.service": "db" + }, + "annotations": { + "kompose.cmd": "%CMD%", + "kompose.version": "%VERSION%" + } + }, + "spec": { + "strategy": { + "resources": {} + }, + "triggers": [ + { + "type": "ConfigChange" + }, + { + "type": "ImageChange", + "imageChangeParams": { + "automatic": true, + "containerNames": [ + "db" + ], + "from": { + "kind": "ImageStreamTag", + "name": "db:latest" + } + } + } + ], + "replicas": 1, + "test": false, + "selector": { + "io.kompose.service": "db" + }, + "template": { + "metadata": { + "creationTimestamp": null, + "labels": { + "io.kompose.service": "db" + } + }, + "spec": { + "containers": [ + { + "name": "db", + "image": " ", + "resources": {} + } + ], + "restartPolicy": "Always", + "nodeSelector": { + "beta.kubernetes.io/os": "ubuntu 14.04", + "kubernetes.io/hostname": "machine" + } + } + } + }, + "status": {} + }, + { + "kind": "ImageStream", + "apiVersion": "v1", + "metadata": { + "name": "db", + "creationTimestamp": null, + "labels": { + "io.kompose.service": "db" + } + }, + "spec": { + "tags": [ + { + "name": "latest", + "annotations": null, + "from": { + "kind": "DockerImage", + "name": "postgres" + }, + "generation": null, + "importPolicy": {} + } + ] + }, + "status": { + "dockerImageRepository": "" + } + }, + { + "apiVersion": "apps/v1", + "kind": "DaemonSet", + "metadata": { + "annotations": { + "kompose.cmd": "%CMD%", + "kompose.service.type": "headless", + "kompose.version": "%VERSION%" + }, + "creationTimestamp": null, + "labels": { + "com.example.description": "This label will appear on the web service", + "io.kompose.service": "foo" + }, + "name": "foo" + }, + "spec": { + "template": { + "metadata": { + "creationTimestamp": null, + "labels": { + "io.kompose.service": "foo" + } + }, + "spec": { + "containers": [ + { + "image": "redis", + "imagePullPolicy": "", + "name": "foo", + "resources": {} + } + ], + "restartPolicy": "Always", + "serviceAccountName": "", + "volumes": null + } + } + }, + "status": { + "currentNumberScheduled": 0, + "desiredNumberScheduled": 0, + "numberMisscheduled": 0 + } + }, + { + "kind": "DeploymentConfig", + "apiVersion": "v1", + "metadata": { + "name": "foo", + "creationTimestamp": null, + "labels": { + "io.kompose.service": "foo" + }, + "annotations": { + "kompose.cmd": "%CMD%", + "kompose.service.type": "headless", + "kompose.version": "%VERSION%" + } + }, + "spec": { + "strategy": { + "type": "Rolling", + "rollingParams": { + "updatePeriodSeconds": 10, + "maxUnavailable": 2, + "maxSurge": 0 + }, + "resources": {} + }, + "triggers": [ + { + "type": "ConfigChange" + }, + { + "type": "ImageChange", + "imageChangeParams": { + "automatic": true, + "containerNames": [ + "foo" + ], + "from": { + "kind": "ImageStreamTag", + "name": "foo:latest" + } + } + } + ], + "replicas": 1, + "test": false, + "selector": { + "io.kompose.service": "foo" + }, + "template": { + "metadata": { + "creationTimestamp": null, + "labels": { + "io.kompose.service": "foo" + } + }, + "spec": { + "containers": [ + { + "name": "foo", + "image": " ", + "resources": {} + } + ], + "restartPolicy": "Always" + } + } + }, + "status": {} + }, + { + "kind": "ImageStream", + "apiVersion": "v1", + "metadata": { + "name": "foo", + "creationTimestamp": null, + "labels": { + "io.kompose.service": "foo" + } + }, + "spec": { + "tags": [ + { + "name": "latest", + "annotations": null, + "from": { + "kind": "DockerImage", + "name": "redis" + }, + "generation": null, + "importPolicy": {} + } + ] + }, + "status": { + "dockerImageRepository": "" + } + }, + { + "kind": "DeploymentConfig", + "apiVersion": "v1", + "metadata": { + "name": "vote", + "creationTimestamp": null, + "labels": { + "io.kompose.service": "vote" + }, + "annotations": { + "kompose.cmd": "%CMD%", + "kompose.version": "%VERSION%" + } + }, + "spec": { + "strategy": { + "type": "Rolling", + "rollingParams": { + "updatePeriodSeconds": 10, + "maxUnavailable": 2, + "maxSurge": 0 + }, + "resources": {} + }, + "triggers": [ + { + "type": "ConfigChange" + }, + { + "type": "ImageChange", + "imageChangeParams": { + "automatic": true, + "containerNames": [ + "vote" + ], + "from": { + "kind": "ImageStreamTag", + "name": "vote:before" + } + } + } + ], + "replicas": 2, + "test": false, + "selector": { + "io.kompose.service": "vote" + }, + "template": { + "metadata": { + "creationTimestamp": null, + "labels": { + "io.kompose.service": "vote" + } + }, + "spec": { + "containers": [ + { + "name": "vote", + "image": " ", + "resources": {} + } + ], + "restartPolicy": "Always", + "nodeSelector": { + "kubernetes.io/hostname": "machine" + } + } + } + }, + "status": {} + }, + { + "kind": "ImageStream", + "apiVersion": "v1", + "metadata": { + "name": "vote", + "creationTimestamp": null, + "labels": { + "io.kompose.service": "vote" + } + }, + "spec": { + "tags": [ + { + "name": "before", + "annotations": null, + "from": { + "kind": "DockerImage", + "name": "dockersamples/examplevotingapp_vote:before" + }, + "generation": null, + "importPolicy": {} + } + ] + }, + "status": { + "dockerImageRepository": "" + } + } + ] +}