forked from LaconicNetwork/kompose
To solve #440
This commit Add support for stop_grace_period which maps to Pod.Spec.TerminationGracePeriodSeconds Updated conversion.md on support for the key
This commit is contained in:
parent
7e785bb31f
commit
c01f6f1763
@ -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 |
|
||||
|
||||
@ -81,6 +81,7 @@ type ServiceConfig struct {
|
||||
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:""`
|
||||
|
||||
@ -373,6 +373,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