diff --git a/pkg/config/cfgvars.go b/pkg/config/cfgvars.go index f8e720209473..3acfc10734f6 100644 --- a/pkg/config/cfgvars.go +++ b/pkg/config/cfgvars.go @@ -107,7 +107,9 @@ func WithCommand(cmd command) CfgVarOption { } if f, err := flags.GetString("kubelet-root-dir"); err == nil && f != "" { - c.KubeletRootDir = f + if f, err := filepath.Abs(f); err == nil { + c.KubeletRootDir = f + } } if f, err := flags.GetString("config"); err == nil && f != "" { diff --git a/pkg/config/cfgvars_test.go b/pkg/config/cfgvars_test.go index f66f63cdaecf..f1e7e5a50e6f 100644 --- a/pkg/config/cfgvars_test.go +++ b/pkg/config/cfgvars_test.go @@ -81,9 +81,12 @@ func TestWithCommand(t *testing.T) { c := &CfgVars{} WithCommand(fakeCmd)(c) + dir, err := filepath.Abs("/path/to/kubelet") + assert.NoError(t, err) + assert.Same(t, in, c.stdin) assert.Equal(t, "/path/to/data", c.DataDir) - assert.Equal(t, "/path/to/kubelet", c.KubeletRootDir) + assert.Equal(t, dir, c.KubeletRootDir) assert.Equal(t, "/path/to/config", c.StartupConfigPath) assert.Equal(t, "/path/to/socket", c.StatusSocketPath) assert.True(t, c.EnableDynamicConfig)