diff --git a/nodeup/pkg/model/kubelet.go b/nodeup/pkg/model/kubelet.go index c58105f292..a42d538f92 100644 --- a/nodeup/pkg/model/kubelet.go +++ b/nodeup/pkg/model/kubelet.go @@ -248,6 +248,12 @@ func buildKubeletComponentConfig(kubeletConfig *kops.KubeletConfigSpec, provider if kubeletConfig.ShutdownGracePeriodCriticalPods != nil { componentConfig.ShutdownGracePeriodCriticalPods = *kubeletConfig.ShutdownGracePeriodCriticalPods } + if kubeletConfig.ImageMaximumGCAge != nil { + componentConfig.ImageMaximumGCAge = *kubeletConfig.ImageMaximumGCAge + } + if kubeletConfig.ImageMinimumGCAge != nil { + componentConfig.ImageMinimumGCAge = *kubeletConfig.ImageMinimumGCAge + } componentConfig.MemorySwap.SwapBehavior = kubeletConfig.MemorySwapBehavior s := runtime.NewScheme() diff --git a/nodeup/pkg/model/kubelet_test.go b/nodeup/pkg/model/kubelet_test.go index cf23912e96..4648790ea8 100644 --- a/nodeup/pkg/model/kubelet_test.go +++ b/nodeup/pkg/model/kubelet_test.go @@ -31,6 +31,7 @@ import ( "k8s.io/kops/pkg/apis/nodeup" "k8s.io/kops/pkg/assets" "k8s.io/kops/pkg/client/simple/vfsclientset" + "k8s.io/kops/pkg/flagbuilder" "k8s.io/kops/pkg/pki" "k8s.io/kops/pkg/testutils" "k8s.io/kops/upup/pkg/fi" @@ -399,6 +400,8 @@ func Test_BuildComponentConfigFile(t *testing.T) { componentConfig := kops.KubeletConfigSpec{ ShutdownGracePeriod: &metav1.Duration{Duration: 30 * time.Second}, ShutdownGracePeriodCriticalPods: &metav1.Duration{Duration: 10 * time.Second}, + ImageMaximumGCAge: &metav1.Duration{Duration: 30 * time.Hour}, + ImageMinimumGCAge: &metav1.Duration{Duration: 30 * time.Minute}, } _, err := buildKubeletComponentConfig(&componentConfig, "") @@ -406,3 +409,34 @@ func Test_BuildComponentConfigFile(t *testing.T) { t.Errorf("Failed to build component config file: %v", err) } } + +func Test_Kubelet_BuildFlags(t *testing.T) { + grid := []struct { + config kops.KubeletConfigSpec + expected string + }{ + { + kops.KubeletConfigSpec{ + ImageMaximumGCAge: &metav1.Duration{Duration: 30 * time.Hour}, + }, + "", + }, + { + kops.KubeletConfigSpec{ + ImageMinimumGCAge: &metav1.Duration{Duration: 30 * time.Minute}, + }, + "", + }, + } + + for _, g := range grid { + actual, err := flagbuilder.BuildFlags(&g.config) + if err != nil { + t.Errorf("error building flags for %v: %v", g.config, err) + continue + } + if actual != g.expected { + t.Errorf("flags did not match. actual=%q expected=%q", actual, g.expected) + } + } +} diff --git a/pkg/apis/kops/componentconfig.go b/pkg/apis/kops/componentconfig.go index 9d871004fe..974c4e5948 100644 --- a/pkg/apis/kops/componentconfig.go +++ b/pkg/apis/kops/componentconfig.go @@ -132,11 +132,11 @@ type KubeletConfigSpec struct { // computed (such as IPSEC). NetworkPluginMTU *int32 `json:"networkPluginMTU,omitempty" flag:"network-plugin-mtu"` // imageMinimumGCAge is the minimum age for an unused image before it is garbage collected. Default: "2m" - ImageMinimumGCAge *string `json:"imageMinimumGCAge,omitempty" flag:"image-minimum-gc-age"` + ImageMinimumGCAge *metav1.Duration `json:"imageMinimumGCAge,omitempty"` // imageMaximumGCAge is the maximum age an image can be unused before it is garbage collected. // The default of this field is "0s", which disables this field--meaning images won't be garbage // collected based on being unused for too long. Default: "0s" (disabled) - ImageMaximumGCAge *string `json:"imageMaximumGCAge,omitempty" flag:"image-maximum-gc-age"` + ImageMaximumGCAge *metav1.Duration `json:"imageMaximumGCAge,omitempty"` // ImageGCHighThresholdPercent is the percent of disk usage after which // image garbage collection is always run. ImageGCHighThresholdPercent *int32 `json:"imageGCHighThresholdPercent,omitempty" flag:"image-gc-high-threshold"` diff --git a/pkg/apis/kops/v1alpha2/componentconfig.go b/pkg/apis/kops/v1alpha2/componentconfig.go index 66c5a0eeb1..cd6d87f50a 100644 --- a/pkg/apis/kops/v1alpha2/componentconfig.go +++ b/pkg/apis/kops/v1alpha2/componentconfig.go @@ -132,11 +132,11 @@ type KubeletConfigSpec struct { // computed (such as IPSEC). NetworkPluginMTU *int32 `json:"networkPluginMTU,omitempty" flag:"network-plugin-mtu"` // imageMinimumGCAge is the minimum age for an unused image before it is garbage collected. Default: "2m" - ImageMinimumGCAge *string `json:"imageMinimumGCAge,omitempty" flag:"image-minimum-gc-age"` + ImageMinimumGCAge *metav1.Duration `json:"imageMinimumGCAge,omitempty"` // imageMaximumGCAge is the maximum age an image can be unused before it is garbage collected. // The default of this field is "0s", which disables this field--meaning images won't be garbage // collected based on being unused for too long. Default: "0s" (disabled) - ImageMaximumGCAge *string `json:"imageMaximumGCAge,omitempty" flag:"image-maximum-gc-age"` + ImageMaximumGCAge *metav1.Duration `json:"imageMaximumGCAge,omitempty"` // ImageGCHighThresholdPercent is the percent of disk usage after which // image garbage collection is always run. ImageGCHighThresholdPercent *int32 `json:"imageGCHighThresholdPercent,omitempty" flag:"image-gc-high-threshold"` diff --git a/pkg/apis/kops/v1alpha2/zz_generated.deepcopy.go b/pkg/apis/kops/v1alpha2/zz_generated.deepcopy.go index 63ec34abfa..1631ca80c1 100644 --- a/pkg/apis/kops/v1alpha2/zz_generated.deepcopy.go +++ b/pkg/apis/kops/v1alpha2/zz_generated.deepcopy.go @@ -4197,12 +4197,12 @@ func (in *KubeletConfigSpec) DeepCopyInto(out *KubeletConfigSpec) { } if in.ImageMinimumGCAge != nil { in, out := &in.ImageMinimumGCAge, &out.ImageMinimumGCAge - *out = new(string) + *out = new(v1.Duration) **out = **in } if in.ImageMaximumGCAge != nil { in, out := &in.ImageMaximumGCAge, &out.ImageMaximumGCAge - *out = new(string) + *out = new(v1.Duration) **out = **in } if in.ImageGCHighThresholdPercent != nil { diff --git a/pkg/apis/kops/v1alpha3/componentconfig.go b/pkg/apis/kops/v1alpha3/componentconfig.go index 224e86936b..ea79995cc6 100644 --- a/pkg/apis/kops/v1alpha3/componentconfig.go +++ b/pkg/apis/kops/v1alpha3/componentconfig.go @@ -131,11 +131,11 @@ type KubeletConfigSpec struct { // computed (such as IPSEC). NetworkPluginMTU *int32 `json:"networkPluginMTU,omitempty" flag:"network-plugin-mtu"` // imageMinimumGCAge is the minimum age for an unused image before it is garbage collected. Default: "2m" - ImageMinimumGCAge *string `json:"imageMinimumGCAge,omitempty" flag:"image-minimum-gc-age"` + ImageMinimumGCAge *metav1.Duration `json:"imageMinimumGCAge,omitempty"` // imageMaximumGCAge is the maximum age an image can be unused before it is garbage collected. // The default of this field is "0s", which disables this field--meaning images won't be garbage // collected based on being unused for too long. Default: "0s" (disabled) - ImageMaximumGCAge *string `json:"imageMaximumGCAge,omitempty" flag:"image-maximum-gc-age"` + ImageMaximumGCAge *metav1.Duration `json:"imageMaximumGCAge,omitempty"` // ImageGCHighThresholdPercent is the percent of disk usage after which // image garbage collection is always run. ImageGCHighThresholdPercent *int32 `json:"imageGCHighThresholdPercent,omitempty" flag:"image-gc-high-threshold"` diff --git a/pkg/apis/kops/v1alpha3/zz_generated.deepcopy.go b/pkg/apis/kops/v1alpha3/zz_generated.deepcopy.go index 2f0d276d3c..f1e31f254f 100644 --- a/pkg/apis/kops/v1alpha3/zz_generated.deepcopy.go +++ b/pkg/apis/kops/v1alpha3/zz_generated.deepcopy.go @@ -4176,12 +4176,12 @@ func (in *KubeletConfigSpec) DeepCopyInto(out *KubeletConfigSpec) { } if in.ImageMinimumGCAge != nil { in, out := &in.ImageMinimumGCAge, &out.ImageMinimumGCAge - *out = new(string) + *out = new(v1.Duration) **out = **in } if in.ImageMaximumGCAge != nil { in, out := &in.ImageMaximumGCAge, &out.ImageMaximumGCAge - *out = new(string) + *out = new(v1.Duration) **out = **in } if in.ImageGCHighThresholdPercent != nil { diff --git a/pkg/apis/kops/zz_generated.deepcopy.go b/pkg/apis/kops/zz_generated.deepcopy.go index df8602ca7c..b0add8aee0 100644 --- a/pkg/apis/kops/zz_generated.deepcopy.go +++ b/pkg/apis/kops/zz_generated.deepcopy.go @@ -4279,12 +4279,12 @@ func (in *KubeletConfigSpec) DeepCopyInto(out *KubeletConfigSpec) { } if in.ImageMinimumGCAge != nil { in, out := &in.ImageMinimumGCAge, &out.ImageMinimumGCAge - *out = new(string) + *out = new(v1.Duration) **out = **in } if in.ImageMaximumGCAge != nil { in, out := &in.ImageMaximumGCAge, &out.ImageMaximumGCAge - *out = new(string) + *out = new(v1.Duration) **out = **in } if in.ImageGCHighThresholdPercent != nil {