Skip to content

Commit

Permalink
Merge pull request #3789 from sairameshv/cgroupsv2-default
Browse files Browse the repository at this point in the history
OCPNODE-1717: Make cgroupsv2 default in OCP-4.14
  • Loading branch information
openshift-merge-robot authored Jul 26, 2023
2 parents 312e16d + 0f0777b commit ddea245
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 44 deletions.
11 changes: 11 additions & 0 deletions pkg/controller/kubelet-config/kubelet_config_nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ func (ctrl *Controller) syncNodeConfigHandler(key string) error {
if err := ctrl.cleanUpDuplicatedMC(managedNodeConfigKeyPrefix); err != nil {
return err
}
// explicitly setting the cgroupMode to "v2" and also updating the config node's spec if found empty
// This helps in updating the cgroupMode on all the worker nodes if they still have cgroupsv1 (Ex: RHEL8 workers)
if nodeConfig.Spec.CgroupMode == osev1.CgroupModeEmpty {
nodeConfig.Spec.CgroupMode = osev1.CgroupModeV2
ctrl.configClient.ConfigV1().Nodes().Update(context.TODO(), nodeConfig, metav1.UpdateOptions{})
}
// checking if the Node spec is empty and accordingly returning from here.
if reflect.DeepEqual(nodeConfig.Spec, osev1.NodeSpec{}) {
klog.V(2).Info("empty Node resource found")
Expand Down Expand Up @@ -263,6 +269,11 @@ func RunNodeConfigBootstrap(templateDir string, featureGateAccess featuregates.F
if nodeConfig == nil {
return nil, fmt.Errorf("nodes.config.openshift.io resource not found")
}
// explicitly setting the cgroupMode to "v2" and also updating the config node's spec if found empty
// This helps in updating the cgroupMode on all the worker nodes if they still have cgroupsv1 (Ex: RHEL8 workers)
if nodeConfig.Spec.CgroupMode == osev1.CgroupModeEmpty {
nodeConfig.Spec.CgroupMode = osev1.CgroupModeV2
}
// checking if the Node spec is empty and accordingly returning from here.
if reflect.DeepEqual(nodeConfig.Spec, osev1.NodeSpec{}) {
klog.V(2).Info("empty Node resource found")
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/kubelet-config/kubelet_config_nodes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ func TestBootstrapNodeConfigDefault(t *testing.T) {
if err != nil {
t.Errorf("could not run node config bootstrap: %v", err)
}
if len(mcs) != 0 {
t.Errorf("expected no machine configs generated with the default node config, got %v machine configs", len(mcs))
if len(mcs) != 2 {
t.Errorf("expected %v machine configs generated with the default node config, got 0 machine configs", len(mcs))
}
})
}
Expand Down
43 changes: 5 additions & 38 deletions pkg/controller/template/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,11 @@ type RenderConfig struct {
}

const (
filesDir = "files"
unitsDir = "units"
platformBase = "_base"
platformOnPrem = "on-prem"
sno = "sno"
baseMasterKubeletMC = "01-master-kubelet"
baseWorkerKubeletMC = "01-worker-kubelet"
filesDir = "files"
unitsDir = "units"
platformBase = "_base"
platformOnPrem = "on-prem"
sno = "sno"
)

// generateTemplateMachineConfigs returns MachineConfig objects from the templateDir and a config object
Expand Down Expand Up @@ -124,43 +122,12 @@ func GenerateMachineConfigsForRole(config *RenderConfig, role, templateDir strin
if err != nil {
return nil, err
}
// defaulting the CGroups version to "v1"
// (TODO) This code can be removed if not required in future releases
if name == baseMasterKubeletMC || name == baseWorkerKubeletMC {
updateMCwithDefaultCgroupsVersion(nameConfig)
}
cfgs = append(cfgs, nameConfig)
}

return cfgs, nil
}

// updateMCwithDefaultCgroupsVersion updates the MC kArgs with the default CGroups version config
func updateMCwithDefaultCgroupsVersion(mc *mcfgv1.MachineConfig) {
// updating the Machine Config resource with the default cgroupv1 config
var (
kernelArgsv1 = []string{"systemd.unified_cgroup_hierarchy=0", "systemd.legacy_systemd_cgroup_controller=1"}
kernelArgsv2 = []string{"systemd.unified_cgroup_hierarchy=1", "cgroup_no_v1=\"all\"", "psi=1"}
adjustedKernelArgs []string
)
// avoiding the undesired kArgs from the already existing kArgs
for _, arg := range mc.Spec.KernelArguments {
// only append the args we want to keep, omitting the undesired
if !ctrlcommon.InSlice(arg, kernelArgsv2) {
adjustedKernelArgs = append(adjustedKernelArgs, arg)
}
}
// appending the desired kArgs to the existing kArgs
for _, arg := range kernelArgsv1 {
// add the additional that aren't already there
if !ctrlcommon.InSlice(arg, adjustedKernelArgs) {
adjustedKernelArgs = append(adjustedKernelArgs, arg)
}
}
// overwrite the KernelArguments with the adjusted KernelArgs
mc.Spec.KernelArguments = adjustedKernelArgs
}

func platformStringFromControllerConfigSpec(ic *mcfgv1.ControllerConfigSpec) (string, error) {
if ic.Infra == nil {
ic.Infra = &configv1.Infrastructure{
Expand Down
15 changes: 11 additions & 4 deletions test/e2e-bootstrap/bootstrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,11 @@ kind: Node
metadata:
name: cluster`),
},
waitForMasterMCs: []string{"99-master-ssh", "99-master-generated-registries"},
waitForWorkerMCs: []string{"99-worker-ssh", "99-worker-generated-registries"},
// "CgroupMode" field in the nodes.config resource is empty
// Internally it gets updated to "v2" explicitly
// Hence, 97-{master/worker}-generated-kubelet are expected
waitForMasterMCs: []string{"99-master-ssh", "99-master-generated-registries", "97-master-generated-kubelet"},
waitForWorkerMCs: []string{"99-worker-ssh", "99-worker-generated-registries", "97-worker-generated-kubelet"},
},
{
name: "With a node config manifest empty \"cgroupMode\"",
Expand All @@ -134,8 +137,10 @@ metadata:
spec:
workerLatencyProfile: MediumUpdateAverageReaction`),
},

waitForMasterMCs: []string{"99-master-ssh", "99-master-generated-registries"},
// "CgroupMode" field in the nodes.config resource is empty
// Internally it gets updated to "v2" explicitly
// Hence, 97-{master/worker}-generated-kubelet are expected
waitForMasterMCs: []string{"99-master-ssh", "99-master-generated-registries", "97-master-generated-kubelet"},
waitForWorkerMCs: []string{"99-worker-ssh", "99-worker-generated-registries", "97-worker-generated-kubelet"},
},
{
Expand Down Expand Up @@ -262,6 +267,8 @@ spec:
memory: 500Mi
`),
},
// 97-{master/worker}-generated-kubelet are expected to be created as the empty "cgroupMode"
// internally translates to "v2"
waitForMasterMCs: []string{"99-master-ssh", "99-master-generated-registries", "97-master-generated-kubelet"},
waitForWorkerMCs: []string{"99-worker-ssh", "99-worker-generated-registries", "99-worker-generated-kubelet", "97-worker-generated-kubelet"},
},
Expand Down

0 comments on commit ddea245

Please sign in to comment.