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

write default kubeletConfig to config path in drop-in dir versions #1603

Merged
merged 2 commits into from
Feb 1, 2024
Merged
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
36 changes: 21 additions & 15 deletions nodeadm/internal/kubelet/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (

"k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
logsapi "k8s.io/component-base/logs/api/v1"
k8skubelet "k8s.io/kubelet/config/v1beta1"

"github.com/aws/aws-sdk-go-v2/feature/ec2/imds"
Expand Down Expand Up @@ -66,7 +65,7 @@ type kubeletConfig struct {
HairpinMode string `json:"hairpinMode"`
ProtectKernelDefaults bool `json:"protectKernelDefaults"`
ReadOnlyPort int `json:"readOnlyPort"`
Logging logsapi.LoggingConfiguration `json:"logging"`
Logging loggingConfiguration `json:"logging"`
SerializeImagePulls bool `json:"serializeImagePulls"`
ServerTLSBootstrap bool `json:"serverTLSBootstrap"`
TLSCipherSuites []string `json:"tlsCipherSuites"`
Expand All @@ -79,6 +78,10 @@ type kubeletConfig struct {
RegisterWithTaints []v1.Taint `json:"registerWithTaints,omitempty"`
}

type loggingConfiguration struct {
Verbosity int `json:"verbosity"`
}

// Creates an internal kubelet configuration from the public facing bootstrap
// kubelet configuration with additional sane defaults.
func defaultKubeletSubConfig() kubeletConfig {
Expand Down Expand Up @@ -117,7 +120,7 @@ func defaultKubeletSubConfig() kubeletConfig {
HairpinMode: "hairpin-veth",
ProtectKernelDefaults: true,
ReadOnlyPort: 0,
Logging: logsapi.LoggingConfiguration{
Logging: loggingConfiguration{
Verbosity: 2,
},
SerializeImagePulls: false,
Expand Down Expand Up @@ -304,9 +307,10 @@ func (k *kubelet) writeKubeletConfigToFile(cfg *api.NodeConfig, userKubeletConfi
return util.WriteFileWithDir(configPath, kubeletConfigBytes, kubeletConfigPerm)
}

// WriteKubeletConfigToDir writes the kubelet config to a directory for drop-in
// directory support. This is only supported on kubelet versions >= 1.28.
// see: https://kubernetes.io/docs/tasks/administer-cluster/kubelet-config-file/#kubelet-conf-d
// WriteKubeletConfigToDir writes nodeadm's generated kubelet config to the
// standard config file and writes the user's provided config to a directory for
// drop-in support. This is only supported on kubelet versions >= 1.28. see:
// https://kubernetes.io/docs/tasks/administer-cluster/kubelet-config-file/#kubelet-conf-d
func (k *kubelet) writeKubeletConfigToDir(cfg *api.NodeConfig, userKubeletConfig []byte) error {
kubeletConfig, err := k.GenerateKubeletConfig(cfg)
if err != nil {
Expand All @@ -317,20 +321,22 @@ func (k *kubelet) writeKubeletConfigToDir(cfg *api.NodeConfig, userKubeletConfig
return err
}

dirPath := path.Join(kubeletConfigRoot, kubeletConfigDir)
k.flags["config-dir"] = dirPath

zap.L().Info("Enabling kubelet config drop-in dir..")
k.setEnv("KUBELET_CONFIG_DROPIN_DIR_ALPHA", "on")
configPath := path.Join(kubeletConfigRoot, kubeletConfigFile)
k.flags["config"] = configPath

filePath := path.Join(dirPath, "99-defaults.conf")
zap.L().Info("Writing kubelet config to drop-in file..", zap.String("path", filePath))
if err := util.WriteFileWithDir(filePath, kubeletConfigBytes, kubeletConfigPerm); err != nil {
zap.L().Info("Writing kubelet config to file..", zap.String("path", configPath))
if err := util.WriteFileWithDir(configPath, kubeletConfigBytes, kubeletConfigPerm); err != nil {
return err
}

if userKubeletConfig != nil && len(userKubeletConfig) > 0 {
filePath = path.Join(dirPath, "00-overrides.conf")
dirPath := path.Join(kubeletConfigRoot, kubeletConfigDir)
k.flags["config-dir"] = dirPath

zap.L().Info("Enabling kubelet config drop-in dir..")
k.setEnv("KUBELET_CONFIG_DROPIN_DIR_ALPHA", "on")

filePath := path.Join(dirPath, "00-nodeadm.conf")
zap.L().Info("Writing user kubelet config to drop-in file..", zap.String("path", filePath))
if err := util.WriteFileWithDir(filePath, userKubeletConfig, kubeletConfigPerm); err != nil {
return err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,6 @@
"serverTLSBootstrap": true,
"kubeReservedCgroup": "/runtime",
"logging": {
"flushFrequency": 0,
"options": {
"json": {
"infoBufferSize": "0"
}
},
"verbosity": 2
},
"tlsCipherSuites": [
Expand Down
4 changes: 2 additions & 2 deletions nodeadm/test/e2e/cases/kubelet-config-dir/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ wait::dbus-ready

nodeadm init --skip run --config-source file://config.yaml

assert::json-files-equal /etc/kubernetes/kubelet/config.json.d/99-defaults.conf expected-kubelet-config.json
assert::json-files-equal /etc/kubernetes/kubelet/config.json.d/00-overrides.conf expected-kubelet-config-drop-in.json
assert::json-files-equal /etc/kubernetes/kubelet/config.json expected-kubelet-config.json
assert::json-files-equal /etc/kubernetes/kubelet/config.json.d/00-nodeadm.conf expected-kubelet-config-drop-in.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,7 @@
"protectKernelDefaults": true,
"readOnlyPort": 0,
"logging": {
"flushFrequency": 0,
"verbosity": 2,
"options": {
"json": {
"infoBufferSize": "0"
}
}
"verbosity": 2
},
"serializeImagePulls": false,
"serverTLSBootstrap": true,
Expand Down
Loading