From 6573190e12a3f8f2972621d86557afe4e3edcf3c Mon Sep 17 00:00:00 2001 From: Piyush Kumar Date: Wed, 29 Jan 2025 10:16:19 +0530 Subject: [PATCH] fixed kubeadm custom binary path (#168) Signed-off-by: Piyush Kumar --- domain/constants.go | 1 + main.go | 2 +- utils/misc.go | 16 +++++++++++----- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/domain/constants.go b/domain/constants.go index 355bac5..6d71158 100644 --- a/domain/constants.go +++ b/domain/constants.go @@ -4,4 +4,5 @@ const ( DefaultAPIAdvertiseAddress = "0.0.0.0" ClusterRootPath = "cluster_root_path" + DefaultRootPath = "/" ) diff --git a/main.go b/main.go index ae06e34..a19cc54 100644 --- a/main.go +++ b/main.go @@ -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 { diff --git a/utils/misc.go b/utils/misc.go index 2af02bf..9f69cd7 100644 --- a/utils/misc.go +++ b/utils/misc.go @@ -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 } @@ -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)