[agent-operator] - cmii deploy part - basic accomplished

This commit is contained in:
zeaslity
2024-06-14 11:41:38 +08:00
parent d86bc43b28
commit f3db4a9ff6
7 changed files with 202 additions and 102 deletions

View File

@@ -1,25 +1,47 @@
package main
import (
"fmt"
"os"
"path/filepath"
"strings"
image2 "wdd.io/agent-common/image"
"wdd.io/agent-common/utils"
agent_deploy "wdd.io/agent-deploy"
"wdd.io/agent-deploy/z_dep"
"wdd.io/agent-operator/image"
)
func CmiiEnvDeploy() {
// 完整部署
shouldDoCompleteDeploy := true
// 部署的环境
cmiiNamespace := dev
// 完整部署
shouldDoCompleteDeploy := true
// 输出特定版本的Tag 或者 从DEMO环境拉取
DeploySpecificTag := "5.5.0"
folderPrefix := "/home/wdd/IdeaProjects/ProjectOctopus/agent-deploy/" + cmiiNamespace + "/"
tenantEnv := cmiiNamespace
if strings.Contains(cmiiNamespace, "-") {
split := strings.Split(cmiiNamespace, "-")
tenantEnv = split[len(split)-1]
}
// common environment
common := &z_dep.CommonEnvironmentConfig{
WebIP: "lab.uavcmlc.com",
WebPort: "",
HarborIP: image2.CmiiHarborPrefix,
HarborPort: "",
Namespace: cmiiNamespace,
TagVersion: DeploySpecificTag,
TenantEnv: tenantEnv,
ApplyFilePrefix: folderPrefix,
}
var backendMap map[string]string
var frontendMap map[string]string
var srsMap map[string]string
@@ -37,35 +59,77 @@ func CmiiEnvDeploy() {
utils.BeautifulPrintWithTitle(srsMap, "srsMap")
// generate and get all old stuff
applyYamlFolder := agent_deploy.CmiiEnvironmentDeploy(shouldDoCompleteDeploy, cmiiNamespace, backendMap, frontendMap)
fmt.Println(applyYamlFolder)
agent_deploy.CmiiEnvironmentDeploy(shouldDoCompleteDeploy, common, backendMap, frontendMap)
// test
//GetNodeWideByKubectl(cmiiNamespace)
GetNodeWideByKubectl(cmiiNamespace)
// clear old apply file
//clearOldApplyStuff(applyYamlFolder+"old/", cmiiNamespace)
// apply new app
//applyNewAppStuff(applyYamlFolder, cmiiNamespace)
//applyNewAppStuff(common, shouldDoCompleteDeploy)
}
func applyNewAppStuff(applyYamlFolder string, cmiiEnv string) bool {
files, err := os.ReadDir(applyYamlFolder)
func applyNewAppStuff(common *z_dep.CommonEnvironmentConfig, shouldDoCompleteDeploy bool) bool {
files, err := os.ReadDir(common.ApplyFilePrefix)
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)
}
if len(files) == 0 {
log.WarnF("no apply file found in %s", common.ApplyFilePrefix)
return false
}
namespace := common.Namespace
if shouldDoCompleteDeploy {
// mysql
ApplyByKubectl(z_dep.MySQLApplyFilePath, namespace)
if !DefaultCmiiOperator.PodStatusCheckTimeout("helm-mysql-0", namespace, 180) {
return false
}
// mongo
ApplyByKubectl(z_dep.MongoApplyFilePath, namespace)
if !DefaultCmiiOperator.PodStatusCheckTimeout("helm-mongo-0", namespace, 180) {
return false
}
// redis
ApplyByKubectl(z_dep.RedisApplyFilePath, namespace)
if !DefaultCmiiOperator.PodStatusCheckTimeout("helm-redis-master-0", namespace, 180) {
return false
}
if !DefaultCmiiOperator.PodStatusCheckTimeout("helm-redis-replicas-0", namespace, 180) {
return false
}
// rabbitmq
ApplyByKubectl(z_dep.RabbitMQApplyFilePath, namespace)
if !DefaultCmiiOperator.PodStatusCheckTimeout("helm-rabbitmq-0", namespace, 180) {
return false
}
// nacos
ApplyByKubectl(z_dep.NacosApplyFilePath, namespace)
if !DefaultCmiiOperator.PodStatusCheckTimeout("helm-nacos-0", namespace, 180) {
return false
}
}
// frontend
ApplyByKubectl(z_dep.IngresApplyFilePath, namespace)
ApplyByKubectl(z_dep.ConfigMapApplyFilePath, namespace)
ApplyByKubectl(z_dep.FrontendApplyFilePath, namespace)
// backend
ApplyByKubectl(z_dep.BackendApplyFilePath, namespace)
return true
}
@@ -78,7 +142,7 @@ func clearOldApplyStuff(oldApplyYamlFolder string, cmiiEnv string) bool {
}
// rearrange
rearrangeCmiiDeploySequence(files)
//rearrangeCmiiDeploySequence(files)
for _, file := range files {
if filepath.Ext(file.Name()) == ".yaml" || filepath.Ext(file.Name()) == ".yml" {
@@ -92,21 +156,11 @@ func clearOldApplyStuff(oldApplyYamlFolder string, cmiiEnv string) bool {
// 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)
//filePath := filepath.Join(oldApplyYamlFolder, file.Name())
//DeleteByKubectl(filePath, cmiiEnv)
}
}
}