Skip to content

Commit 4daf7bf

Browse files
committed
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 <svanka@redhat.com>
1 parent 3d84f65 commit 4daf7bf

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

pkg/controller/kubelet-config/helpers.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"fmt"
88
"reflect"
99
"strconv"
10+
"strings"
1011

1112
ign3types "github.com/coreos/ignition/v2/config/v3_2/types"
1213
"github.com/imdario/mergo"
@@ -33,6 +34,7 @@ const (
3334
managedNodeConfigKeyPrefix = "97"
3435
managedFeaturesKeyPrefix = "98"
3536
managedKubeletConfigKeyPrefix = "99"
37+
protectKernelDefaultsStr = "\"protectKernelDefaults\":false"
3638
)
3739

3840
func createNewKubeletDynamicSystemReservedIgnition(autoSystemReserved *bool, userDefinedSystemReserved map[string]string) *ign3types.File {
@@ -455,6 +457,14 @@ func generateKubeletIgnFiles(kubeletConfig *mcfgv1.KubeletConfig, originalKubeCo
455457
// Remove them here to prevent the specKubeletConfig merge overwriting them.
456458
specKubeletConfig.FeatureGates = nil
457459

460+
// "protectKernelDefaults" is a boolean, optional field with `omitempty` json tag in the upstream kubelet configuration
461+
// This field has been set to `true` by default in OCP recently
462+
// As this field is an optional one with the above tag, it gets omitted when a user inputs it to `false`
463+
// Reference: https://github.com/golang/go/issues/13284
464+
// Adding a workaround to decide if the user has actually set the field to `false`
465+
if strings.Contains(string(kubeletConfig.Spec.KubeletConfig.Raw), protectKernelDefaultsStr) {
466+
originalKubeConfig.ProtectKernelDefaults = false
467+
}
458468
// Merge the Old and New
459469
err = mergo.Merge(originalKubeConfig, specKubeletConfig, mergo.WithOverride)
460470
if err != nil {

0 commit comments

Comments
 (0)