Skip to content

Commit

Permalink
fixed kubeadm custom binary path (#168)
Browse files Browse the repository at this point in the history
Signed-off-by: Piyush Kumar <[email protected]>
  • Loading branch information
kpiyush17 authored Jan 29, 2025
1 parent 82b0ecc commit 6573190
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
1 change: 1 addition & 0 deletions domain/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ const (
DefaultAPIAdvertiseAddress = "0.0.0.0"

ClusterRootPath = "cluster_root_path"
DefaultRootPath = "/"
)
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func clusterProvider(cluster clusterplugin.Cluster) yip.YipConfig {

clusterCtx := CreateClusterContext(cluster)

cmpResult, err := utils.IsKubeadmVersionGreaterThan131()
cmpResult, err := utils.IsKubeadmVersionGreaterThan131(clusterCtx.RootPath)
if err != nil {
logrus.Fatalf("failed to check if kubeadm version is greater than 131: %v", err)
} else if cmpResult < 0 {
Expand Down
16 changes: 11 additions & 5 deletions utils/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ import (
func GetClusterRootPath(cluster clusterplugin.Cluster) string {
rootpath := cluster.ProviderOptions[domain.ClusterRootPath]
if rootpath == "" {
return "/"
return domain.DefaultRootPath
}
return rootpath
}

func IsKubeadmVersionGreaterThan131() (int, error) {
currentVersion, err := getCurrentKubeadmVersion()
func IsKubeadmVersionGreaterThan131(rootPath string) (int, error) {
currentVersion, err := getCurrentKubeadmVersion(rootPath)
if err != nil {
return 0, err
}
Expand All @@ -33,8 +33,14 @@ func IsKubeadmVersionGreaterThan131() (int, error) {
return v1.Compare("v1.31.0")
}

func getCurrentKubeadmVersion() (string, error) {
cmd := exec.Command("kubeadm", "version", "-o", "short")
func getCurrentKubeadmVersion(rootPath string) (string, error) {
var kubeadmPath string
if rootPath != domain.DefaultRootPath {
kubeadmPath = fmt.Sprintf("%s/usr/bin/kubeadm", rootPath)
} else {
kubeadmPath = "kubeadm"
}
cmd := exec.Command(kubeadmPath, "version", "-o", "short")
output, err := cmd.CombinedOutput()
if err != nil {
return "", fmt.Errorf("error getting current kubeadm version: %v", err)
Expand Down

0 comments on commit 6573190

Please sign in to comment.