Skip to content

Commit

Permalink
added support for restart-policy keys in v3
Browse files Browse the repository at this point in the history
Resolves `restart_policy` from issue kubernetes#644
  • Loading branch information
surajnarwade committed Jun 22, 2017
1 parent cf39f78 commit 4b20ac5
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 8 deletions.
6 changes: 3 additions & 3 deletions pkg/loader/compose/v3.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (

"github.com/docker/cli/cli/compose/loader"
"github.com/docker/cli/cli/compose/types"

log "github.com/Sirupsen/logrus"
"github.com/kubernetes-incubator/kompose/pkg/kobject"
"github.com/pkg/errors"
Expand Down Expand Up @@ -183,21 +183,21 @@ func dockerComposeToKomposeMapping(composeObject *types.Config) (kobject.Kompose
serviceConfig.CapDrop = composeServiceConfig.CapDrop
serviceConfig.Expose = composeServiceConfig.Expose
serviceConfig.Privileged = composeServiceConfig.Privileged
serviceConfig.Restart = composeServiceConfig.Restart
serviceConfig.User = composeServiceConfig.User
serviceConfig.Stdin = composeServiceConfig.StdinOpen
serviceConfig.Tty = composeServiceConfig.Tty
serviceConfig.TmpFs = composeServiceConfig.Tmpfs
serviceConfig.ContainerName = composeServiceConfig.ContainerName
serviceConfig.Command = composeServiceConfig.Entrypoint
serviceConfig.Args = composeServiceConfig.Command

// This is a bit messy since we use yaml.MemStringorInt
// TODO: Refactor yaml.MemStringorInt in kobject.go to int64
// Since Deploy.Resources.Limits does not initialize, we must check type Resources before continuing
if (composeServiceConfig.Deploy.Resources != types.Resources{}) {
serviceConfig.MemLimit = libcomposeyaml.MemStringorInt(composeServiceConfig.Deploy.Resources.Limits.MemoryBytes)
}
//Handling restart-policy
serviceConfig.Restart = composeServiceConfig.Deploy.RestartPolicy.Condition

// POOF. volumes_From is gone in v3. docker/cli will error out of volumes_from is added in v3
// serviceConfig.VolumesFrom = composeServiceConfig.VolumesFrom
Expand Down
4 changes: 2 additions & 2 deletions pkg/transformer/kubernetes/k8sutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,9 +441,9 @@ func (k *Kubernetes) UpdateKubernetesObjects(name string, service kobject.Servic

// Configure the container restart policy.
switch service.Restart {
case "", "always":
case "", "always", "any":
template.Spec.RestartPolicy = api.RestartPolicyAlways
case "no":
case "no", "none":
template.Spec.RestartPolicy = api.RestartPolicyNever
case "on-failure":
template.Spec.RestartPolicy = api.RestartPolicyOnFailure
Expand Down
3 changes: 1 addition & 2 deletions script/test/fixtures/v3/output-env-subs.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@
"image": "foo/bar:latest",
"env": [
{
"name": "FOO",
"value": "bar"
"name": "FOO"
}
],
"resources": {}
Expand Down
2 changes: 1 addition & 1 deletion script/test/fixtures/v3/output-k8s-full-example.json
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@
}
},
"spec": {
"replicas": 1,
"replicas": 6,
"template": {
"metadata": {
"creationTimestamp": null,
Expand Down

0 comments on commit 4b20ac5

Please sign in to comment.