Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

moved preload image stage to init and join stage #146

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
Expand Down
6 changes: 5 additions & 1 deletion scripts/import.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
12 changes: 8 additions & 4 deletions stages/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
12 changes: 8 additions & 4 deletions stages/join.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
12 changes: 4 additions & 8 deletions stages/pre.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
}

Expand Down