[ Cmii ] [ Operator ] - agent operator for DCU part
This commit is contained in:
@@ -69,6 +69,8 @@ func BasicDownloadFileHTTP(downloadUrl string, proxyUrl string, proxyUser string
|
|||||||
return true, resultLog
|
return true, resultLog
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// quick sort function
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
//socksProxyUrl := "socks5://192.168.35.71:22888"
|
//socksProxyUrl := "socks5://192.168.35.71:22888"
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ type CmiiMinioOperator struct {
|
|||||||
|
|
||||||
LocalClient *minio.Client
|
LocalClient *minio.Client
|
||||||
PublicClient *minio.Client
|
PublicClient *minio.Client
|
||||||
|
DemoClient *minio.Client
|
||||||
|
|
||||||
OctopusBucketName string
|
OctopusBucketName string
|
||||||
}
|
}
|
||||||
@@ -22,6 +23,7 @@ type CmiiMinioOperator struct {
|
|||||||
const (
|
const (
|
||||||
DefaultLocalEndpoint = "http://10.250.0.100:9000"
|
DefaultLocalEndpoint = "http://10.250.0.100:9000"
|
||||||
DefaultPublicEndpoint = "http://42.192.52.227:9000"
|
DefaultPublicEndpoint = "http://42.192.52.227:9000"
|
||||||
|
DemoEndpoint = "https://oss.demo.uavcmlc.com:18000"
|
||||||
DefaultAccessKeyID = "cmii"
|
DefaultAccessKeyID = "cmii"
|
||||||
DefaultSecretAccessKey = "B#923fC7mk"
|
DefaultSecretAccessKey = "B#923fC7mk"
|
||||||
DefaultOctopusBucketName = "octopus"
|
DefaultOctopusBucketName = "octopus"
|
||||||
@@ -46,6 +48,14 @@ func (op CmiiMinioOperator) buildCmiiMinioOperator() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if op.DemoClient == nil {
|
||||||
|
// 初始化Minio客户端对象。
|
||||||
|
op.PublicClient, err = minio.New(DemoEndpoint, DefaultAccessKeyID, DefaultSecretAccessKey, false)
|
||||||
|
if err != nil {
|
||||||
|
log.ErrorF("[buildCmiiMinioOperator] - build for DemoClient error ! => %s", err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
log.DebugF("[buildCmiiMinioOperator] - build client success !")
|
log.DebugF("[buildCmiiMinioOperator] - build client success !")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,8 +70,19 @@ func (op CmiiMinioOperator) UploadToPublicOctopus(filePath, fileName string) boo
|
|||||||
return op.uploadToOctopus(op.PublicClient, filePath, fileName)
|
return op.uploadToOctopus(op.PublicClient, filePath, fileName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (op CmiiMinioOperator) UploadToDemo(bucketName, filePath, fileName string) bool {
|
||||||
|
|
||||||
|
op.buildCmiiMinioOperator()
|
||||||
|
return op.uploadToOss(op.PublicClient, bucketName, filePath, fileName)
|
||||||
|
}
|
||||||
|
|
||||||
func (op CmiiMinioOperator) uploadToOctopus(client *minio.Client, filePath, fileName string) bool {
|
func (op CmiiMinioOperator) uploadToOctopus(client *minio.Client, filePath, fileName string) bool {
|
||||||
|
|
||||||
|
return op.uploadToOss(client, DefaultOctopusBucketName, filePath, fileName)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (op CmiiMinioOperator) uploadToOss(client *minio.Client, bucketName, filePath, fileName string) bool {
|
||||||
|
|
||||||
if !strings.HasSuffix(filePath, "/") {
|
if !strings.HasSuffix(filePath, "/") {
|
||||||
filePath += "/"
|
filePath += "/"
|
||||||
}
|
}
|
||||||
@@ -69,17 +90,17 @@ func (op CmiiMinioOperator) uploadToOctopus(client *minio.Client, filePath, file
|
|||||||
// 打开要上传的文件
|
// 打开要上传的文件
|
||||||
file, err := os.Open(filePath + fileName)
|
file, err := os.Open(filePath + fileName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.ErrorF("[uploadToOctopus] - file %s open error! %s", filePath+fileName, err.Error())
|
log.ErrorF("[uploadToOss] - file %s open error! %s", filePath+fileName, err.Error())
|
||||||
}
|
}
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
|
|
||||||
// 使用PutObject上传文件
|
// 使用PutObject上传文件
|
||||||
n, err := client.PutObject(DefaultOctopusBucketName, fileName, file, -1, minio.PutObjectOptions{})
|
n, err := client.PutObject(bucketName, fileName, file, -1, minio.PutObjectOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.ErrorF("[uploadToOctopus] - upload %s error %s", filePath+fileName, err.Error())
|
log.ErrorF("[uploadToOss] - upload %s error %s", filePath+fileName, err.Error())
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
log.InfoF("[uploadToOctopus] - uploaded %s of size %d", filePath+fileName, n)
|
log.InfoF("[uploadToOss] - uploaded %s of size %d", filePath+fileName, n)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,11 +18,15 @@ const PublicDeployHarborHost = "42.192.52.227"
|
|||||||
const DirectPushDeployHarborHost = "36.134.71.138"
|
const DirectPushDeployHarborHost = "36.134.71.138"
|
||||||
|
|
||||||
type ImageSyncEntity struct {
|
type ImageSyncEntity struct {
|
||||||
ProjectName string // 3
|
ProjectName string // 优先级3
|
||||||
ProjectVersion string // 2
|
ProjectVersion string // 优先级2
|
||||||
CmiiImageList map[string]string // 1
|
CmiiNameTagList []string // 优先级1 appName:tag的形式
|
||||||
DirectHarborHost string //此参数决定是否能够直连目标主机,如果有则代表直连,可以直接推送景象
|
FullNameImageList []string // 优先级1
|
||||||
PushToDemoMinio bool
|
DownloadImage bool // 下载镜像
|
||||||
|
CompressImageToGzip bool // 压缩镜像
|
||||||
|
UploadToDemoMinio bool // 上传镜像
|
||||||
|
ShouldDirectPushToHarbor bool // 直接推送到对方的主机 || 离线部署机 使用此部门
|
||||||
|
DirectHarborHost string // 目标Harbor仓库的Host,全名称带端口
|
||||||
}
|
}
|
||||||
|
|
||||||
type ImageSyncResult struct {
|
type ImageSyncResult struct {
|
||||||
@@ -38,59 +42,125 @@ type ImageSyncResult struct {
|
|||||||
func (sync ImageSyncEntity) PullFromEntityAndSyncConditionally() (imageSyncResult ImageSyncResult) {
|
func (sync ImageSyncEntity) PullFromEntityAndSyncConditionally() (imageSyncResult ImageSyncResult) {
|
||||||
|
|
||||||
var realCmiiImageList []string
|
var realCmiiImageList []string
|
||||||
var errorPullImageList []string
|
|
||||||
var errorGzipImageList []string
|
|
||||||
var allCmiiImageNameList []string
|
var allCmiiImageNameList []string
|
||||||
|
|
||||||
|
var errorPullImageList []string
|
||||||
var allGzipFileNameList []string
|
var allGzipFileNameList []string
|
||||||
|
var errorGzipImageList []string
|
||||||
var errorPushImageNameList []string
|
var errorPushImageNameList []string
|
||||||
var gzipFolderFullPath string
|
var gzipFolderFullPath string
|
||||||
// get all image name by Name or Version
|
|
||||||
|
if (sync.CmiiNameTagList == nil && sync.FullNameImageList == nil) || (len(sync.CmiiNameTagList) == 0 && len(sync.FullNameImageList) == 0) {
|
||||||
|
// 没有指定特定的镜像,那么根据 ProjectVersion 或者从DEMO拉取镜像
|
||||||
// pull images
|
// pull images
|
||||||
// compress
|
// compress
|
||||||
if sync.ProjectVersion != "" {
|
if sync.ProjectVersion != "" {
|
||||||
// get version
|
// get version
|
||||||
if sync.DirectHarborHost == "" {
|
if sync.DirectHarborHost == "" {
|
||||||
errorPullImageList, errorGzipImageList, allCmiiImageNameList = FetchVersionImages(sync.ProjectVersion, true)
|
errorPullImageList, errorGzipImageList, allCmiiImageNameList = DownloadCompressUploadFromVersion(sync.ProjectVersion, true, sync.UploadToDemoMinio)
|
||||||
gzipFolderFullPath = OfflineImageGzipFolderPrefix + sync.ProjectVersion
|
gzipFolderFullPath = OfflineImageGzipFolderPrefix + sync.ProjectVersion
|
||||||
} else {
|
} else {
|
||||||
errorPullImageList, errorGzipImageList, allCmiiImageNameList = FetchVersionImages(sync.ProjectVersion, false)
|
errorPullImageList, errorGzipImageList, allCmiiImageNameList = DownloadCompressUploadFromVersion(sync.ProjectVersion, false, sync.UploadToDemoMinio)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// get demo images
|
// get demo images
|
||||||
if sync.DirectHarborHost == "" {
|
if sync.DirectHarborHost == "" {
|
||||||
errorPullImageList, errorGzipImageList, allCmiiImageNameList = FetchDemoImages(sync.ProjectName, true)
|
errorPullImageList, errorGzipImageList, allCmiiImageNameList = DownloadCompressUploadFromDemo(sync.ProjectName, sync.CompressImageToGzip, sync.UploadToDemoMinio)
|
||||||
gzipFolderFullPath = OfflineImageGzipFolderPrefix + sync.ProjectName
|
gzipFolderFullPath = OfflineImageGzipFolderPrefix + sync.ProjectName
|
||||||
} else {
|
} else {
|
||||||
errorPullImageList, errorGzipImageList, allCmiiImageNameList = FetchDemoImages(sync.ProjectName, false)
|
errorPullImageList, errorGzipImageList, allCmiiImageNameList = DownloadCompressUploadFromDemo(sync.ProjectName, false, sync.UploadToDemoMinio)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// 拉取特定的镜像
|
||||||
|
|
||||||
backAllImageNameList := allCmiiImageNameList[:]
|
gzipFolderFullPath = OfflineImageGzipFolderPrefix + "tmp"
|
||||||
realCmiiImageList = slices.DeleteFunc(backAllImageNameList, func(imageName string) bool {
|
// 组装镜像名称
|
||||||
return slices.Contains(errorPullImageList, imageName)
|
allCmiiImageNameList = concatAndUniformCmiiImage(sync.FullNameImageList, sync.CmiiNameTagList)
|
||||||
})
|
|
||||||
realCmiiImageList = slices.DeleteFunc(backAllImageNameList, func(imageName string) bool {
|
|
||||||
return slices.Contains(errorGzipImageList, imageName)
|
|
||||||
})
|
|
||||||
|
|
||||||
// direct push if can
|
// DCU
|
||||||
if sync.DirectHarborHost != "" {
|
errorPullImageList, errorGzipImageList, realCmiiImageList, allGzipFileNameList = DownloadCompressUploadFromFullNameList(allCmiiImageNameList, sync.CompressImageToGzip, gzipFolderFullPath, sync.UploadToDemoMinio)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 直接传输到目标Harbor仓库
|
||||||
|
if sync.ShouldDirectPushToHarbor {
|
||||||
|
if sync.DirectHarborHost == "" {
|
||||||
|
log.ErrorF("DirectHarborHost is null ! can't push to target harbor !")
|
||||||
|
}
|
||||||
// push to
|
// push to
|
||||||
errorPushImageNameList = image.TagFromListAndPushToCHarbor(realCmiiImageList, sync.DirectHarborHost)
|
errorPushImageNameList = image.TagFromListAndPushToCHarbor(realCmiiImageList, sync.DirectHarborHost)
|
||||||
|
|
||||||
// build
|
|
||||||
imageSyncResult.AllCmiiImageNameList = allCmiiImageNameList
|
|
||||||
imageSyncResult.ErrorPullImageList = errorPullImageList
|
|
||||||
imageSyncResult.ErrorGzipImageList = errorGzipImageList
|
|
||||||
imageSyncResult.ErrorPushImageNameList = errorPushImageNameList
|
|
||||||
imageSyncResult.RealImageNameList = realCmiiImageList
|
|
||||||
|
|
||||||
// no gzip file
|
|
||||||
|
|
||||||
return imageSyncResult
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// build result
|
||||||
|
imageSyncResult.AllCmiiImageNameList = allCmiiImageNameList
|
||||||
|
|
||||||
|
imageSyncResult.RealImageNameList = realCmiiImageList
|
||||||
|
imageSyncResult.ErrorPullImageList = errorPullImageList
|
||||||
|
|
||||||
|
imageSyncResult.RealGzipFileNameList = allGzipFileNameList
|
||||||
|
imageSyncResult.ErrorGzipImageList = errorGzipImageList
|
||||||
|
|
||||||
|
imageSyncResult.ErrorPushImageNameList = errorPushImageNameList
|
||||||
|
|
||||||
|
return imageSyncResult
|
||||||
|
}
|
||||||
|
|
||||||
|
func concatAndUniformCmiiImage(fullImageList []string, cmiiImageList []string) []string {
|
||||||
|
|
||||||
|
if cmiiImageList != nil || len(cmiiImageList) > 0 {
|
||||||
|
// cmiiImageList has content
|
||||||
|
if fullImageList == nil {
|
||||||
|
fullImageList = []string{}
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, cmiiImage := range cmiiImageList {
|
||||||
|
fullImageList = append(fullImageList, image2.CmiiHarborPrefix+cmiiImage)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return fullImageList
|
||||||
|
}
|
||||||
|
|
||||||
|
func DownloadCompressUploadFromFullNameList(fullNameList []string, shouldGzip bool, gzipFolderFullPath string, shouldOss bool) (errorPullImageList, errorGzipImageList, realCmiiImageName, allGzipFileNameList []string) {
|
||||||
|
|
||||||
|
// Download
|
||||||
|
log.Info("DOWNLOAD START !")
|
||||||
|
errorPullImageList = image.PullFromFullNameList(fullNameList)
|
||||||
|
// remove failed
|
||||||
|
fullNameList = slices.DeleteFunc(fullNameList, func(imageName string) bool {
|
||||||
|
return slices.Contains(errorPullImageList, imageName)
|
||||||
|
})
|
||||||
|
|
||||||
|
// Compress
|
||||||
|
if shouldGzip {
|
||||||
|
// mkdir folder
|
||||||
|
err := os.MkdirAll(gzipFolderFullPath, os.ModeDir)
|
||||||
|
if err != nil {
|
||||||
|
if !errors.Is(err, os.ErrExist) {
|
||||||
|
log.ErrorF("create folder error of %s", gzipFolderFullPath)
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 循环遍历压缩
|
||||||
|
log.Info("COMPRESS START")
|
||||||
|
|
||||||
|
for _, imageFullName := range fullNameList {
|
||||||
|
if !image.SaveToTarGZ(imageFullName, gzipFolderFullPath) {
|
||||||
|
errorGzipImageList = append(errorGzipImageList, imageFullName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// remove failed
|
||||||
|
fullNameList = slices.DeleteFunc(fullNameList, func(imageName string) bool {
|
||||||
|
return slices.Contains(errorGzipImageList, imageName)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Upload
|
||||||
|
if shouldOss {
|
||||||
|
//uploadGzipFileToDemoMinio()
|
||||||
// get gzip file name list
|
// get gzip file name list
|
||||||
|
log.Info("UPLOAD OSS START !")
|
||||||
err := filepath.WalkDir(gzipFolderFullPath, func(path string, d fs.DirEntry, err error) error {
|
err := filepath.WalkDir(gzipFolderFullPath, func(path string, d fs.DirEntry, err error) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.ErrorF("error getting gzip file name list 1! %s", err.Error())
|
log.ErrorF("error getting gzip file name list 1! %s", err.Error())
|
||||||
@@ -104,34 +174,38 @@ func (sync ImageSyncEntity) PullFromEntityAndSyncConditionally() (imageSyncResul
|
|||||||
log.ErrorF("error getting gzip file name list 2! %s", err.Error())
|
log.ErrorF("error getting gzip file name list 2! %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
// push to demo minio
|
// start to upload
|
||||||
if sync.PushToDemoMinio {
|
// extract demo oss location suffix from gzipFolderFullPath
|
||||||
log.InfoF("pretend to push to minio !")
|
trimPrefix := strings.TrimPrefix(gzipFolderFullPath, OfflineImageGzipFolderPrefix)
|
||||||
// create path
|
bucketName := "cmlc-installation/" + trimPrefix
|
||||||
// push
|
log.InfoF("gzip file location in demo oss is %s", DemoEndpoint+"/"+bucketName)
|
||||||
|
|
||||||
|
minioOperator := CmiiMinioOperator{}
|
||||||
|
for _, gzipFileName := range allGzipFileNameList {
|
||||||
|
|
||||||
|
if !minioOperator.UploadToDemo(bucketName, gzipFolderFullPath, gzipFileName) {
|
||||||
|
log.ErrorF("upload of %s to demo oss error !", gzipFolderFullPath+gzipFileName)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// build
|
}
|
||||||
imageSyncResult.AllCmiiImageNameList = allCmiiImageNameList
|
|
||||||
imageSyncResult.ErrorPullImageList = errorPullImageList
|
|
||||||
imageSyncResult.ErrorGzipImageList = errorGzipImageList
|
|
||||||
imageSyncResult.ErrorPushImageNameList = errorPushImageNameList
|
|
||||||
imageSyncResult.RealGzipFileNameList = allGzipFileNameList
|
|
||||||
imageSyncResult.RealImageNameList = realCmiiImageList
|
|
||||||
|
|
||||||
// no gzip file
|
return errorPullImageList, errorGzipImageList, fullNameList, allGzipFileNameList
|
||||||
|
|
||||||
return imageSyncResult
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func FetchDemoImages(projectName string, gzipSplit bool) (errorPullImageList, errorGzipImageList, allCmiiImageName []string) {
|
func uploadGzipFileToDemoMinio() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// DownloadCompressUploadFromDemo 获取DEMO环境的全部镜像
|
||||||
|
func DownloadCompressUploadFromDemo(projectName string, shouldGzip bool, shouldOss bool) (errorPullImageList, errorGzipImageList, realCmiiImageName []string) {
|
||||||
|
|
||||||
// generate a project folder
|
// generate a project folder
|
||||||
err := os.MkdirAll(OfflineImageGzipFolderPrefix+projectName, os.ModeDir)
|
err := os.MkdirAll(OfflineImageGzipFolderPrefix+projectName, os.ModeDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if !errors.Is(err, os.ErrExist) {
|
if !errors.Is(err, os.ErrExist) {
|
||||||
log.ErrorF("[FetchDemoImages] - create folder of %s error %s", OfflineImageGzipFolderPrefix+projectName, err.Error())
|
log.ErrorF("[Download_Compress_Upload_From_Demo] - create folder of %s error %s", OfflineImageGzipFolderPrefix+projectName, err.Error())
|
||||||
return errorPullImageList, errorGzipImageList, allCmiiImageName
|
return errorPullImageList, errorGzipImageList, realCmiiImageName
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -168,25 +242,25 @@ func FetchDemoImages(projectName string, gzipSplit bool) (errorPullImageList, er
|
|||||||
frontendFullNameList, frontendPull := image.PullFromCmiiHarborByMap(frontendMap, true)
|
frontendFullNameList, frontendPull := image.PullFromCmiiHarborByMap(frontendMap, true)
|
||||||
srsFullNameList, srsPull := image.PullFromCmiiHarborByMap(srsMap, true)
|
srsFullNameList, srsPull := image.PullFromCmiiHarborByMap(srsMap, true)
|
||||||
|
|
||||||
allCmiiImageName = append(allCmiiImageName, backendFullNameList...)
|
realCmiiImageName = append(realCmiiImageName, backendFullNameList...)
|
||||||
allCmiiImageName = append(allCmiiImageName, frontendFullNameList...)
|
realCmiiImageName = append(realCmiiImageName, frontendFullNameList...)
|
||||||
allCmiiImageName = append(allCmiiImageName, srsFullNameList...)
|
realCmiiImageName = append(realCmiiImageName, srsFullNameList...)
|
||||||
|
|
||||||
// compress image
|
// compress image
|
||||||
if gzipSplit {
|
if shouldGzip {
|
||||||
for image_name, tag := range backendMap {
|
for imageName, tag := range backendMap {
|
||||||
if !image.SaveToTarGZ(image_name+":"+tag, OfflineImageGzipFolderPrefix+projectName+"/app/") {
|
if !image.SaveToTarGZ(imageName+":"+tag, OfflineImageGzipFolderPrefix+projectName+"/app/") {
|
||||||
errorGzipImageList = append(errorGzipImageList, image2.CmiiHarborPrefix+image_name+":"+tag)
|
errorGzipImageList = append(errorGzipImageList, image2.CmiiHarborPrefix+imageName+":"+tag)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for image_name, tag := range frontendMap {
|
for imageName, tag := range frontendMap {
|
||||||
if !image.SaveToTarGZ(image_name+":"+tag, OfflineImageGzipFolderPrefix+projectName+"/app/") {
|
if !image.SaveToTarGZ(imageName+":"+tag, OfflineImageGzipFolderPrefix+projectName+"/app/") {
|
||||||
errorGzipImageList = append(errorGzipImageList, image2.CmiiHarborPrefix+image_name+":"+tag)
|
errorGzipImageList = append(errorGzipImageList, image2.CmiiHarborPrefix+imageName+":"+tag)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for image_name, tag := range srsMap {
|
for imageName, tag := range srsMap {
|
||||||
if !image.SaveToTarGZ(image_name+":"+tag, OfflineImageGzipFolderPrefix+projectName+"/app/") {
|
if !image.SaveToTarGZ(imageName+":"+tag, OfflineImageGzipFolderPrefix+projectName+"/app/") {
|
||||||
errorGzipImageList = append(errorGzipImageList, image2.CmiiHarborPrefix+image_name+":"+tag)
|
errorGzipImageList = append(errorGzipImageList, image2.CmiiHarborPrefix+imageName+":"+tag)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -198,17 +272,18 @@ func FetchDemoImages(projectName string, gzipSplit bool) (errorPullImageList, er
|
|||||||
errorPullImageList = append(errorPullImageList, frontendPull...)
|
errorPullImageList = append(errorPullImageList, frontendPull...)
|
||||||
errorPullImageList = append(errorPullImageList, srsPull...)
|
errorPullImageList = append(errorPullImageList, srsPull...)
|
||||||
|
|
||||||
return errorPullImageList, errorGzipImageList, allCmiiImageName
|
return errorPullImageList, errorGzipImageList, realCmiiImageName
|
||||||
}
|
}
|
||||||
|
|
||||||
func FetchVersionImages(cmiiVersion string, shouldGzip bool) (errorPullImageList, errorGzipImageList, allCmiiImageName []string) {
|
// DownloadCompressUploadFromVersion 根据版本下载全部的CMII镜像
|
||||||
|
func DownloadCompressUploadFromVersion(cmiiVersion string, shouldGzip bool, shouldOss bool) (errorPullImageList, errorGzipImageList, realCmiiImageName []string) {
|
||||||
|
|
||||||
// generate a project folder
|
// generate a project folder
|
||||||
err := os.MkdirAll(OfflineImageGzipFolderPrefix+cmiiVersion, os.ModeDir)
|
err := os.MkdirAll(OfflineImageGzipFolderPrefix+cmiiVersion, os.ModeDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if !errors.Is(err, os.ErrExist) {
|
if !errors.Is(err, os.ErrExist) {
|
||||||
log.ErrorF("[FetchDemoImages] - create folder of %s error %s", OfflineImageGzipFolderPrefix+cmiiVersion, err.Error())
|
log.ErrorF("[Download_Compress_Upload_From_Demo] - create folder of %s error %s", OfflineImageGzipFolderPrefix+cmiiVersion, err.Error())
|
||||||
return errorPullImageList, errorGzipImageList, allCmiiImageName
|
return errorPullImageList, errorGzipImageList, realCmiiImageName
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -222,39 +297,39 @@ func FetchVersionImages(cmiiVersion string, shouldGzip bool) (errorPullImageList
|
|||||||
frontendMap[app] = cmiiVersion
|
frontendMap[app] = cmiiVersion
|
||||||
}
|
}
|
||||||
|
|
||||||
allCmiiImageName = append(allCmiiImageName, image.ConvertCMiiImageMapToList(backendMap)...)
|
realCmiiImageName = append(realCmiiImageName, image.ConvertCMiiImageMapToList(backendMap)...)
|
||||||
allCmiiImageName = append(allCmiiImageName, image.ConvertCMiiImageMapToList(frontendMap)...)
|
realCmiiImageName = append(realCmiiImageName, image.ConvertCMiiImageMapToList(frontendMap)...)
|
||||||
|
|
||||||
for key, value := range CmiiSrsAppMap {
|
for key, value := range CmiiSrsAppMap {
|
||||||
var app *CmiiDeploymentInterface
|
var app *CmiiDeploymentInterface
|
||||||
if strings.Contains(value, "deployment") {
|
if strings.Contains(value, "deployment") {
|
||||||
app = CmiiOperator.DeploymentOneInterface(demo, key)
|
app = CmiiOperator.DeploymentOneInterface(demo, key)
|
||||||
if app != nil {
|
if app != nil {
|
||||||
allCmiiImageName = append(allCmiiImageName, app.Image)
|
realCmiiImageName = append(realCmiiImageName, app.Image)
|
||||||
}
|
}
|
||||||
} else if strings.Contains(value, "state") {
|
} else if strings.Contains(value, "state") {
|
||||||
app = CmiiOperator.StatefulSetOneInterface(demo, key)
|
app = CmiiOperator.StatefulSetOneInterface(demo, key)
|
||||||
if app != nil {
|
if app != nil {
|
||||||
for _, imageName := range app.ContainerImageMap {
|
for _, imageName := range app.ContainerImageMap {
|
||||||
allCmiiImageName = append(allCmiiImageName, imageName)
|
realCmiiImageName = append(realCmiiImageName, imageName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
utils.BeautifulPrintListWithTitle(allCmiiImageName, "Cmii Version Image => "+cmiiVersion)
|
utils.BeautifulPrintListWithTitle(realCmiiImageName, "Cmii Version Image => "+cmiiVersion)
|
||||||
|
|
||||||
// do work
|
// do work
|
||||||
if shouldGzip {
|
if shouldGzip {
|
||||||
errorPullImageList, errorGzipImageList = image.PullFromListAndCompressSplit(allCmiiImageName, OfflineImageGzipFolderPrefix+cmiiVersion)
|
errorPullImageList, errorGzipImageList = image.PullFromListAndCompressSplit(realCmiiImageName, OfflineImageGzipFolderPrefix+cmiiVersion)
|
||||||
} else {
|
} else {
|
||||||
errorPullImageList = image.PullFromFullNameList(allCmiiImageName)
|
errorPullImageList = image.PullFromFullNameList(realCmiiImageName)
|
||||||
}
|
}
|
||||||
|
|
||||||
return errorPullImageList, errorGzipImageList, allCmiiImageName
|
return errorPullImageList, errorGzipImageList, realCmiiImageName
|
||||||
}
|
}
|
||||||
|
|
||||||
func FetchDependencyRepos(gzipSplit bool) (errorPullImageList, errorGzipImageList []string) {
|
func DownloadCompressUploadDependency(shouldGzip bool, shouldOss bool) (errorPullImageList, errorGzipImageList []string) {
|
||||||
err := os.MkdirAll(OfflineImageGzipFolderPrefix, os.ModeDir)
|
err := os.MkdirAll(OfflineImageGzipFolderPrefix, os.ModeDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if !errors.Is(err, os.ErrExist) {
|
if !errors.Is(err, os.ErrExist) {
|
||||||
@@ -262,10 +337,13 @@ func FetchDependencyRepos(gzipSplit bool) (errorPullImageList, errorGzipImageLis
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// pull middleware images
|
||||||
errorPullImageList, errorGzipImageList = image.PullFromListAndCompressSplit(image.MiddlewareAmd64, OfflineImageGzipFolderPrefix+"middle/")
|
errorPullImageList, errorGzipImageList = image.PullFromListAndCompressSplit(image.MiddlewareAmd64, OfflineImageGzipFolderPrefix+"middle/")
|
||||||
|
|
||||||
|
// pull rke images
|
||||||
pull, gzipImageList := image.PullFromListAndCompressSplit(image.Rancher1204Amd64, OfflineImageGzipFolderPrefix+"rke/")
|
pull, gzipImageList := image.PullFromListAndCompressSplit(image.Rancher1204Amd64, OfflineImageGzipFolderPrefix+"rke/")
|
||||||
|
|
||||||
|
// result
|
||||||
return append(errorPullImageList, pull...), append(errorGzipImageList, gzipImageList...)
|
return append(errorPullImageList, pull...), append(errorGzipImageList, gzipImageList...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,32 +2,36 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
image2 "wdd.io/agent-common/image"
|
||||||
"wdd.io/agent-common/utils"
|
"wdd.io/agent-common/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
/* 拉取
|
||||||
|
*/
|
||||||
|
|
||||||
func TestFetchDemoImages(t *testing.T) {
|
func TestFetchDemoImages(t *testing.T) {
|
||||||
|
|
||||||
errorPullImageList, errorGzipImageList, allCmiiImageName := FetchDemoImages("shls", true)
|
//errorPullImageList, errorGzipImageList, allCmiiImageName := DownloadCompressUploadFromDemo("shls", true)
|
||||||
|
//
|
||||||
utils.BeautifulPrintListWithTitle(errorPullImageList, "cmii errorPullImageList")
|
//utils.BeautifulPrintListWithTitle(errorPullImageList, "cmii errorPullImageList")
|
||||||
utils.BeautifulPrintListWithTitle(errorGzipImageList, "cmii errorGzipImageList")
|
//utils.BeautifulPrintListWithTitle(errorGzipImageList, "cmii errorGzipImageList")
|
||||||
utils.BeautifulPrintListWithTitle(allCmiiImageName, "cmii allCmiiImageName")
|
//utils.BeautifulPrintListWithTitle(allCmiiImageName, "cmii allCmiiImageName")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFetchVersionImages(t *testing.T) {
|
func TestFetchVersionImages(t *testing.T) {
|
||||||
errorPullImageList, errorGzipImageList, allCmiiImageName := FetchVersionImages("5.4.0", true)
|
//errorPullImageList, errorGzipImageList, allCmiiImageName := DownloadCompressUploadFromVersion("5.4.0", true)
|
||||||
|
//
|
||||||
utils.BeautifulPrintListWithTitle(errorPullImageList, "cmii errorPullImageList")
|
//utils.BeautifulPrintListWithTitle(errorPullImageList, "cmii errorPullImageList")
|
||||||
utils.BeautifulPrintListWithTitle(errorGzipImageList, "cmii errorGzipImageList")
|
//utils.BeautifulPrintListWithTitle(errorGzipImageList, "cmii errorGzipImageList")
|
||||||
utils.BeautifulPrintListWithTitle(allCmiiImageName, "cmii allCmiiImageName")
|
//utils.BeautifulPrintListWithTitle(allCmiiImageName, "cmii allCmiiImageName")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFetchDependencyRepos(t *testing.T) {
|
func TestFetchDependencyRepos(t *testing.T) {
|
||||||
|
|
||||||
errorPullImageList, errorGzipImageList := FetchDependencyRepos(true)
|
//errorPullImageList, errorGzipImageList := FetchDependencyRepos(true)
|
||||||
|
//
|
||||||
utils.BeautifulPrintListWithTitle(errorPullImageList, "dep errorPullImageList")
|
//utils.BeautifulPrintListWithTitle(errorPullImageList, "dep errorPullImageList")
|
||||||
utils.BeautifulPrintListWithTitle(errorGzipImageList, "dep errorGzipImageList")
|
//utils.BeautifulPrintListWithTitle(errorGzipImageList, "dep errorGzipImageList")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLoadSplitGzipImageToTargetHarbor(t *testing.T) {
|
func TestLoadSplitGzipImageToTargetHarbor(t *testing.T) {
|
||||||
@@ -44,6 +48,48 @@ func TestLoadSplitDepGzipImageToTargetHarbor(t *testing.T) {
|
|||||||
utils.BeautifulPrintListWithTitle(errorPushImageNameList, "errorPushImageNameList")
|
utils.BeautifulPrintListWithTitle(errorPushImageNameList, "errorPushImageNameList")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPullFromEntityAndSyncConditionally(t *testing.T) {
|
||||||
|
// 创建一个模拟的sync对象,用于测试函数的行为。这里需要根据你的实际需求来设置mock数据和预期结果。
|
||||||
|
sync := ImageSyncEntity{
|
||||||
|
CmiiNameTagList: []string{
|
||||||
|
"cmii-uav-gateway:5.4.0",
|
||||||
|
},
|
||||||
|
FullNameImageList: nil,
|
||||||
|
ProjectVersion: "",
|
||||||
|
DirectHarborHost: "",
|
||||||
|
CompressImageToGzip: false,
|
||||||
|
UploadToDemoMinio: false,
|
||||||
|
ShouldDirectPushToHarbor: false,
|
||||||
|
}
|
||||||
|
|
||||||
|
// 调用函数并获取结果。这里需要根据你的实际需求来验证返回的结果是否符合预期。
|
||||||
|
result := sync.PullFromEntityAndSyncConditionally()
|
||||||
|
|
||||||
|
utils.BeautifulPrint(sync)
|
||||||
|
|
||||||
|
// 添加断言以检查函数的输出,例如:
|
||||||
|
if len(result.ErrorPullImageList) != 0 {
|
||||||
|
t.Errorf("Expected no error pulling images, got %v", result.ErrorPullImageList)
|
||||||
|
}
|
||||||
|
// ...其他验证逻辑...
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestConcatAndUniformCmiiImage(t *testing.T) {
|
||||||
|
// 创建一个模拟的fullImageList和cmiiImageList,用于测试函数的行为。这里需要根据你的实际需求来设置mock数据和预期结果。
|
||||||
|
fullImageList := []string{"image3", "image4"}
|
||||||
|
cmiiImageList := []string{"image1", "image2"}
|
||||||
|
|
||||||
|
// 调用函数并获取结果。这里需要根据你的实际需求来验证返回的结果是否符合预期。
|
||||||
|
result := concatAndUniformCmiiImage(fullImageList, cmiiImageList)
|
||||||
|
|
||||||
|
// 添加断言以检查函数的输出,例如:
|
||||||
|
expectedResult := []string{"image3", "image4", image2.CmiiHarborPrefix + "image1", image2.CmiiHarborPrefix + "image2"}
|
||||||
|
if len(result) != len(expectedResult) {
|
||||||
|
t.Errorf("Expected %v, got %v", expectedResult, result)
|
||||||
|
}
|
||||||
|
// ...其他验证逻辑...
|
||||||
|
}
|
||||||
|
|
||||||
func TestImageSyncEntity_PullFromEntityAndSyncConditionally(t *testing.T) {
|
func TestImageSyncEntity_PullFromEntityAndSyncConditionally(t *testing.T) {
|
||||||
imageSyncEntity := ImageSyncEntity{
|
imageSyncEntity := ImageSyncEntity{
|
||||||
ProjectVersion: "5.4.0",
|
ProjectVersion: "5.4.0",
|
||||||
|
|||||||
@@ -311,22 +311,22 @@ func PullCmiiFromFileJson(filePathName string) {
|
|||||||
// PullFromFullNameList 根据镜像名列表拉取全部的镜像
|
// PullFromFullNameList 根据镜像名列表拉取全部的镜像
|
||||||
func PullFromFullNameList(fullImageNameList []string) (errorPullImageList []string) {
|
func PullFromFullNameList(fullImageNameList []string) (errorPullImageList []string) {
|
||||||
|
|
||||||
for _, dep := range fullImageNameList {
|
for _, fullImageName := range fullImageNameList {
|
||||||
|
|
||||||
pullResult := PullFromCmiiHarbor(dep)
|
pullResult := PullFromCmiiHarbor(fullImageName)
|
||||||
if pullResult == nil {
|
if pullResult == nil {
|
||||||
errorPullImageList = append(errorPullImageList, dep)
|
errorPullImageList = append(errorPullImageList, fullImageName)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
scanner := bufio.NewScanner(pullResult)
|
scanner := bufio.NewScanner(pullResult)
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
line := scanner.Text()
|
//line := scanner.Text()
|
||||||
if strings.Contains(line, "\"status\":\"Pulling from") {
|
//if strings.Contains(line, "\"status\":\"Pulling from") {
|
||||||
fmt.Println(line)
|
// fmt.Println(line)
|
||||||
}
|
//}
|
||||||
if strings.Contains(line, "Status: Image is up to date for") {
|
//if strings.Contains(line, "Status: Image is up to date for") {
|
||||||
fmt.Println(line)
|
// fmt.Println(line)
|
||||||
}
|
//}
|
||||||
}
|
}
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,8 +12,7 @@ var LocalKubeConfigFile = "/root/.kube/config"
|
|||||||
// 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" -output "build/agent-operator_{{.OS}}_{{.Arch}}"
|
||||||
// C:\Users\wddsh\go\bin\gox.exe -osarch="linux/amd64 linux/arm64" -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 main() {
|
func RealProjectRunner() {
|
||||||
|
|
||||||
// build from local LocalKubeConfigFile
|
// build from local LocalKubeConfigFile
|
||||||
if !utils.FileExists(LocalKubeConfigFile) {
|
if !utils.FileExists(LocalKubeConfigFile) {
|
||||||
log.ErrorF("%s not exits! error!", LocalKubeConfigFile)
|
log.ErrorF("%s not exits! error!", LocalKubeConfigFile)
|
||||||
@@ -65,5 +64,13 @@ func main() {
|
|||||||
//ScaleCmiiBackendDeploymentToDesiredReplicas(realNamespace, 1)
|
//ScaleCmiiBackendDeploymentToDesiredReplicas(realNamespace, 1)
|
||||||
|
|
||||||
// update from map
|
// update from map
|
||||||
|
}
|
||||||
|
|
||||||
|
func CmiiRunner() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
|
||||||
|
CmiiRunner()
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user