[agent-operator] - image bastion mode

This commit is contained in:
zeaslity
2024-04-19 16:50:56 +08:00
parent 6f9cba1270
commit c6ee9ed859
18 changed files with 609 additions and 83 deletions

View File

@@ -2,8 +2,11 @@ package image
import (
"strings"
"wdd.io/agent-common/logger"
)
var log = logger.Log
var unSupported = "UN-SUPPORT-APP-NAME"
const CmiiHarborPrefix = "harbor.cdcyy.com.cn/cmii/"
@@ -99,7 +102,8 @@ func ImageFullNameToGzipFileName(imageFullName string) (gzipFileName string) {
return gzipFileName
}
func ImageFullNameToTargetImageFullName(imageFullName, targetHost string) string {
// ImageNameToTargetImageFullName 将ImageName转换为目标TargetHosts的全名称ImageName的格式为 短名称或者长名称 均可
func ImageNameToTargetImageFullName(imageFullName, targetHostFullName string) string {
if strings.HasPrefix(imageFullName, CmiiHarborPrefix) {
imageFullName = strings.TrimPrefix(imageFullName, CmiiHarborPrefix)
@@ -108,7 +112,7 @@ func ImageFullNameToTargetImageFullName(imageFullName, targetHost string) string
}
// rancher/123:v123
if strings.HasPrefix(imageFullName, "rancher") {
return targetHost + "/" + imageFullName
return targetHostFullName + "/" + imageFullName
}
// ossr/srs:v4.0.5
if strings.Contains(imageFullName, "/") {
@@ -117,10 +121,25 @@ func ImageFullNameToTargetImageFullName(imageFullName, targetHost string) string
// srs:v4.0.5
// cmii-uav-platform:5.4.0
return targetHost + "/cmii/" + imageFullName
s := targetHostFullName + "/cmii/" + imageFullName
log.InfoF("ImageFullName: [%s] to TargetImageFullName: [%s]", imageFullName, s)
return s
}
func GzipFileNameToImageFullName(gzipFileName string) (imageFullName string) {
if !strings.HasSuffix(gzipFileName, ".tar.gz") {
log.ErrorF(" %s is not end with .tar.gz", gzipFileName)
return ""
}
gzipFileName = strings.TrimSuffix(gzipFileName, ".tar.gz")
if strings.HasPrefix(gzipFileName, "docker") {
return strings.Split(gzipFileName, "=")[1] + "/" + strings.Split(gzipFileName, "=")[2] + ":" + strings.Split(gzipFileName, "=")[3]
}
if strings.HasPrefix(gzipFileName, "cmlc=cmii=") {
return strings.Split(gzipFileName, "=")[2] + ":" + strings.Split(gzipFileName, "=")[3]
}
return gzipFileName
}