Rename NoSwap to LimitedSwap as workloads may still swap

Also made the options a kubelet type, address API review feedback
This commit is contained in:
Elana Hashman
2021-06-17 16:03:31 -07:00
parent 0deef4610e
commit d3fd1362ca
7 changed files with 29 additions and 15 deletions

View File

@@ -326,7 +326,7 @@ type KubeletConfiguration struct {
FeatureGates map[string]bool
// Tells the Kubelet to fail to start if swap is enabled on the node.
FailSwapOn bool
// Configure swap memory available to container workloads.
// memorySwap configures swap memory available to container workloads.
// +featureGate=NodeSwapEnabled
// +optional
MemorySwap MemorySwapConfiguration
@@ -574,8 +574,10 @@ type MemoryReservation struct {
}
type MemorySwapConfiguration struct {
// Configure swap memory available to container workloads. May be one of
// "", "NoSwap": workloads cannot use swap
// swapBehavior configures swap memory available to container workloads. May be one of
// "", "LimitedSwap": workload combined memory and swap usage cannot exceed pod memory limit
// "UnlimitedSwap": workloads can use unlimited swap, up to the allocatable limit.
// +featureGate=NodeSwapEnabled
// +optional
SwapBehavior string
}

View File

@@ -156,8 +156,8 @@ func ValidateKubeletConfiguration(kc *kubeletconfig.KubeletConfiguration) error
allErrors = append(allErrors, fmt.Errorf("invalid configuration: Specifying ShutdownGracePeriod or ShutdownGracePeriodCriticalPods requires feature gate GracefulNodeShutdown"))
}
if localFeatureGate.Enabled(features.NodeSwapEnabled) {
if kc.MemorySwap.SwapBehavior != "" && kc.MemorySwap.SwapBehavior != "NoSwap" && kc.MemorySwap.SwapBehavior != "UnlimitedSwap" {
allErrors = append(allErrors, fmt.Errorf("invalid configuration: MemorySwap.SwapBehavior %v must be one of: NoSwap, UnlimitedSwap", kc.MemorySwap.SwapBehavior))
if kc.MemorySwap.SwapBehavior != "" && kc.MemorySwap.SwapBehavior != kubetypes.LimitedSwap && kc.MemorySwap.SwapBehavior != kubetypes.UnlimitedSwap {
allErrors = append(allErrors, fmt.Errorf("invalid configuration: MemorySwap.SwapBehavior %v must be one of: LimitedSwap, UnlimitedSwap", kc.MemorySwap.SwapBehavior))
}
}

View File

@@ -24,6 +24,7 @@ import (
utilerrors "k8s.io/apimachinery/pkg/util/errors"
componentbaseconfig "k8s.io/component-base/config"
kubeletconfig "k8s.io/kubernetes/pkg/kubelet/apis/config"
kubetypes "k8s.io/kubernetes/pkg/kubelet/types"
)
func TestValidateKubeletConfiguration(t *testing.T) {
@@ -145,7 +146,7 @@ func TestValidateKubeletConfiguration(t *testing.T) {
TopologyManagerPolicy: kubeletconfig.NoneTopologyManagerPolicy,
ShutdownGracePeriod: metav1.Duration{Duration: 10 * time.Minute},
ShutdownGracePeriodCriticalPods: metav1.Duration{Duration: 0},
MemorySwap: kubeletconfig.MemorySwapConfiguration{SwapBehavior: "UnlimitedSwap"},
MemorySwap: kubeletconfig.MemorySwapConfiguration{SwapBehavior: kubetypes.UnlimitedSwap},
FeatureGates: map[string]bool{
"CustomCPUCFSQuotaPeriod": true,
"GracefulNodeShutdown": true,