Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move hard-coded cgroup settings into worker profiles #5370

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading