[agent-operator] - cmii deploy part

This commit is contained in:
zeaslity
2024-06-13 15:06:33 +08:00
parent f1fdfc7777
commit 540d69ede2
19 changed files with 503 additions and 140 deletions

View File

@@ -0,0 +1,82 @@
package main
import (
"os"
"path/filepath"
"wdd.io/agent-common/utils"
"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, frontendMap, backendMap)
// 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
}
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
}