From e520ddc66dc77bc0e7df543f4b0924ff264131d2 Mon Sep 17 00:00:00 2001 From: zeaslity Date: Thu, 16 Nov 2023 11:47:51 +0800 Subject: [PATCH] [ Server ] [ Harbor ] - sync projects - 9 --- agent-go/executor/HarborExecutor.go | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/agent-go/executor/HarborExecutor.go b/agent-go/executor/HarborExecutor.go index 8410c1c..5b62fb2 100644 --- a/agent-go/executor/HarborExecutor.go +++ b/agent-go/executor/HarborExecutor.go @@ -234,22 +234,19 @@ func (hOp *HarborOperator) SyncProjectExec(funcArgs []string) (bool, []string) { if policy.Name == octopusReplicationPolicyName { err := targetClient.DeleteReplicationPolicyByID(ctx, policy.ID) if err != nil { - return false, []string{ - "[Harbor Sync Project ] - delete exists replication policy failed !", - } + log.ErrorF("[Harbor Sync Project ] - delete exists replication policy failed ! => %v ", policy) } } } } + log.Debug("[Harbor Sync Project ] - start to delete exist exist harbor endpoints !") exitRegistry, _ := targetClient.GetRegistryByName(ctx, OctopusSourceHarborName) if exitRegistry != nil { log.Debug("[Harbor Sync Project ] - source endpoints already exists ! delete it !") err := targetClient.DeleteRegistryByID(ctx, exitRegistry.ID) if err != nil { - return false, []string{ - "[Harbor Sync Project ] - source endpoints delete failed !", - } + log.ErrorF("[Harbor Sync Project ] - source endpoints delete failed ! => %v ", exitRegistry) } } @@ -271,8 +268,16 @@ func (hOp *HarborOperator) SyncProjectExec(funcArgs []string) (bool, []string) { "[Harbor Sync Project ] - source endpoints create failed !", } } - // 创建复制策略 + // get the real one for it's ID + realOctopusSourceRegistry, err := targetClient.GetRegistryByName(ctx, OctopusSourceHarborName) + if err != nil { + return false, []string{ + "[Harbor Sync Project ] - source endpoints get failed !", + } + } + + // 创建复制策略 octopusReplicationPolicy := &model.ReplicationPolicy{ CopyByChunk: nil, Deletion: false, @@ -280,7 +285,7 @@ func (hOp *HarborOperator) SyncProjectExec(funcArgs []string) (bool, []string) { DestNamespace: "", // 可以指定目标 Harbor 中的特定项目,如果为空,则使用源项目名称 DestNamespaceReplaceCount: nil, SrcRegistry: &model.Registry{ - ID: octopusSourceRegistry.ID, + ID: realOctopusSourceRegistry.ID, }, DestRegistry: &model.Registry{ ID: 0, @@ -308,8 +313,9 @@ func (hOp *HarborOperator) SyncProjectExec(funcArgs []string) (bool, []string) { log.Info("[Harbor Sync Project ] - Start To Sync Project !") 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 !: %s\n", err.Error()) + syncErrorMessage := fmt.Sprintf("[Harbor Sync Project ] - Sync Project Failed ! Error is => %s\n", err.Error()) log.Error(syncErrorMessage) return false, []string{ syncErrorMessage,