From e875c27ab8431fa8f1fc511bc75a687cbcd0030a Mon Sep 17 00:00:00 2001 From: Justin Santa Barbara Date: Wed, 1 Feb 2017 00:25:05 -0500 Subject: [PATCH] Workaround for time.Duration zero value Go 1.6 has the zero value of time.Duration render to a string as `0`, but 1.7 and on renders as `0s`. Force to `0s` for consistency across versions. --- pkg/apis/kops/componentconfig.go | 2 +- pkg/flagbuilder/build_flags.go | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/pkg/apis/kops/componentconfig.go b/pkg/apis/kops/componentconfig.go index 4ddb357564..b7d7a89a9e 100644 --- a/pkg/apis/kops/componentconfig.go +++ b/pkg/apis/kops/componentconfig.go @@ -306,7 +306,7 @@ type KubeletConfigSpec struct { // Comma-delimited list of grace periods for each soft eviction signal. For example, 'memory.available=30s'. EvictionSoftGracePeriod string `json:"evictionSoftGracePeriod,omitempty" flag:"eviction-soft-grace-period"` // Duration for which the kubelet has to wait before transitioning out of an eviction pressure condition. - EvictionPressureTransitionPeriod metav1.Duration `json:"evictionPressureTransitionPeriod,omitempty" flag:"eviction-pressure-transition-period" flag-empty:"0"` + EvictionPressureTransitionPeriod metav1.Duration `json:"evictionPressureTransitionPeriod,omitempty" flag:"eviction-pressure-transition-period" flag-empty:"0s"` // Maximum allowed grace period (in seconds) to use when terminating pods in response to a soft eviction threshold being met. EvictionMaxPodGracePeriod int32 `json:"evictionMaxPodGracePeriod,omitempty" flag:"eviction-max-pod-grace-period" flag-empty:"0"` // Comma-delimited list of minimum reclaims (e.g. imagefs.available=2Gi) that describes the minimum amount of resource the kubelet will reclaim when performing a pod eviction if that resource is under pressure. diff --git a/pkg/flagbuilder/build_flags.go b/pkg/flagbuilder/build_flags.go index 1b02737658..43ec1a3fa7 100644 --- a/pkg/flagbuilder/build_flags.go +++ b/pkg/flagbuilder/build_flags.go @@ -114,6 +114,14 @@ func BuildFlags(options interface{}) (string, error) { case metav1.Duration: vString := v.Duration.String() + + // See https://github.com/kubernetes/kubernetes/issues/40783 + // Go renders a time.Duration to `0` in <= 1.6, and `0s` in >= 1.7 + // We force it to be `0s`, regardless of value + if vString == "0" { + vString = "0s" + } + if vString != flagEmpty { flag = fmt.Sprintf("--%s=%s", flagName, vString) }