Skip to content

Commit 123d1ea

Browse files
committed
kubelet: Set --config to avoid using legacy defaults
Fixes #12310 It also help avoid similar issues as #12164 in the future. I.e. we do not need to explicity override defaults by using cli flags. Signed-off-by: Boleyn Su <[email protected]>
1 parent 925726c commit 123d1ea

File tree

5 files changed

+7
-9
lines changed

5 files changed

+7
-9
lines changed

pkg/agent/config/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,7 @@ func get(ctx context.Context, envInfo *cmds.Agent, proxy proxy.Proxy) (*config.N
601601
return nil, err
602602
}
603603

604+
kubeletConfig := filepath.Join(envInfo.DataDir, "agent", "etc", "kubelet.conf")
604605
// Ensure kubelet config dir exists
605606
kubeletConfigDir := filepath.Join(envInfo.DataDir, "agent", "etc", "kubelet.conf.d")
606607
if err := os.MkdirAll(kubeletConfigDir, 0700); err != nil {
@@ -635,6 +636,7 @@ func get(ctx context.Context, envInfo *cmds.Agent, proxy proxy.Proxy) (*config.N
635636
nodeConfig.AgentConfig.ClusterDomain = controlConfig.ClusterDomain
636637
nodeConfig.AgentConfig.ResolvConf = locateOrGenerateResolvConf(envInfo)
637638
nodeConfig.AgentConfig.ClientCA = clientCAFile
639+
nodeConfig.AgentConfig.KubeletConfig = kubeletConfig
638640
nodeConfig.AgentConfig.KubeletConfigDir = kubeletConfigDir
639641
nodeConfig.AgentConfig.KubeConfigKubelet = kubeconfigKubelet
640642
nodeConfig.AgentConfig.KubeConfigKubeProxy = kubeconfigKubeproxy

pkg/daemons/agent/agent.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import (
1616
daemonconfig "github.com/k3s-io/k3s/pkg/daemons/config"
1717
"github.com/k3s-io/k3s/pkg/daemons/executor"
1818
"github.com/k3s-io/k3s/pkg/util"
19-
"github.com/k3s-io/k3s/pkg/version"
2019
"github.com/otiai10/copy"
2120
pkgerrors "github.com/pkg/errors"
2221
"github.com/sirupsen/logrus"
@@ -72,7 +71,7 @@ func startKubelet(ctx context.Context, cfg *daemonconfig.Agent) error {
7271
return pkgerrors.WithMessage(err, "prepare user configuration drop-ins")
7372
}
7473

75-
if err := writeKubeletConfig(cfg.KubeletConfigDir, defaultConfig); err != nil {
74+
if err := writeKubeletConfig(cfg.KubeletConfig, defaultConfig); err != nil {
7675
return pkgerrors.WithMessage(err, "generate default kubelet configuration drop-in")
7776
}
7877

@@ -158,7 +157,7 @@ func writeKubeletConfig(path string, config *kubeletconfig.KubeletConfiguration)
158157
if err != nil {
159158
return err
160159
}
161-
return os.WriteFile(filepath.Join(path, "00-"+version.Program+"-defaults.conf"), b, 0600)
160+
return os.WriteFile(path, b, 0600)
162161
}
163162

164163
func defaultKubeletConfig(cfg *daemonconfig.Agent) (*kubeletconfig.KubeletConfiguration, error) {

pkg/daemons/agent/agent_linux.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,9 @@ func kubeletArgsAndConfig(cfg *config.Agent) (map[string]string, *kubeletconfig.
7575
return nil, nil, err
7676
}
7777
argsMap := map[string]string{
78+
"config": cfg.KubeletConfig,
7879
"config-dir": cfg.KubeletConfigDir,
7980
"kubeconfig": cfg.KubeConfigKubelet,
80-
// note: KubeletConfiguration will omit this field when marshalling if it is set to 0, so we set it via CLI
81-
// https://github.com/k3s-io/k3s/issues/12164
82-
"read-only-port": "0",
8381
}
8482

8583
if cfg.RootDir != "" {

pkg/daemons/agent/agent_windows.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,9 @@ func kubeletArgsAndConfig(cfg *config.Agent) (map[string]string, *kubeletconfig.
4848
return nil, nil, err
4949
}
5050
argsMap := map[string]string{
51+
"config": cfg.KubeletConfig,
5152
"config-dir": cfg.KubeletConfigDir,
5253
"kubeconfig": cfg.KubeConfigKubelet,
53-
// note: KubeletConfiguration will omit this field when marshalling if it is set to 0, so we set it via CLI
54-
// https://github.com/k3s-io/k3s/issues/12164
55-
"read-only-port": "0",
5654
}
5755
if cfg.RootDir != "" {
5856
argsMap["root-dir"] = cfg.RootDir

pkg/daemons/config/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ type Agent struct {
119119
ClusterDomain string
120120
ResolvConf string
121121
RootDir string
122+
KubeletConfig string
122123
KubeletConfigDir string
123124
KubeConfigKubelet string
124125
KubeConfigKubeProxy string

0 commit comments

Comments
 (0)