Skip to content

Commit

Permalink
Read kubelet version from file when possible
Browse files Browse the repository at this point in the history
  • Loading branch information
cartermckinnon committed Oct 16, 2024
1 parent 07da109 commit 450d096
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
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 450d096

Please sign in to comment.