[ Server ] [ Harbor ] - sync projects - 9
This commit is contained in:
@@ -221,10 +221,27 @@ func (hOp *HarborOperator) SyncProjectExec(funcArgs []string) (bool, []string) {
|
|||||||
return false, append(syncNotExistHarborProjectError, "targetClient")
|
return false, append(syncNotExistHarborProjectError, "targetClient")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
octopusReplicationPolicyName := "octopus-sync-replication"
|
||||||
|
OctopusSourceHarborName := "octopus-source"
|
||||||
|
|
||||||
// add source registry to destination harbor
|
// add source registry to destination harbor
|
||||||
log.InfoF("[Harbor Sync Project ] - start to create source harbor endpoints => %s", hOp.SourceHarborHost)
|
log.InfoF("[Harbor Sync Project ] - start to create source harbor endpoints => %s", hOp.SourceHarborHost)
|
||||||
OctopusSourceHarborName := "octopus-source"
|
|
||||||
|
log.Debug("[Harbor Sync Project ] - start to delete exist replication policy !")
|
||||||
|
policies, _ := targetClient.ListReplicationPolicies(ctx)
|
||||||
|
if policies != nil {
|
||||||
|
for _, policy := range policies {
|
||||||
|
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.Debug("[Harbor Sync Project ] - start to delete exist exist harbor endpoints !")
|
||||||
exitRegistry, _ := targetClient.GetRegistryByName(ctx, OctopusSourceHarborName)
|
exitRegistry, _ := targetClient.GetRegistryByName(ctx, OctopusSourceHarborName)
|
||||||
if exitRegistry != nil {
|
if exitRegistry != nil {
|
||||||
log.Debug("[Harbor Sync Project ] - source endpoints already exists ! delete it !")
|
log.Debug("[Harbor Sync Project ] - source endpoints already exists ! delete it !")
|
||||||
@@ -255,6 +272,7 @@ func (hOp *HarborOperator) SyncProjectExec(funcArgs []string) (bool, []string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 创建复制策略
|
// 创建复制策略
|
||||||
|
|
||||||
octopusReplicationPolicy := &model.ReplicationPolicy{
|
octopusReplicationPolicy := &model.ReplicationPolicy{
|
||||||
CopyByChunk: nil,
|
CopyByChunk: nil,
|
||||||
Deletion: false,
|
Deletion: false,
|
||||||
@@ -275,7 +293,7 @@ func (hOp *HarborOperator) SyncProjectExec(funcArgs []string) (bool, []string) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
ID: 0,
|
ID: 0,
|
||||||
Name: "octopus-sync-replication",
|
Name: octopusReplicationPolicyName,
|
||||||
Override: true,
|
Override: true,
|
||||||
ReplicateDeletion: false,
|
ReplicateDeletion: false,
|
||||||
Speed: nil,
|
Speed: nil,
|
||||||
@@ -289,20 +307,6 @@ func (hOp *HarborOperator) SyncProjectExec(funcArgs []string) (bool, []string) {
|
|||||||
// 在源 Harbor 中创建复制策略
|
// 在源 Harbor 中创建复制策略
|
||||||
log.Info("[Harbor Sync Project ] - Start To Sync Project !")
|
log.Info("[Harbor Sync Project ] - Start To Sync Project !")
|
||||||
|
|
||||||
policies, _ := targetClient.ListReplicationPolicies(ctx)
|
|
||||||
if policies != nil {
|
|
||||||
for _, policy := range policies {
|
|
||||||
if policy.Name == octopusReplicationPolicy.Name {
|
|
||||||
err := targetClient.DeleteReplicationPolicyByID(ctx, policy.ID)
|
|
||||||
if err != nil {
|
|
||||||
return false, []string{
|
|
||||||
"[Harbor Sync Project ] - delete exists replication policy failed !",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
err = targetClient.NewReplicationPolicy(ctx, octopusReplicationPolicy.DestRegistry, octopusReplicationPolicy.SrcRegistry, octopusReplicationPolicy.Deletion, octopusReplicationPolicy.Override, octopusReplicationPolicy.Enabled, octopusReplicationPolicy.Filters, octopusReplicationPolicy.Trigger, octopusReplicationPolicy.DestNamespace, octopusReplicationPolicy.Name, octopusReplicationPolicy.Name)
|
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 {
|
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 !: %s\n", err.Error())
|
||||||
|
|||||||
Reference in New Issue
Block a user