From 4daf7bfbf73e2f22f3accf6c1afe06fcb6d46058 Mon Sep 17 00:00:00 2001 From: Sai Ramesh Vanka Date: Wed, 21 Jun 2023 12:31:51 +0530 Subject: [PATCH] Minor fix to support `protectKernelDefaults` field in Kubelet Config `protectKernelDefaults` field is an upstream, optional boolean field in the Kubelet Configuration Recently, this has been defaulted to `true` in the OCP So, even if the user inputs the field to `false`, this gets omitted due to the tag Added a minor workaround to detect if the user has set the field to `false` Signed-off-by: Sai Ramesh Vanka --- pkg/controller/kubelet-config/helpers.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pkg/controller/kubelet-config/helpers.go b/pkg/controller/kubelet-config/helpers.go index 0533a0e48b..b76f4ff868 100644 --- a/pkg/controller/kubelet-config/helpers.go +++ b/pkg/controller/kubelet-config/helpers.go @@ -7,6 +7,7 @@ import ( "fmt" "reflect" "strconv" + "strings" ign3types "github.com/coreos/ignition/v2/config/v3_2/types" "github.com/imdario/mergo" @@ -33,6 +34,7 @@ const ( managedNodeConfigKeyPrefix = "97" managedFeaturesKeyPrefix = "98" managedKubeletConfigKeyPrefix = "99" + protectKernelDefaultsStr = "\"protectKernelDefaults\":false" ) func createNewKubeletDynamicSystemReservedIgnition(autoSystemReserved *bool, userDefinedSystemReserved map[string]string) *ign3types.File { @@ -455,6 +457,14 @@ func generateKubeletIgnFiles(kubeletConfig *mcfgv1.KubeletConfig, originalKubeCo // Remove them here to prevent the specKubeletConfig merge overwriting them. specKubeletConfig.FeatureGates = nil + // "protectKernelDefaults" is a boolean, optional field with `omitempty` json tag in the upstream kubelet configuration + // This field has been set to `true` by default in OCP recently + // As this field is an optional one with the above tag, it gets omitted when a user inputs it to `false` + // Reference: https://github.com/golang/go/issues/13284 + // Adding a workaround to decide if the user has actually set the field to `false` + if strings.Contains(string(kubeletConfig.Spec.KubeletConfig.Raw), protectKernelDefaultsStr) { + originalKubeConfig.ProtectKernelDefaults = false + } // Merge the Old and New err = mergo.Merge(originalKubeConfig, specKubeletConfig, mergo.WithOverride) if err != nil {