[ Cmii ] [ Octopus ] - project a lot

This commit is contained in:
zeaslity
2024-03-08 17:23:41 +08:00
parent 52c360eb49
commit 5e80d7baad
56 changed files with 1112 additions and 240 deletions

View File

@@ -6,6 +6,7 @@ import (
"time"
"wdd.io/agent-go/executor"
"wdd.io/agent-go/utils"
image2 "wdd.io/cmii_operator/image"
)
var CmiiOperator = CmiiK8sOperator{}
@@ -250,18 +251,13 @@ func RestartCmiiFrontendDeployment(cmiiEnv string) {
func UpdateCmiiDeploymentImageTag(cmiiEnv, appName, newTag string) bool {
deployment := CmiiOperator.DeploymentExist(cmiiEnv, appName)
if deployment == nil {
log.ErrorF("[UpdateCmiiDeploymentImageTag] - [%s] [%s] not exists !", cmiiEnv, appName)
cmiiDeploymentInterface := CmiiOperator.DeploymentOneInterface(cmiiEnv, appName)
if cmiiDeploymentInterface == nil {
return false
}
deploymentInterface := CmiiDeploymentInterface{}
cmiiDeploymentInterface := deploymentInterface.Convert(*deployment)
// check if need to update
if cmiiDeploymentInterface.ImageTag == newTag {
log.DebugF("[UpdateCmiiDeploymentImageTag] - [%s] [%s] image tag are the same ! no need to update !", cmiiEnv, appName)
// restart
if CmiiOperator.DeploymentRestart(cmiiEnv, appName) {
return true
@@ -270,8 +266,8 @@ func UpdateCmiiDeploymentImageTag(cmiiEnv, appName, newTag string) bool {
}
}
content := executor.BasicWordSpaceCompletion(utils.TimeSplitFormatString()+" "+cmiiDeploymentInterface.Namespace, 45)
content = executor.BasicWordSpaceCompletion(content+cmiiDeploymentInterface.Name, 85)
content := executor.BasicWordSpaceCompletion(utils.TimeSplitFormatString()+" "+cmiiDeploymentInterface.Namespace, 35)
content = executor.BasicWordSpaceCompletion(content+cmiiDeploymentInterface.Name, 75)
content = executor.BasicWordSpaceCompletion(content+cmiiDeploymentInterface.ImageTag, 105)
content = content + newTag + "\n"
@@ -296,7 +292,7 @@ func UpdateCmiiDeploymentImageTag(cmiiEnv, appName, newTag string) bool {
}
// log
log.InfoF("[UpdateCmiiDeploymentImageTag] - real image tag are [%s] \n update tag [%s] success ! ", deploy.Image, content)
//log.InfoF("[UpdateCmiiDeploymentImageTag] - real image tag are [%s] update tag [%s] success ! ", deploy.Image, content)
return true
}
@@ -305,7 +301,9 @@ func UpdateCmiiImageTagFromNameTagMap(cmiiEnv string, nameTagMap map[string]stri
result = make(map[string]string, len(nameTagMap))
for appName, newTag := range nameTagMap {
if AppNameBelongsToCmiiImage(appName) {
if UpdateCmiiDeploymentImageTag(cmiiEnv, appName, newTag) {
log.InfoF("[UpdateCmiiImageTagFromNameTagMap] - %s %s to %s", cmiiEnv, appName, newTag)
result[appName] = newTag
} else {
result[appName] = "false"
@@ -407,13 +405,14 @@ func BackupAllDeploymentFromEnv(cmiiEnv string) bool {
return true
}
func BackupAllCmiiDeploymentToMap(cmiiEnv string) (backendMap, frontendMap map[string]string) {
func BackupAllCmiiDeploymentToMap(cmiiEnv string) (backendMap, frontendMap, srsMap map[string]string) {
allInterface := CmiiOperator.DeploymentAllInterface(cmiiEnv)
allInterface = FilterAllCmiiAppSoft(allInterface)
backendMap = make(map[string]string, len(allInterface))
frontendMap = make(map[string]string, len(allInterface))
srsMap = make(map[string]string, len(allInterface))
for _, deploymentInterface := range allInterface {
if strings.Contains(deploymentInterface.Name, "platform") {
@@ -423,7 +422,33 @@ func BackupAllCmiiDeploymentToMap(cmiiEnv string) (backendMap, frontendMap map[s
}
}
return backendMap, frontendMap
// add srs part
for key, value := range CmiiSrsAppMap {
var app *CmiiDeploymentInterface
if strings.Contains(value, "deployment") {
app = CmiiOperator.DeploymentOneInterface(cmiiEnv, key)
if app != nil {
for _, image := range app.ContainerImageMap {
split := strings.Split(image, ":")
if strings.Contains(split[0], image2.CmiiHarborPrefix) {
split[0] = strings.Split(split[0], image2.CmiiHarborPrefix)[1]
}
srsMap[split[0]] = split[1]
}
}
} else if strings.Contains(value, "state") {
app = CmiiOperator.StatefulSetOneInterface(cmiiEnv, key)
if app != nil {
for _, image := range app.ContainerImageMap {
split := strings.Split(image, ":")
split[0], _ = strings.CutPrefix(split[0], image2.CmiiHarborPrefix)
srsMap[split[0]] = split[1]
}
}
}
}
return backendMap, frontendMap, srsMap
}
func BackUpAllCmiiAppImageNameFromEnv(cmiiEnv string) {