139 lines
3.1 KiB
Go
139 lines
3.1 KiB
Go
package main
|
|
|
|
import (
|
|
"bufio"
|
|
"flag"
|
|
"fmt"
|
|
"os"
|
|
"strings"
|
|
"wdd.io/agent-common/utils"
|
|
"wdd.io/agent-operator/real_project/bgtg"
|
|
)
|
|
|
|
var LocalKubeConfigFile = "/root/.kube/config"
|
|
|
|
// build for offline usage
|
|
// C:\Users\wddsh\go\bin\gox.exe -osarch="linux/amd64" -output "build/agent-operator_{{.OS}}_{{.Arch}}"
|
|
// C:\Users\wddsh\go\bin\gox.exe -osarch="linux/amd64 linux/arm64" -output "build/agent-operator_{{.OS}}_{{.Arch}}"
|
|
|
|
func RealProjectRunner() {
|
|
// build from local LocalKubeConfigFile
|
|
if !utils.FileExists(LocalKubeConfigFile) {
|
|
log.ErrorF("%s not exits! error!", LocalKubeConfigFile)
|
|
return
|
|
}
|
|
|
|
readFile, err := os.ReadFile(LocalKubeConfigFile)
|
|
if err != nil {
|
|
log.ErrorF("error reading %s, error %s", LocalKubeConfigFile, err.Error())
|
|
return
|
|
}
|
|
|
|
realNamespace := "bjtg"
|
|
|
|
op := CmiiK8sOperator{}
|
|
op.BuildCurrentClientFromConfig(readFile)
|
|
CmiiOperator = op
|
|
|
|
// ops
|
|
|
|
// update
|
|
result := UpdateCmiiImageTagFromNameTagList(realNamespace, bgtg.AllCmiiImageTagList)
|
|
//result := UpdateCmiiImageTagFromNameTagMap(realNamespace, xmyd.Real540ImageTagMap)
|
|
utils.BeautifulPrint(result)
|
|
|
|
//for _, imageFullName := range xmyd.AllCmiiImageTagList {
|
|
// appName := image.ImageFullNameToAppName(imageFullName)
|
|
// if appName == "" {
|
|
// log.InfoF("can't update %s", imageFullName)
|
|
// continue
|
|
// }
|
|
// exists := op.DeploymentExist(realNamespace, appName)
|
|
// if exists == nil {
|
|
// log.InfoF("app of %s not eixts", appName)
|
|
// continue
|
|
// }
|
|
//
|
|
// _ = op.DeploymentUpdateTag(realNamespace, appName, image.ImageFullNameToImageTag(imageFullName))
|
|
//
|
|
//}
|
|
|
|
// backup system app tag
|
|
//backendMap, frontendMap, srsMap := BackupAllCmiiDeploymentToMap(realNamespace)
|
|
//utils.BeautifulPrint(backendMap)
|
|
//utils.BeautifulPrint(frontendMap)
|
|
//utils.BeautifulPrint(srsMap)
|
|
|
|
// scale deployment
|
|
//ScaleCmiiFrontendDeploymentToDesiredReplicas(realNamespace, 1)
|
|
//ScaleCmiiBackendDeploymentToDesiredReplicas(realNamespace, 1)
|
|
|
|
// update from map
|
|
}
|
|
|
|
func CmiiRunner() {
|
|
|
|
}
|
|
|
|
var DLTUHelp = `
|
|
DLTUHelp
|
|
dltu [ossUrl] [localGzipFolder] [harborHostFullName]
|
|
`
|
|
|
|
func main() {
|
|
|
|
//RealProjectRunner()
|
|
|
|
// 解析命令行参数
|
|
var mode string
|
|
flag.StringVar(&mode, "mode", "mode", "agent run mode")
|
|
flag.Parse()
|
|
|
|
if mode == "image" {
|
|
// 堡垒机模式 的 镜像美容
|
|
// 初始化堡垒机模式
|
|
for {
|
|
|
|
reader := bufio.NewReader(os.Stdin)
|
|
for {
|
|
fmt.Printf(DLTUHelp)
|
|
fmt.Print("enter ==> ")
|
|
|
|
text, _ := reader.ReadString('\n')
|
|
split := strings.Split(text, " ")
|
|
var result []string
|
|
for _, s := range split {
|
|
text = strings.TrimSpace(s)
|
|
if text == "" {
|
|
continue
|
|
}
|
|
|
|
result = append(result, text)
|
|
}
|
|
|
|
if len(result) != 4 {
|
|
fmt.Println("input error!")
|
|
fmt.Printf(DLTUHelp)
|
|
return
|
|
}
|
|
|
|
ossUrl := result[1]
|
|
localGzipFolder := result[2]
|
|
harborHostFullName := result[3]
|
|
|
|
fmt.Println("ossUrl: ", ossUrl)
|
|
fmt.Println("localGzipFolder: ", localGzipFolder)
|
|
fmt.Println("harborHostFullName: ", harborHostFullName)
|
|
fmt.Println()
|
|
|
|
DownloadLoadTagPush(false, ossUrl, localGzipFolder, harborHostFullName)
|
|
|
|
// 下载
|
|
|
|
fmt.Println()
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|