diff --git a/main.go b/main.go index 025075a..4b6da35 100644 --- a/main.go +++ b/main.go @@ -41,10 +41,6 @@ func clusterProvider(cluster clusterplugin.Cluster) yip.YipConfig { stages.GetPreKubeadmImportCoreK8sImageStage(clusterRootPath), } - if cluster.ImportLocalImages { - preStage = append(preStage, stages.GetPreKubeadmImportLocalImageStage(cluster)) - } - cluster.ClusterToken = utils.TransformToken(cluster.ClusterToken) finalStages = append(finalStages, preStage...) diff --git a/scripts/import.sh b/scripts/import.sh index 0d4fb39..f4d2ecf 100644 --- a/scripts/import.sh +++ b/scripts/import.sh @@ -3,8 +3,12 @@ CONTENT_PATH=$1 ROOT_PATH=$2 +if [ ! -d "$CONTENT_PATH" ]; then + exit 0 +fi + # find all tar files recursively -for tarfile in $(find $CONTENT_PATH -name "*.tar" -type f) +for tarfile in $(find "$CONTENT_PATH" -name "*.tar" -type f) do # try to import the tar file into containerd up to ten times for i in {1..10} diff --git a/stages/init.go b/stages/init.go index 652f9d4..30c0a85 100644 --- a/stages/init.go +++ b/stages/init.go @@ -68,17 +68,21 @@ func getKubeadmInitStage(cluster clusterplugin.Cluster, clusterCfg kubeadmapiv3. If: fmt.Sprintf("[ ! -f %s ]", filepath.Join(clusterRootPath, "opt/kubeadm.init")), } + if cluster.ImportLocalImages { + initStage.Commands = getImportLocalImageStageCommands(cluster) + } + if utils.IsProxyConfigured(cluster.Env) { proxy := cluster.Env - initStage.Commands = []string{ + initStage.Commands = append(initStage.Commands, fmt.Sprintf("bash %s %s %t %s %s %s", filepath.Join(clusterRootPath, helperScriptPath, "kube-init.sh"), clusterRootPath, true, proxy["HTTP_PROXY"], proxy["HTTPS_PROXY"], utils.GetNoProxyConfig(clusterCfg, cluster.Env)), fmt.Sprintf("touch %s", filepath.Join(clusterRootPath, "opt/kubeadm.init")), - } + ) } else { - initStage.Commands = []string{ + initStage.Commands = append(initStage.Commands, fmt.Sprintf("bash %s %s", filepath.Join(clusterRootPath, helperScriptPath, "kube-init.sh"), clusterRootPath), fmt.Sprintf("touch %s", filepath.Join(clusterRootPath, "opt/kubeadm.init")), - } + ) } return initStage } diff --git a/stages/join.go b/stages/join.go index f84cdee..abf3bf7 100644 --- a/stages/join.go +++ b/stages/join.go @@ -92,17 +92,21 @@ func getKubeadmJoinStage(cluster clusterplugin.Cluster, clusterCfg kubeadmapiv3. If: fmt.Sprintf("[ ! -f %s ]", filepath.Join(clusterRootPath, "opt/kubeadm.join")), } + if cluster.ImportLocalImages { + joinStage.Commands = getImportLocalImageStageCommands(cluster) + } + if utils.IsProxyConfigured(cluster.Env) { proxy := cluster.Env - joinStage.Commands = []string{ + joinStage.Commands = append(joinStage.Commands, fmt.Sprintf("bash %s %s %s %t %s %s %s", filepath.Join(clusterRootPath, helperScriptPath, "kube-join.sh"), cluster.Role, clusterRootPath, true, proxy["HTTP_PROXY"], proxy["HTTPS_PROXY"], utils.GetNoProxyConfig(clusterCfg, cluster.Env)), fmt.Sprintf("touch %s", filepath.Join(clusterRootPath, "opt/kubeadm.join")), - } + ) } else { - joinStage.Commands = []string{ + joinStage.Commands = append(joinStage.Commands, fmt.Sprintf("bash %s %s %s", filepath.Join(clusterRootPath, helperScriptPath, "kube-join.sh"), cluster.Role, clusterRootPath), fmt.Sprintf("touch %s", filepath.Join(clusterRootPath, "opt/kubeadm.join")), - } + ) } return joinStage } diff --git a/stages/pre.go b/stages/pre.go index 2c7898d..72a9c7e 100644 --- a/stages/pre.go +++ b/stages/pre.go @@ -32,20 +32,16 @@ func GetPreKubeadmSwapOffDisableStage() yip.Stage { } } -func GetPreKubeadmImportLocalImageStage(cluster clusterplugin.Cluster) yip.Stage { +func getImportLocalImageStageCommands(cluster clusterplugin.Cluster) []string { clusterRootPath := utils.GetClusterRootPath(cluster) if cluster.LocalImagesPath == "" { cluster.LocalImagesPath = filepath.Join(clusterRootPath, "opt/content/images") } - return yip.Stage{ - Name: "Run Import Local Images", - Commands: []string{ - fmt.Sprintf("chmod +x %s", filepath.Join(clusterRootPath, helperScriptPath, "import.sh")), - fmt.Sprintf("/bin/sh %s %s > /var/log/import.log", filepath.Join(clusterRootPath, helperScriptPath, "import.sh"), cluster.LocalImagesPath), - }, - If: fmt.Sprintf("[ -d %s ]", cluster.LocalImagesPath), + return []string{ + fmt.Sprintf("chmod +x %s", filepath.Join(clusterRootPath, helperScriptPath, "import.sh")), + fmt.Sprintf("/bin/sh %s %s %s > /var/log/import.log", filepath.Join(clusterRootPath, helperScriptPath, "import.sh"), cluster.LocalImagesPath, clusterRootPath), } }