forked from LaconicNetwork/kompose
Merge pull request #608 from gitlawr/stop_grace_period
Add support for stop_grace_period
This commit is contained in:
commit
8938fa13f5
@ -35,7 +35,7 @@ This document outlines all the conversion details regarding `docker-compose.yaml
|
||||
| pid | | N | | |
|
||||
| ports | | Y | [Service.Spec.Ports](https://kubernetes.io/docs/api-reference/v1/definitions/#_v1_containerport) | |
|
||||
| security_opt | | N | | |
|
||||
| stop_grace_period | | N | | |
|
||||
| stop_grace_period | | Y | [Pod.Spec.TerminationGracePeriodSeconds](https://kubernetes.io/docs/resources-reference/v1.6/#podspec-v1-core) | |
|
||||
| stop_signal | | N | | |
|
||||
| sysctls | | N | | |
|
||||
| ulimits | | N | | See this [issue](https://github.com/kubernetes/kubernetes/issues/3595) on the k8s repo |
|
||||
|
||||
@ -59,36 +59,37 @@ type ConvertOptions struct {
|
||||
// ServiceConfig holds the basic struct of a container
|
||||
type ServiceConfig struct {
|
||||
// use tags to mark from what element this value comes
|
||||
ContainerName string
|
||||
Image string `compose:"image" bundle:"Image"`
|
||||
Environment []EnvVar `compose:"environment" bundle:"Env"`
|
||||
Port []Ports `compose:"ports" bundle:"Ports"`
|
||||
Command []string `compose:"command" bundle:"Command"`
|
||||
WorkingDir string `compose:"" bundle:"WorkingDir"`
|
||||
Args []string `compose:"args" bundle:"Args"`
|
||||
Volumes []string `compose:"volumes" bundle:"Volumes"`
|
||||
Network []string `compose:"network" bundle:"Networks"`
|
||||
Labels map[string]string `compose:"labels" bundle:"Labels"`
|
||||
Annotations map[string]string `compose:"" bundle:""`
|
||||
CPUSet string `compose:"cpuset" bundle:""`
|
||||
CPUShares int64 `compose:"cpu_shares" bundle:""`
|
||||
CPUQuota int64 `compose:"cpu_quota" bundle:""`
|
||||
CapAdd []string `compose:"cap_add" bundle:""`
|
||||
CapDrop []string `compose:"cap_drop" bundle:""`
|
||||
Expose []string `compose:"expose" bundle:""`
|
||||
Privileged bool `compose:"privileged" bundle:""`
|
||||
Restart string `compose:"restart" bundle:""`
|
||||
User string `compose:"user" bundle:"User"`
|
||||
VolumesFrom []string `compose:"volumes_from" bundle:""`
|
||||
ServiceType string `compose:"kompose.service.type" bundle:""`
|
||||
Build string `compose:"build" bundle:""`
|
||||
BuildArgs map[string]*string `compose:"build-args" bundle:""`
|
||||
ExposeService string `compose:"kompose.service.expose" bundle:""`
|
||||
Stdin bool `compose:"stdin_open" bundle:""`
|
||||
Tty bool `compose:"tty" bundle:""`
|
||||
MemLimit yaml.MemStringorInt `compose:"mem_limit" bundle:""`
|
||||
TmpFs []string `compose:"tmpfs" bundle:""`
|
||||
Dockerfile string `compose:"dockerfile" bundle:""`
|
||||
ContainerName string
|
||||
Image string `compose:"image" bundle:"Image"`
|
||||
Environment []EnvVar `compose:"environment" bundle:"Env"`
|
||||
Port []Ports `compose:"ports" bundle:"Ports"`
|
||||
Command []string `compose:"command" bundle:"Command"`
|
||||
WorkingDir string `compose:"" bundle:"WorkingDir"`
|
||||
Args []string `compose:"args" bundle:"Args"`
|
||||
Volumes []string `compose:"volumes" bundle:"Volumes"`
|
||||
Network []string `compose:"network" bundle:"Networks"`
|
||||
Labels map[string]string `compose:"labels" bundle:"Labels"`
|
||||
Annotations map[string]string `compose:"" bundle:""`
|
||||
CPUSet string `compose:"cpuset" bundle:""`
|
||||
CPUShares int64 `compose:"cpu_shares" bundle:""`
|
||||
CPUQuota int64 `compose:"cpu_quota" bundle:""`
|
||||
CapAdd []string `compose:"cap_add" bundle:""`
|
||||
CapDrop []string `compose:"cap_drop" bundle:""`
|
||||
Expose []string `compose:"expose" bundle:""`
|
||||
Privileged bool `compose:"privileged" bundle:""`
|
||||
Restart string `compose:"restart" bundle:""`
|
||||
User string `compose:"user" bundle:"User"`
|
||||
VolumesFrom []string `compose:"volumes_from" bundle:""`
|
||||
ServiceType string `compose:"kompose.service.type" bundle:""`
|
||||
StopGracePeriod string `compose:"stop_grace_period" bundle:""`
|
||||
Build string `compose:"build" bundle:""`
|
||||
BuildArgs map[string]*string `compose:"build-args" bundle:""`
|
||||
ExposeService string `compose:"kompose.service.expose" bundle:""`
|
||||
Stdin bool `compose:"stdin_open" bundle:""`
|
||||
Tty bool `compose:"tty" bundle:""`
|
||||
MemLimit yaml.MemStringorInt `compose:"mem_limit" bundle:""`
|
||||
TmpFs []string `compose:"tmpfs" bundle:""`
|
||||
Dockerfile string `compose:"dockerfile" bundle:""`
|
||||
}
|
||||
|
||||
// EnvVar holds the environment variable struct of a container
|
||||
|
||||
@ -377,6 +377,7 @@ func (c *Compose) LoadFile(files []string) (kobject.KomposeObject, error) {
|
||||
serviceConfig.Tty = composeServiceConfig.Tty
|
||||
serviceConfig.MemLimit = composeServiceConfig.MemLimit
|
||||
serviceConfig.TmpFs = composeServiceConfig.Tmpfs
|
||||
serviceConfig.StopGracePeriod = composeServiceConfig.StopGracePeriod
|
||||
komposeObject.ServiceConfigs[normalizeServiceNames(name)] = serviceConfig
|
||||
if normalizeServiceNames(name) != name {
|
||||
log.Infof("Service name in docker-compose has been changed from %q to %q", name, normalizeServiceNames(name))
|
||||
|
||||
@ -27,6 +27,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"text/template"
|
||||
"time"
|
||||
|
||||
log "github.com/Sirupsen/logrus"
|
||||
"github.com/ghodss/yaml"
|
||||
@ -38,10 +39,11 @@ import (
|
||||
"k8s.io/kubernetes/pkg/apis/extensions"
|
||||
"k8s.io/kubernetes/pkg/runtime"
|
||||
|
||||
"sort"
|
||||
|
||||
deployapi "github.com/openshift/origin/pkg/deploy/api"
|
||||
"github.com/pkg/errors"
|
||||
"k8s.io/kubernetes/pkg/api/resource"
|
||||
"sort"
|
||||
)
|
||||
|
||||
/**
|
||||
@ -382,6 +384,13 @@ func (k *Kubernetes) UpdateKubernetesObjects(name string, service kobject.Servic
|
||||
template.Spec.Containers[0].TTY = service.Tty
|
||||
template.Spec.Volumes = volumes
|
||||
|
||||
if service.StopGracePeriod != "" {
|
||||
template.Spec.TerminationGracePeriodSeconds, err = DurationStrToSecondsInt(service.StopGracePeriod)
|
||||
if err != nil {
|
||||
log.Warningf("Failed to parse duration \"%v\" for service \"%v\"", service.StopGracePeriod, name)
|
||||
}
|
||||
}
|
||||
|
||||
// Configure the resource limits
|
||||
if service.MemLimit != 0 {
|
||||
memoryResourceList := api.ResourceList{
|
||||
@ -553,3 +562,16 @@ func SortedKeys(komposeObject kobject.KomposeObject) []string {
|
||||
sort.Strings(sortedKeys)
|
||||
return sortedKeys
|
||||
}
|
||||
|
||||
//converts duration string to *int64 in seconds
|
||||
func DurationStrToSecondsInt(s string) (*int64, error) {
|
||||
if s == "" {
|
||||
return nil, nil
|
||||
}
|
||||
duration, err := time.ParseDuration(s)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
r := (int64)(duration.Seconds())
|
||||
return &r, nil
|
||||
}
|
||||
|
||||
@ -26,10 +26,11 @@ import (
|
||||
"github.com/kubernetes-incubator/kompose/pkg/kobject"
|
||||
"github.com/kubernetes-incubator/kompose/pkg/testutils"
|
||||
|
||||
"reflect"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/apis/extensions"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
/*
|
||||
@ -296,3 +297,30 @@ func TestSortedKeys(t *testing.T) {
|
||||
t.Logf("Test Fail output should be %s", c)
|
||||
}
|
||||
}
|
||||
|
||||
//test conversion from duration string to seconds *int64
|
||||
func TestDurationStrToSecondsInt(t *testing.T) {
|
||||
testCases := map[string]struct {
|
||||
in string
|
||||
out *int64
|
||||
}{
|
||||
"5s": {in: "5s", out: &[]int64{5}[0]},
|
||||
"1m30s": {in: "1m30s", out: &[]int64{90}[0]},
|
||||
"empty": {in: "", out: nil},
|
||||
"onlynumber": {in: "2", out: nil},
|
||||
"illegal": {in: "abc", out: nil},
|
||||
}
|
||||
|
||||
for name, test := range testCases {
|
||||
result, _ := DurationStrToSecondsInt(test.in)
|
||||
if test.out == nil && result != nil {
|
||||
t.Errorf("Case '%v' for TestDurationStrToSecondsInt fail, Expected 'nil' , got '%v'", name, *result)
|
||||
}
|
||||
if test.out != nil && result == nil {
|
||||
t.Errorf("Case '%v' for TestDurationStrToSecondsInt fail, Expected '%v' , got 'nil'", name, *test.out)
|
||||
}
|
||||
if test.out != nil && result != nil && *test.out != *result {
|
||||
t.Errorf("Case '%v' for TestDurationStrToSecondsInt fail, Expected '%v' , got '%v'", name, *test.out, *result)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user