From 07da10961ebff0ee45ec78ba43e70ef90860d65b Mon Sep 17 00:00:00 2001 From: Carter McKinnon Date: Thu, 3 Oct 2024 19:50:29 -0700 Subject: [PATCH 1/2] feat(nodeadm): use cached kubelet version --- nodeadm/cmd/nodeadm/init/init.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/nodeadm/cmd/nodeadm/init/init.go b/nodeadm/cmd/nodeadm/init/init.go index febb1159c..99f054ec1 100644 --- a/nodeadm/cmd/nodeadm/init/init.go +++ b/nodeadm/cmd/nodeadm/init/init.go @@ -2,6 +2,7 @@ package init import ( "context" + "time" "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/config" @@ -46,6 +47,8 @@ func (c *initCmd) Flaggy() *flaggy.Subcommand { } func (c *initCmd) Run(log *zap.Logger, opts *cli.GlobalOptions) error { + start := time.Now() + log.Info("Checking user is root..") root, err := cli.IsRunningAsRoot() if err != nil { @@ -139,6 +142,8 @@ func (c *initCmd) Run(log *zap.Logger, opts *cli.GlobalOptions) error { } } + log.Info("done!", zap.Duration("duration", time.Since(start))) + return nil } From 450d096c20d7a73dd32852b1f7c303f64f7a1428 Mon Sep 17 00:00:00 2001 From: Carter McKinnon Date: Tue, 15 Oct 2024 15:53:24 -0700 Subject: [PATCH 2/2] Read kubelet version from file when possible --- nodeadm/internal/kubelet/version.go | 16 ++++++++++------ templates/al2023/provisioners/install-worker.sh | 3 +++ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/nodeadm/internal/kubelet/version.go b/nodeadm/internal/kubelet/version.go index 7ee011637..e52fd3769 100644 --- a/nodeadm/internal/kubelet/version.go +++ b/nodeadm/internal/kubelet/version.go @@ -1,6 +1,8 @@ package kubelet import ( + "errors" + "os" "os/exec" "regexp" ) @@ -10,17 +12,19 @@ func GetKubeletVersion() (string, error) { if err != nil { return "", err } - version := parseSemVer(*rawVersion) + version := parseSemVer(string(rawVersion)) return version, nil } -func GetKubeletVersionRaw() (*string, error) { - output, err := exec.Command("kubelet", "--version").Output() - if err != nil { +const kubeletVersionFile = "/etc/eks/kubelet-version.txt" + +func GetKubeletVersionRaw() ([]byte, error) { + if _, err := os.Stat(kubeletVersionFile); errors.Is(err, os.ErrNotExist) { + return exec.Command("kubelet", "--version").Output() + } else if err != nil { return nil, err } - rawVersion := string(output) - return &rawVersion, nil + return os.ReadFile(kubeletVersionFile) } var semVerRegex = regexp.MustCompile(`v[0-9]+\.[0-9]+.[0-9]+`) diff --git a/templates/al2023/provisioners/install-worker.sh b/templates/al2023/provisioners/install-worker.sh index 212e3683d..6c6540a86 100644 --- a/templates/al2023/provisioners/install-worker.sh +++ b/templates/al2023/provisioners/install-worker.sh @@ -187,6 +187,9 @@ done sudo rm ./*.sha256 +kubelet --version > "${WORKING_DIR}/kubelet-version.txt" +sudo mv "${WORKING_DIR}/kubelet-version.txt" /etc/eks/kubelet-version.txt + ################################################################################ ### ECR Credential Provider Binary ############################################# ################################################################################