Skip to content

Commit

Permalink
Move hard-coded cgroup settings into worker profiles
Browse files Browse the repository at this point in the history
This makes them overridable. Also, don't set cgroupsRoot to true, which
is the default anyway.

Signed-off-by: Tom Wieczorek <twieczorek@mirantis.com>
  • Loading branch information
twz123 committed Dec 19, 2024
1 parent 5274ba1 commit 2d14e51
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 @@ -243,13 +242,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 2d14e51

Please sign in to comment.