[ Server ] [ Harbor ] - sync status - 7

This commit is contained in:
zeaslity
2023-11-16 17:29:55 +08:00
parent 80b36d0c6e
commit f1b8f8efc8
4 changed files with 69 additions and 29 deletions

View File

@@ -210,11 +210,14 @@ func (hOp *HarborOperator) SyncProjectExec(funcArgs []string) (bool, []string) {
hOp.SourceHarborClient = createClient
}
needToSynchronizedProject := funcArgs[2]
log.InfoF("[Harbor Sync Project ] - start to sync harbor project => %s", needToSynchronizedProject)
log.DebugF("[Harbor Sync Project ] - start to check projects all exists!")
ctx := context.Background()
// check both source and target harbor project exists
needToCreateProjectNameList := []string{"cmii", "rancher"}
needToCreateProjectNameList := []string{"rancher", "cmii"}
for _, projectName := range needToCreateProjectNameList {
syncNotExistHarborProjectError := []string{
@@ -298,7 +301,7 @@ func (hOp *HarborOperator) SyncProjectExec(funcArgs []string) (bool, []string) {
Filters: []*model.ReplicationFilter{
{
Type: "name",
Value: "rancher/**", // 根据需要同步的仓库进行调整
Value: needToSynchronizedProject + "/**",
},
},
ID: 0,
@@ -314,12 +317,12 @@ func (hOp *HarborOperator) SyncProjectExec(funcArgs []string) (bool, []string) {
}
// 在源 Harbor 中创建复制策略
log.Info("[Harbor Sync Project ] - Start To Sync Project !")
log.InfoF("[Harbor Sync Project ] - Start To Sync Project => %s !", needToSynchronizedProject)
err = targetClient.NewReplicationPolicy(ctx, octopusReplicationPolicy.DestRegistry, octopusReplicationPolicy.SrcRegistry, octopusReplicationPolicy.Deletion, octopusReplicationPolicy.Override, octopusReplicationPolicy.Enabled, octopusReplicationPolicy.Filters, octopusReplicationPolicy.Trigger, octopusReplicationPolicy.DestNamespace, octopusReplicationPolicy.Name, octopusReplicationPolicy.Name)
if err != nil {
syncErrorMessage := fmt.Sprintf("[Harbor Sync Project ] - Sync Project Failed ! Error is => %s\n", err.Error())
syncErrorMessage := fmt.Sprintf("[Harbor Sync Project ] - Sync Project [ %s ] Failed ! Error is => %s\n", needToSynchronizedProject, err.Error())
log.Error(syncErrorMessage)
return false, []string{
syncErrorMessage,
@@ -345,7 +348,7 @@ func (hOp *HarborOperator) SyncProjectExec(funcArgs []string) (bool, []string) {
}
return true, []string{
"[ Harbor Sync Project ] - sync started !",
fmt.Sprintf("[ Harbor Sync Project ] - sync project [ %s ] started !", needToSynchronizedProject),
}
}
@@ -385,10 +388,12 @@ func (hOp *HarborOperator) SyncStatusExec(funcArgs []string) (bool, []string) {
// find the newest one only have one here
for _, execution := range replicationExecutions {
if !strings.HasPrefix(execution.Status, "Succeed") {
log.InfoF("[sync status]- status are => %v", execution)
bytes, _ := json.Marshal(execution)
log.InfoF("[sync status]- status are => %v", string(bytes))
// report status
return false, []string{
fmt.Sprintf("[sync status] - not complete ! progress is => %s %", strconv.FormatInt(execution.Succeed/execution.Total, 10)),
fmt.Sprintf("[sync status] - not complete ! progress is => %s %",
strconv.FormatFloat(float64(execution.Succeed)/float64(execution.Total), 'f', 1, 64)),
}
}
}