Skip to content

Commit

Permalink
feat(nodeadm): use cached kubelet version to reduce config time (#1991)
Browse files Browse the repository at this point in the history
  • Loading branch information
cartermckinnon authored Oct 16, 2024
1 parent 140e281 commit 57d74d0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
5 changes: 5 additions & 0 deletions nodeadm/cmd/nodeadm/init/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}

Expand Down
16 changes: 10 additions & 6 deletions nodeadm/internal/kubelet/version.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package kubelet

import (
"errors"
"os"
"os/exec"
"regexp"
)
Expand All @@ -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]+`)
Expand Down
3 changes: 3 additions & 0 deletions templates/al2023/provisioners/install-worker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 #############################################
################################################################################
Expand Down

0 comments on commit 57d74d0

Please sign in to comment.