Skip to content

Commit

Permalink
Merge pull request #5370 from twz123/overridable-cgroup-settings
Browse files Browse the repository at this point in the history
Move hard-coded cgroup settings into worker profiles
  • Loading branch information
twz123 authored Jan 7, 2025
2 parents 60b726f + d8d10b8 commit 99c7e78
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
5 changes: 4 additions & 1 deletion pkg/component/controller/workerconfig/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -504,11 +504,12 @@ func (r *Reconciler) buildConfigMaps(snapshot *snapshot) ([]*corev1.ConfigMap, e
workerProfiles := make(map[string]*workerconfig.Profile)

workerProfile := r.buildProfile(snapshot)
workerProfile.KubeletConfiguration.CgroupsPerQOS = ptr.To(true)
workerProfiles["default"] = workerProfile

workerProfile = r.buildProfile(snapshot)
workerProfile.KubeletConfiguration.CgroupsPerQOS = ptr.To(false)
workerProfile.KubeletConfiguration.KubeReservedCgroup = ""
workerProfile.KubeletConfiguration.KubeletCgroups = ""
workerProfiles["default-windows"] = workerProfile

for _, profile := range snapshot.profiles {
Expand Down Expand Up @@ -597,6 +598,8 @@ func (r *Reconciler) buildProfile(snapshot *snapshot) *workerconfig.Profile {
},
ClusterDNS: []string{r.clusterDNSIP.String()},
ClusterDomain: r.clusterDomain,
KubeReservedCgroup: "system.slice",
KubeletCgroups: "/system.slice/containerd.service",
TLSMinVersion: "VersionTLS12",
TLSCipherSuites: cipherSuites,
FailSwapOn: ptr.To(false),
Expand Down
15 changes: 14 additions & 1 deletion pkg/component/controller/workerconfig/reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,19 +369,23 @@ func TestReconciler_ResourceGeneration(t *testing.T) {
}, {
Name: "profile_YYY",
Config: &runtime.RawExtension{Raw: []byte(`{"authentication": {"webhook": {"cacheTTL": "15s"}}}`)},
}, {
Name: "profile_ZZZ",
Config: &runtime.RawExtension{Raw: []byte(`{"cgroupsPerQOS": false, "kubeletCgroups": "", "kubeReservedCgroup": ""}`)},
}},
},
}))

expectedConfigMaps := map[string]func(expected *kubeletConfig){
"worker-config-default-1.31": func(expected *kubeletConfig) {
expected.CgroupsPerQOS = ptr.To(true)
expected.FeatureGates = map[string]bool{"kubelet-feature": true}
},

"worker-config-default-windows-1.31": func(expected *kubeletConfig) {
expected.CgroupsPerQOS = ptr.To(false)
expected.FeatureGates = map[string]bool{"kubelet-feature": true}
expected.KubeletCgroups = ""
expected.KubeReservedCgroup = ""
},

"worker-config-profile_XXX-1.31": func(expected *kubeletConfig) {
Expand All @@ -393,6 +397,13 @@ func TestReconciler_ResourceGeneration(t *testing.T) {
expected.Authentication.Webhook.CacheTTL = metav1.Duration{Duration: 15 * time.Second}
expected.FeatureGates = map[string]bool{"kubelet-feature": true}
},

"worker-config-profile_ZZZ-1.31": func(expected *kubeletConfig) {
expected.CgroupsPerQOS = ptr.To(false)
expected.FeatureGates = map[string]bool{"kubelet-feature": true}
expected.KubeletCgroups = ""
expected.KubeReservedCgroup = ""
},
}

appliedResources := applied()
Expand Down Expand Up @@ -751,6 +762,8 @@ func makeKubeletConfig(t *testing.T, mods ...func(*kubeletConfig)) string {
ClusterDomain: "test.local",
EventRecordQPS: ptr.To(int32(0)),
FailSwapOn: ptr.To(false),
KubeletCgroups: "/system.slice/containerd.service",
KubeReservedCgroup: "system.slice",
RotateCertificates: true,
ServerTLSBootstrap: true,
TLSMinVersion: "VersionTLS12",
Expand Down
8 changes: 0 additions & 8 deletions pkg/component/worker/kubelet.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import (
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/validation"
kubeletv1beta1 "k8s.io/kubelet/config/v1beta1"
"k8s.io/utils/ptr"

"github.com/sirupsen/logrus"
"sigs.k8s.io/yaml"
Expand Down Expand Up @@ -241,13 +240,6 @@ func (k *Kubelet) writeKubeletConfig() error {
config.RegisterWithTaints = taints
}

// cgroup related things (Linux only)
if runtime.GOOS == "linux" {
config.KubeReservedCgroup = "system.slice"
config.KubeletCgroups = "/system.slice/containerd.service"
config.CgroupsPerQOS = ptr.To(true)
}

configBytes, err := yaml.Marshal(config)
if err != nil {
return fmt.Errorf("can't marshal kubelet config: %w", err)
Expand Down

0 comments on commit 99c7e78

Please sign in to comment.