diff --git a/nodeadm/cmd/nodeadm/init/init.go b/nodeadm/cmd/nodeadm/init/init.go index febb1159cfc1..6cd1f408a073 100644 --- a/nodeadm/cmd/nodeadm/init/init.go +++ b/nodeadm/cmd/nodeadm/init/init.go @@ -89,7 +89,7 @@ func (c *initCmd) Run(log *zap.Logger, opts *cli.GlobalOptions) error { daemons := []daemon.Daemon{ containerd.NewContainerdDaemon(daemonManager), - kubelet.NewKubeletDaemon(daemonManager), + kubelet.NewKubeletDaemon(log, daemonManager), } if !slices.Contains(c.skipPhases, configPhase) { diff --git a/nodeadm/internal/kubelet/daemon.go b/nodeadm/internal/kubelet/daemon.go index f8fd77039485..e2d625201344 100644 --- a/nodeadm/internal/kubelet/daemon.go +++ b/nodeadm/internal/kubelet/daemon.go @@ -3,6 +3,7 @@ package kubelet import ( "github.com/awslabs/amazon-eks-ami/nodeadm/internal/api" "github.com/awslabs/amazon-eks-ami/nodeadm/internal/daemon" + "go.uber.org/zap" ) const KubeletDaemonName = "kubelet" @@ -17,7 +18,11 @@ type kubelet struct { flags map[string]string } -func NewKubeletDaemon(daemonManager daemon.DaemonManager) daemon.Daemon { +func NewKubeletDaemon(log *zap.Logger, daemonManager daemon.DaemonManager) daemon.Daemon { + version, err := GetKubeletVersion() + if err != nil { + log.Info("kubelet", zap.String("version", version)) + } return &kubelet{ daemonManager: daemonManager, environment: make(map[string]string), diff --git a/nodeadm/internal/kubelet/version.go b/nodeadm/internal/kubelet/version.go index 7ee011637a8d..a916a0ec9754 100644 --- a/nodeadm/internal/kubelet/version.go +++ b/nodeadm/internal/kubelet/version.go @@ -5,16 +5,23 @@ import ( "regexp" ) +var ( + kubeletVersion string +) + func GetKubeletVersion() (string, error) { - rawVersion, err := GetKubeletVersionRaw() + if kubeletVersion != "" { + return kubeletVersion, nil + } + rawVersion, err := getKubeletVersionRaw() if err != nil { return "", err } - version := parseSemVer(*rawVersion) - return version, nil + kubeletVersion = parseSemVer(*rawVersion) + return kubeletVersion, nil } -func GetKubeletVersionRaw() (*string, error) { +func getKubeletVersionRaw() (*string, error) { output, err := exec.Command("kubelet", "--version").Output() if err != nil { return nil, err