[ Server ] [ Harbor ] - sync projects - 9
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user