Skip to content

Commit eb805d2

Browse files
committed
kubelet: Wait less for control-plane pods to restart
1 parent 3a9e01b commit eb805d2

File tree

10 files changed

+43
-0
lines changed

10 files changed

+43
-0
lines changed

nodeup/pkg/model/kubelet.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@ import (
2626
"path"
2727
"path/filepath"
2828
"strings"
29+
"time"
2930

3031
awsconfig "github.com/aws/aws-sdk-go-v2/config"
3132
"github.com/aws/aws-sdk-go-v2/feature/ec2/imds"
3233
ec2types "github.com/aws/aws-sdk-go-v2/service/ec2/types"
34+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3335
"k8s.io/apimachinery/pkg/runtime"
3436
"k8s.io/apimachinery/pkg/runtime/serializer"
3537
"k8s.io/klog/v2"
@@ -242,6 +244,9 @@ func buildKubeletComponentConfig(kubeletConfig *kops.KubeletConfigSpec, provider
242244
if providerID != "" {
243245
componentConfig.ProviderID = providerID
244246
}
247+
componentConfig.CrashLoopBackOff = kubelet.CrashLoopBackOffConfig{
248+
MaxContainerRestartPeriod: kubeletConfig.CrashLoopBackOffMaxContainerRestartPeriod,
249+
}
245250
if kubeletConfig.ShutdownGracePeriod != nil {
246251
componentConfig.ShutdownGracePeriod = *kubeletConfig.ShutdownGracePeriod
247252
}
@@ -648,6 +653,11 @@ func (b *KubeletBuilder) buildKubeletConfigSpec(ctx context.Context) (*kops.Kube
648653

649654
c.ClientCAFile = filepath.Join(b.PathSrvKubernetes(), "ca.crt")
650655

656+
// Wait less for pods to restart, especially during the bootstrap sequence
657+
if b.IsMaster && c.CrashLoopBackOffMaxContainerRestartPeriod == nil {
658+
c.CrashLoopBackOffMaxContainerRestartPeriod = &metav1.Duration{Duration: time.Minute}
659+
}
660+
651661
// Respect any MaxPods value the user sets explicitly.
652662
if (b.NodeupConfig.Networking.AmazonVPC != nil || (b.NodeupConfig.Networking.Cilium != nil && b.NodeupConfig.Networking.Cilium.IPAM == kops.CiliumIpamEni)) && c.MaxPods == nil {
653663
config, err := awsconfig.LoadDefaultConfig(ctx)

pkg/apis/kops/componentconfig.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,8 @@ type KubeletConfigSpec struct {
243243
// MemorySwapBehavior defines how swap is used by container workloads.
244244
// Supported values: LimitedSwap, "UnlimitedSwap.
245245
MemorySwapBehavior string `json:"memorySwapBehavior,omitempty"`
246+
// CrashLoopBackOffMaxContainerRestartPeriod is the maximum duration the backoff delay can accrue to for container restarts, minimum 1 second, maximum 300 seconds. If not set, defaults to the internal crashloopbackoff maximum (300s).
247+
CrashLoopBackOffMaxContainerRestartPeriod *metav1.Duration `json:"crashLoopBackOffMaxContainerRestartPeriod,omitempty"`
246248
}
247249

248250
// KubeProxyConfig defines the configuration for a proxy

pkg/apis/kops/v1alpha2/componentconfig.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,8 @@ type KubeletConfigSpec struct {
243243
// MemorySwapBehavior defines how swap is used by container workloads.
244244
// Supported values: LimitedSwap, "UnlimitedSwap.
245245
MemorySwapBehavior string `json:"memorySwapBehavior,omitempty"`
246+
// CrashLoopBackOffMaxContainerRestartPeriod is the maximum duration the backoff delay can accrue to for container restarts, minimum 1 second, maximum 300 seconds. If not set, defaults to the internal crashloopbackoff maximum (300s).
247+
CrashLoopBackOffMaxContainerRestartPeriod *metav1.Duration `json:"crashLoopBackOffMaxContainerRestartPeriod,omitempty"`
246248
}
247249

248250
// KubeProxyConfig defines the configuration for a proxy

pkg/apis/kops/v1alpha2/zz_generated.conversion.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/apis/kops/v1alpha2/zz_generated.deepcopy.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/apis/kops/v1alpha3/componentconfig.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,8 @@ type KubeletConfigSpec struct {
241241
// MemorySwapBehavior defines how swap is used by container workloads.
242242
// Supported values: LimitedSwap, "UnlimitedSwap.
243243
MemorySwapBehavior string `json:"memorySwapBehavior,omitempty"`
244+
// CrashLoopBackOffMaxContainerRestartPeriod is the maximum duration the backoff delay can accrue to for container restarts, minimum 1 second, maximum 300 seconds. If not set, defaults to the internal crashloopbackoff maximum (300s).
245+
CrashLoopBackOffMaxContainerRestartPeriod *metav1.Duration `json:"crashLoopBackOffMaxContainerRestartPeriod,omitempty"`
244246
}
245247

246248
// KubeProxyConfig defines the configuration for a proxy

pkg/apis/kops/v1alpha3/zz_generated.conversion.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/apis/kops/v1alpha3/zz_generated.deepcopy.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/apis/kops/validation/validation.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"path/filepath"
2626
"regexp"
2727
"strings"
28+
"time"
2829

2930
"github.com/aws/aws-sdk-go-v2/aws/arn"
3031
"github.com/blang/semver/v4"
@@ -966,6 +967,13 @@ func validateKubelet(k *kops.KubeletConfigSpec, c *kops.Cluster, kubeletPath *fi
966967
}
967968
}
968969

970+
containerRestartPeriod := k.CrashLoopBackOffMaxContainerRestartPeriod
971+
if containerRestartPeriod != nil {
972+
if containerRestartPeriod.Duration < time.Second || containerRestartPeriod.Duration > 300*time.Second {
973+
allErrs = append(allErrs, field.Invalid(kubeletPath.Child("crashLoopBackOffMaxContainerRestartPeriod"), containerRestartPeriod.String(), "crashLoopBackOffMaxContainerRestartPeriod must be a value between 1s and 300s"))
974+
}
975+
}
976+
969977
if k.MemorySwapBehavior != "" {
970978
allErrs = append(allErrs, IsValidValue(kubeletPath.Child("memorySwapBehavior"), &k.MemorySwapBehavior, []string{"LimitedSwap", "UnlimitedSwap"})...)
971979
}

pkg/apis/kops/zz_generated.deepcopy.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)