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 | | |
|
| pid | | N | | |
|
||||||
| ports | | Y | [Service.Spec.Ports](https://kubernetes.io/docs/api-reference/v1/definitions/#_v1_containerport) | |
|
| ports | | Y | [Service.Spec.Ports](https://kubernetes.io/docs/api-reference/v1/definitions/#_v1_containerport) | |
|
||||||
| security_opt | | N | | |
|
| 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 | | |
|
| stop_signal | | N | | |
|
||||||
| sysctls | | N | | |
|
| sysctls | | N | | |
|
||||||
| ulimits | | N | | See this [issue](https://github.com/kubernetes/kubernetes/issues/3595) on the k8s repo |
|
| 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
|
// ServiceConfig holds the basic struct of a container
|
||||||
type ServiceConfig struct {
|
type ServiceConfig struct {
|
||||||
// use tags to mark from what element this value comes
|
// use tags to mark from what element this value comes
|
||||||
ContainerName string
|
ContainerName string
|
||||||
Image string `compose:"image" bundle:"Image"`
|
Image string `compose:"image" bundle:"Image"`
|
||||||
Environment []EnvVar `compose:"environment" bundle:"Env"`
|
Environment []EnvVar `compose:"environment" bundle:"Env"`
|
||||||
Port []Ports `compose:"ports" bundle:"Ports"`
|
Port []Ports `compose:"ports" bundle:"Ports"`
|
||||||
Command []string `compose:"command" bundle:"Command"`
|
Command []string `compose:"command" bundle:"Command"`
|
||||||
WorkingDir string `compose:"" bundle:"WorkingDir"`
|
WorkingDir string `compose:"" bundle:"WorkingDir"`
|
||||||
Args []string `compose:"args" bundle:"Args"`
|
Args []string `compose:"args" bundle:"Args"`
|
||||||
Volumes []string `compose:"volumes" bundle:"Volumes"`
|
Volumes []string `compose:"volumes" bundle:"Volumes"`
|
||||||
Network []string `compose:"network" bundle:"Networks"`
|
Network []string `compose:"network" bundle:"Networks"`
|
||||||
Labels map[string]string `compose:"labels" bundle:"Labels"`
|
Labels map[string]string `compose:"labels" bundle:"Labels"`
|
||||||
Annotations map[string]string `compose:"" bundle:""`
|
Annotations map[string]string `compose:"" bundle:""`
|
||||||
CPUSet string `compose:"cpuset" bundle:""`
|
CPUSet string `compose:"cpuset" bundle:""`
|
||||||
CPUShares int64 `compose:"cpu_shares" bundle:""`
|
CPUShares int64 `compose:"cpu_shares" bundle:""`
|
||||||
CPUQuota int64 `compose:"cpu_quota" bundle:""`
|
CPUQuota int64 `compose:"cpu_quota" bundle:""`
|
||||||
CapAdd []string `compose:"cap_add" bundle:""`
|
CapAdd []string `compose:"cap_add" bundle:""`
|
||||||
CapDrop []string `compose:"cap_drop" bundle:""`
|
CapDrop []string `compose:"cap_drop" bundle:""`
|
||||||
Expose []string `compose:"expose" bundle:""`
|
Expose []string `compose:"expose" bundle:""`
|
||||||
Privileged bool `compose:"privileged" bundle:""`
|
Privileged bool `compose:"privileged" bundle:""`
|
||||||
Restart string `compose:"restart" bundle:""`
|
Restart string `compose:"restart" bundle:""`
|
||||||
User string `compose:"user" bundle:"User"`
|
User string `compose:"user" bundle:"User"`
|
||||||
VolumesFrom []string `compose:"volumes_from" bundle:""`
|
VolumesFrom []string `compose:"volumes_from" bundle:""`
|
||||||
ServiceType string `compose:"kompose.service.type" bundle:""`
|
ServiceType string `compose:"kompose.service.type" bundle:""`
|
||||||
Build string `compose:"build" bundle:""`
|
StopGracePeriod string `compose:"stop_grace_period" bundle:""`
|
||||||
BuildArgs map[string]*string `compose:"build-args" bundle:""`
|
Build string `compose:"build" bundle:""`
|
||||||
ExposeService string `compose:"kompose.service.expose" bundle:""`
|
BuildArgs map[string]*string `compose:"build-args" bundle:""`
|
||||||
Stdin bool `compose:"stdin_open" bundle:""`
|
ExposeService string `compose:"kompose.service.expose" bundle:""`
|
||||||
Tty bool `compose:"tty" bundle:""`
|
Stdin bool `compose:"stdin_open" bundle:""`
|
||||||
MemLimit yaml.MemStringorInt `compose:"mem_limit" bundle:""`
|
Tty bool `compose:"tty" bundle:""`
|
||||||
TmpFs []string `compose:"tmpfs" bundle:""`
|
MemLimit yaml.MemStringorInt `compose:"mem_limit" bundle:""`
|
||||||
Dockerfile string `compose:"dockerfile" bundle:""`
|
TmpFs []string `compose:"tmpfs" bundle:""`
|
||||||
|
Dockerfile string `compose:"dockerfile" bundle:""`
|
||||||
}
|
}
|
||||||
|
|
||||||
// EnvVar holds the environment variable struct of a container
|
// EnvVar holds the environment variable struct of a container
|
||||||
|
|||||||
@ -373,6 +373,7 @@ func (c *Compose) LoadFile(files []string) (kobject.KomposeObject, error) {
|
|||||||
serviceConfig.Tty = composeServiceConfig.Tty
|
serviceConfig.Tty = composeServiceConfig.Tty
|
||||||
serviceConfig.MemLimit = composeServiceConfig.MemLimit
|
serviceConfig.MemLimit = composeServiceConfig.MemLimit
|
||||||
serviceConfig.TmpFs = composeServiceConfig.Tmpfs
|
serviceConfig.TmpFs = composeServiceConfig.Tmpfs
|
||||||
|
serviceConfig.StopGracePeriod = composeServiceConfig.StopGracePeriod
|
||||||
komposeObject.ServiceConfigs[normalizeServiceNames(name)] = serviceConfig
|
komposeObject.ServiceConfigs[normalizeServiceNames(name)] = serviceConfig
|
||||||
if normalizeServiceNames(name) != name {
|
if normalizeServiceNames(name) != name {
|
||||||
log.Infof("Service name in docker-compose has been changed from %q to %q", name, normalizeServiceNames(name))
|
log.Infof("Service name in docker-compose has been changed from %q to %q", name, normalizeServiceNames(name))
|
||||||
|
|||||||
@ -27,6 +27,7 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
"time"
|
||||||
|
|
||||||
log "github.com/Sirupsen/logrus"
|
log "github.com/Sirupsen/logrus"
|
||||||
"github.com/ghodss/yaml"
|
"github.com/ghodss/yaml"
|
||||||
@ -38,10 +39,11 @@ import (
|
|||||||
"k8s.io/kubernetes/pkg/apis/extensions"
|
"k8s.io/kubernetes/pkg/apis/extensions"
|
||||||
"k8s.io/kubernetes/pkg/runtime"
|
"k8s.io/kubernetes/pkg/runtime"
|
||||||
|
|
||||||
|
"sort"
|
||||||
|
|
||||||
deployapi "github.com/openshift/origin/pkg/deploy/api"
|
deployapi "github.com/openshift/origin/pkg/deploy/api"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"k8s.io/kubernetes/pkg/api/resource"
|
"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.Containers[0].TTY = service.Tty
|
||||||
template.Spec.Volumes = volumes
|
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
|
// Configure the resource limits
|
||||||
if service.MemLimit != 0 {
|
if service.MemLimit != 0 {
|
||||||
memoryResourceList := api.ResourceList{
|
memoryResourceList := api.ResourceList{
|
||||||
@ -553,3 +562,16 @@ func SortedKeys(komposeObject kobject.KomposeObject) []string {
|
|||||||
sort.Strings(sortedKeys)
|
sort.Strings(sortedKeys)
|
||||||
return 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/kobject"
|
||||||
"github.com/kubernetes-incubator/kompose/pkg/testutils"
|
"github.com/kubernetes-incubator/kompose/pkg/testutils"
|
||||||
|
|
||||||
|
"reflect"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"k8s.io/kubernetes/pkg/api"
|
"k8s.io/kubernetes/pkg/api"
|
||||||
"k8s.io/kubernetes/pkg/apis/extensions"
|
"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)
|
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