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 97aac5b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 6 additions & 2 deletions pkg/loader/compose/v3.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/docker/cli/cli/compose/loader"
"github.com/docker/cli/cli/compose/types"

"fmt"
log "github.com/Sirupsen/logrus"
"github.com/kubernetes-incubator/kompose/pkg/kobject"
"github.com/pkg/errors"
Expand Down Expand Up @@ -183,21 +184,24 @@ func dockerComposeToKomposeMapping(composeObject *types.Config) (kobject.Kompose
serviceConfig.CapDrop = composeServiceConfig.CapDrop
serviceConfig.Expose = composeServiceConfig.Expose
serviceConfig.Privileged = composeServiceConfig.Privileged
serviceConfig.Restart = composeServiceConfig.Restart
// 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

fmt.Println("ser policy", serviceConfig.Restart)
// 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
fmt.Println("restart policy", serviceConfig.Restart)

// 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

0 comments on commit 97aac5b

Please sign in to comment.