Merge pull request #608 from gitlawr/stop_grace_period

Add support for stop_grace_period
This commit is contained in:
Charlie Drage
2017-05-23 14:42:29 -04:00
committed by GitHub
5 changed files with 85 additions and 33 deletions
+23 -1
View File
@@ -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
}
+29 -1
View File
@@ -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)
}
}
}