From 80afaaead22a476affdc2f0bbdfbdc5ae5e2b08c Mon Sep 17 00:00:00 2001 From: Ciprian Hacman Date: Fri, 14 Jul 2023 07:46:31 +0300 Subject: [PATCH] Add support for using swap memory --- k8s/crds/kops.k8s.io_clusters.yaml | 8 ++++++++ k8s/crds/kops.k8s.io_instancegroups.yaml | 4 ++++ nodeup/pkg/model/kubelet.go | 1 + pkg/apis/kops/componentconfig.go | 3 +++ pkg/apis/kops/v1alpha2/componentconfig.go | 3 +++ pkg/apis/kops/v1alpha2/zz_generated.conversion.go | 2 ++ pkg/apis/kops/v1alpha3/componentconfig.go | 3 +++ pkg/apis/kops/v1alpha3/zz_generated.conversion.go | 2 ++ pkg/apis/kops/validation/validation.go | 4 ++++ 9 files changed, 30 insertions(+) diff --git a/k8s/crds/kops.k8s.io_clusters.yaml b/k8s/crds/kops.k8s.io_clusters.yaml index bb5c767365..966e108986 100644 --- a/k8s/crds/kops.k8s.io_clusters.yaml +++ b/k8s/crds/kops.k8s.io_clusters.yaml @@ -3808,6 +3808,10 @@ spec: Kubelet. format: int32 type: integer + memorySwapBehavior: + description: 'MemorySwapBehavior defines how swap is used by container + workloads. Supported values: LimitedSwap, "UnlimitedSwap.' + type: string networkPluginMTU: description: NetworkPluginMTU is the MTU to be passed to the network plugin, and overrides the default MTU for cases where it cannot @@ -4237,6 +4241,10 @@ spec: Kubelet. format: int32 type: integer + memorySwapBehavior: + description: 'MemorySwapBehavior defines how swap is used by container + workloads. Supported values: LimitedSwap, "UnlimitedSwap.' + type: string networkPluginMTU: description: NetworkPluginMTU is the MTU to be passed to the network plugin, and overrides the default MTU for cases where it cannot diff --git a/k8s/crds/kops.k8s.io_instancegroups.yaml b/k8s/crds/kops.k8s.io_instancegroups.yaml index 05e10e8078..473e80a332 100644 --- a/k8s/crds/kops.k8s.io_instancegroups.yaml +++ b/k8s/crds/kops.k8s.io_instancegroups.yaml @@ -621,6 +621,10 @@ spec: Kubelet. format: int32 type: integer + memorySwapBehavior: + description: 'MemorySwapBehavior defines how swap is used by container + workloads. Supported values: LimitedSwap, "UnlimitedSwap.' + type: string networkPluginMTU: description: NetworkPluginMTU is the MTU to be passed to the network plugin, and overrides the default MTU for cases where it cannot diff --git a/nodeup/pkg/model/kubelet.go b/nodeup/pkg/model/kubelet.go index 9123b6ad3b..0cacb200a5 100644 --- a/nodeup/pkg/model/kubelet.go +++ b/nodeup/pkg/model/kubelet.go @@ -220,6 +220,7 @@ func buildKubeletComponentConfig(kubeletConfig *kops.KubeletConfigSpec) (*nodeta if kubeletConfig.ShutdownGracePeriodCriticalPods != nil { componentConfig.ShutdownGracePeriodCriticalPods = *kubeletConfig.ShutdownGracePeriodCriticalPods } + componentConfig.MemorySwap.SwapBehavior = kubeletConfig.MemorySwapBehavior s := runtime.NewScheme() if err := kubelet.AddToScheme(s); err != nil { diff --git a/pkg/apis/kops/componentconfig.go b/pkg/apis/kops/componentconfig.go index 149142abc5..5ac714739a 100644 --- a/pkg/apis/kops/componentconfig.go +++ b/pkg/apis/kops/componentconfig.go @@ -232,6 +232,9 @@ type KubeletConfigSpec struct { // ShutdownGracePeriodCriticalPods specifies the duration used to terminate critical pods during a node shutdown. // Default: 10s ShutdownGracePeriodCriticalPods *metav1.Duration `json:"shutdownGracePeriodCriticalPods,omitempty"` + // MemorySwapBehavior defines how swap is used by container workloads. + // Supported values: LimitedSwap, "UnlimitedSwap. + MemorySwapBehavior string `json:"memorySwapBehavior,omitempty"` } // KubeProxyConfig defines the configuration for a proxy diff --git a/pkg/apis/kops/v1alpha2/componentconfig.go b/pkg/apis/kops/v1alpha2/componentconfig.go index d819b67d97..c85799490a 100644 --- a/pkg/apis/kops/v1alpha2/componentconfig.go +++ b/pkg/apis/kops/v1alpha2/componentconfig.go @@ -232,6 +232,9 @@ type KubeletConfigSpec struct { // ShutdownGracePeriodCriticalPods specifies the duration used to terminate critical pods during a node shutdown. // Default: 10s ShutdownGracePeriodCriticalPods *metav1.Duration `json:"shutdownGracePeriodCriticalPods,omitempty"` + // MemorySwapBehavior defines how swap is used by container workloads. + // Supported values: LimitedSwap, "UnlimitedSwap. + MemorySwapBehavior string `json:"memorySwapBehavior,omitempty"` } // KubeProxyConfig defines the configuration for a proxy diff --git a/pkg/apis/kops/v1alpha2/zz_generated.conversion.go b/pkg/apis/kops/v1alpha2/zz_generated.conversion.go index d7381ff257..d79230ef40 100644 --- a/pkg/apis/kops/v1alpha2/zz_generated.conversion.go +++ b/pkg/apis/kops/v1alpha2/zz_generated.conversion.go @@ -5387,6 +5387,7 @@ func autoConvert_v1alpha2_KubeletConfigSpec_To_kops_KubeletConfigSpec(in *Kubele out.PodPidsLimit = in.PodPidsLimit out.ShutdownGracePeriod = in.ShutdownGracePeriod out.ShutdownGracePeriodCriticalPods = in.ShutdownGracePeriodCriticalPods + out.MemorySwapBehavior = in.MemorySwapBehavior return nil } @@ -5486,6 +5487,7 @@ func autoConvert_kops_KubeletConfigSpec_To_v1alpha2_KubeletConfigSpec(in *kops.K out.PodPidsLimit = in.PodPidsLimit out.ShutdownGracePeriod = in.ShutdownGracePeriod out.ShutdownGracePeriodCriticalPods = in.ShutdownGracePeriodCriticalPods + out.MemorySwapBehavior = in.MemorySwapBehavior return nil } diff --git a/pkg/apis/kops/v1alpha3/componentconfig.go b/pkg/apis/kops/v1alpha3/componentconfig.go index 099d76e457..8daa41f85d 100644 --- a/pkg/apis/kops/v1alpha3/componentconfig.go +++ b/pkg/apis/kops/v1alpha3/componentconfig.go @@ -230,6 +230,9 @@ type KubeletConfigSpec struct { // ShutdownGracePeriodCriticalPods specifies the duration used to terminate critical pods during a node shutdown. // Default: 10s ShutdownGracePeriodCriticalPods *metav1.Duration `json:"shutdownGracePeriodCriticalPods,omitempty"` + // MemorySwapBehavior defines how swap is used by container workloads. + // Supported values: LimitedSwap, "UnlimitedSwap. + MemorySwapBehavior string `json:"memorySwapBehavior,omitempty"` } // KubeProxyConfig defines the configuration for a proxy diff --git a/pkg/apis/kops/v1alpha3/zz_generated.conversion.go b/pkg/apis/kops/v1alpha3/zz_generated.conversion.go index 610e933cd5..3c1fefa12c 100644 --- a/pkg/apis/kops/v1alpha3/zz_generated.conversion.go +++ b/pkg/apis/kops/v1alpha3/zz_generated.conversion.go @@ -5744,6 +5744,7 @@ func autoConvert_v1alpha3_KubeletConfigSpec_To_kops_KubeletConfigSpec(in *Kubele out.PodPidsLimit = in.PodPidsLimit out.ShutdownGracePeriod = in.ShutdownGracePeriod out.ShutdownGracePeriodCriticalPods = in.ShutdownGracePeriodCriticalPods + out.MemorySwapBehavior = in.MemorySwapBehavior return nil } @@ -5843,6 +5844,7 @@ func autoConvert_kops_KubeletConfigSpec_To_v1alpha3_KubeletConfigSpec(in *kops.K out.PodPidsLimit = in.PodPidsLimit out.ShutdownGracePeriod = in.ShutdownGracePeriod out.ShutdownGracePeriodCriticalPods = in.ShutdownGracePeriodCriticalPods + out.MemorySwapBehavior = in.MemorySwapBehavior return nil } diff --git a/pkg/apis/kops/validation/validation.go b/pkg/apis/kops/validation/validation.go index ef300727ac..bdbc5db4d9 100644 --- a/pkg/apis/kops/validation/validation.go +++ b/pkg/apis/kops/validation/validation.go @@ -918,6 +918,10 @@ func validateKubelet(k *kops.KubeletConfigSpec, c *kops.Cluster, kubeletPath *fi allErrs = append(allErrs, field.Invalid(kubeletPath.Child("shutdownGracePeriodCriticalPods"), k.ShutdownGracePeriodCriticalPods.String(), "shutdownGracePeriodCriticalPods cannot be greater than shutdownGracePeriod")) } } + + if k.MemorySwapBehavior != "" { + allErrs = append(allErrs, IsValidValue(kubeletPath.Child("memorySwapBehavior"), &k.MemorySwapBehavior, []string{"LimitedSwap", "UnlimitedSwap"})...) + } } return allErrs }