diff --git a/nodeadm/internal/kubelet/config.go b/nodeadm/internal/kubelet/config.go index 6fce79f28..978a2b24b 100644 --- a/nodeadm/internal/kubelet/config.go +++ b/nodeadm/internal/kubelet/config.go @@ -379,7 +379,7 @@ func (k *kubelet) writeKubeletConfigToDir(cfg *api.NodeConfig) error { k.flags["config-dir"] = dirPath zap.L().Info("Enabling kubelet config drop-in dir..") - k.setEnv("KUBELET_CONFIG_DROPIN_DIR_ALPHA", "on") + k.environment["KUBELET_CONFIG_DROPIN_DIR_ALPHA"] = "on" filePath := path.Join(dirPath, "00-nodeadm.conf") // merge in default type metadata like kind and apiVersion in case the diff --git a/nodeadm/internal/kubelet/environment.go b/nodeadm/internal/kubelet/environment.go index 6abf8a9cd..244b3420b 100644 --- a/nodeadm/internal/kubelet/environment.go +++ b/nodeadm/internal/kubelet/environment.go @@ -30,12 +30,11 @@ func (k *kubelet) writeKubeletEnvironment(cfg *api.NodeConfig) error { // write additional environment variables var kubeletEnvironment []string for eKey, eValue := range k.environment { - kubeletEnvironment = append(kubeletEnvironment, fmt.Sprintf(`%s="%s"`, eKey, eValue)) + kubeletEnvironment = append(kubeletEnvironment, fmt.Sprintf(`%s=%s`, sanitize(eKey), sanitize(eValue))) } return util.WriteFileWithDir(kubeletEnvironmentFilePath, []byte(strings.Join(kubeletEnvironment, "\n")), kubeletConfigPerm) } -// Add values to the environment variables map in a terse manner -func (k *kubelet) setEnv(envName string, envArg string) { - k.environment[envName] = envArg +func sanitize(s string) string { + return strings.ReplaceAll(s, "\n", " ") } diff --git a/nodeadm/test/e2e/cases/kubelet-flags/config.yaml b/nodeadm/test/e2e/cases/kubelet-flags/config.yaml index 8919683a5..bdf6441d8 100644 --- a/nodeadm/test/e2e/cases/kubelet-flags/config.yaml +++ b/nodeadm/test/e2e/cases/kubelet-flags/config.yaml @@ -14,3 +14,6 @@ spec: - --v=5 - --node-labels=foo=bar,foo2=baz - --register-with-taints=foo=bar:NoSchedule + - | + --foo + --bar diff --git a/nodeadm/test/e2e/cases/kubelet-flags/run.sh b/nodeadm/test/e2e/cases/kubelet-flags/run.sh index 4235fc719..5abd450a2 100755 --- a/nodeadm/test/e2e/cases/kubelet-flags/run.sh +++ b/nodeadm/test/e2e/cases/kubelet-flags/run.sh @@ -12,5 +12,5 @@ wait::dbus-ready nodeadm init --skip run --config-source file://config.yaml -assert::file-contains /etc/eks/kubelet/environment '--v=5 --node-labels=foo=bar,foo2=baz --register-with-taints=foo=bar:NoSchedule"$' +assert::file-contains /etc/eks/kubelet/environment '--v=5 --node-labels=foo=bar,foo2=baz --register-with-taints=foo=bar:NoSchedule --foo --bar $' assert::file-contains /etc/eks/kubelet/environment '--hostname-override=i-1234567890abcdef0'