package main import ( "fmt" "os" "path/filepath" "wdd.io/agent-common/utils" agent_deploy "wdd.io/agent-deploy" "wdd.io/agent-operator/image" ) func CmiiEnvDeploy() { // 完整部署 shouldDoCompleteDeploy := true // 部署的环境 cmiiNamespace := dev // 输出特定版本的Tag 或者 从DEMO环境拉取 DeploySpecificTag := "5.5.0" var backendMap map[string]string var frontendMap map[string]string var srsMap map[string]string if DeploySpecificTag == "" { // 从DEMO环境拉取 backendMap, frontendMap, srsMap = BackupAllCmiiDeploymentToMap(demo) } else { // 输出特定版本的Tag backendMap, frontendMap, srsMap = image.GenerateCmiiTagVersionImageMap(DeploySpecificTag) } utils.BeautifulPrintWithTitle(backendMap, "backendMap") utils.BeautifulPrintWithTitle(frontendMap, "frontendMap") utils.BeautifulPrintWithTitle(srsMap, "srsMap") // generate and get all old stuff applyYamlFolder := agent_deploy.CmiiEnvironmentDeploy(shouldDoCompleteDeploy, cmiiNamespace, backendMap, frontendMap) fmt.Println(applyYamlFolder) // test //GetNodeWideByKubectl(cmiiNamespace) // clear old apply file //clearOldApplyStuff(applyYamlFolder+"old/", cmiiNamespace) // apply new app //applyNewAppStuff(applyYamlFolder, cmiiNamespace) } func applyNewAppStuff(applyYamlFolder string, cmiiEnv string) bool { files, err := os.ReadDir(applyYamlFolder) if err != nil { log.ErrorF("failed to read directory: %v", err) return false } for _, file := range files { if filepath.Ext(file.Name()) == ".yaml" || filepath.Ext(file.Name()) == ".yml" { filePath := filepath.Join(applyYamlFolder, file.Name()) ApplyByKubectl(filePath, cmiiEnv) } } return true } func clearOldApplyStuff(oldApplyYamlFolder string, cmiiEnv string) bool { files, err := os.ReadDir(oldApplyYamlFolder) if err != nil { log.ErrorF("failed to read directory: %v", err) return false } // rearrange rearrangeCmiiDeploySequence(files) for _, file := range files { if filepath.Ext(file.Name()) == ".yaml" || filepath.Ext(file.Name()) == ".yml" { filePath := filepath.Join(oldApplyYamlFolder, file.Name()) DeleteByKubectl(filePath, cmiiEnv) } } return true } // rearrangeCmiiDeploySequence 重新排序CmiiDeploy顺序 func rearrangeCmiiDeploySequence(files []os.DirEntry) { k8s - backend.yaml k8s - configmap.yaml k8s - emqx.yaml k8s - frontend.yaml k8s - ingress.yaml k8s - mongo.yaml k8s - mysql.yaml k8s - nacos.yaml k8s - pvc.yaml k8s - rabbitmq.yaml k8s - redis.yaml for _, file := range files { if filepath.Ext(file.Name()) == ".yaml" || filepath.Ext(file.Name()) == ".yml" { filePath := filepath.Join(oldApplyYamlFolder, file.Name()) DeleteByKubectl(filePath, cmiiEnv) } } }