Skip to content

Commit

Permalink
feat(replication): Add copy_by_chunk
Browse files Browse the repository at this point in the history
Add copy_by_chunk option

Signed-off-by: Paweł Kalemba <pawel.kalemba@getresponse.com>
  • Loading branch information
pkalemba committed May 24, 2024
1 parent bcd459a commit 37b787f
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 5 deletions.
1 change: 1 addition & 0 deletions client/replication.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func GetReplicationBody(d *schema.ResourceData) models.ReplicationBody {
Deletion: d.Get("deletion").(bool),
DestNamespace: d.Get("dest_namespace").(string),
DestNamespaceReplace: d.Get("dest_namespace_replace").(int),
CopyByChunk: d.Get("copy_by_chunk").(bool),
Speed: d.Get("speed").(int),
}

Expand Down
1 change: 1 addition & 0 deletions docs/resources/replication.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ resource "harbor_replication" "alpine" {
- `description` (String) Description of the replication policy.
- `dest_namespace` (String) Specify the destination namespace. if empty, the resource will be put under the same namespace as the source.
- `dest_namespace_replace` (Number) Specify the destination namespace flattening policy. Integers from `-1` to `3` are valid values in the harbor API. A value of `-1` will 'Flatten All Levels', `0` means 'No Flattening', `1` 'Flatten 1 Level', `2` 'Flatten 2 Levels', `3` 'Flatten 3 Levels' (Default: `-1`, see [Replication Rules](https://goharbor.io/docs/latest/administration/configuring-replication/create-replication-rules/) for more details)
- `copy_by_chunk` (Boolean) Specify whether to enable the artifact blobs copied by chunks. (Default: `false`)
- `enabled` (Boolean) Specify whether the replication is enabled. (Default: `true`)
- `execute_on_changed` (Boolean) Specify whether to execute the replication rule if new or modified. (Default: `false`)
- `filters` (Block Set) (see [below for nested schema](#nestedblock--filters))
Expand Down
11 changes: 6 additions & 5 deletions models/replications.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ type ReplicationBody struct {
Cron string `json:"cron,omitempty"`
} `json:"trigger_settings,omitempty"`
} `json:"trigger,omitempty"`
Enabled bool `json:"enabled"`
Deletion bool `json:"deletion,omitempty"`
Override bool `json:"override,omitempty"`
Filters []ReplicationFilters `json:"filters,omitempty"`
Speed int `json:"speed,omitempty"`
Enabled bool `json:"enabled"`
Deletion bool `json:"deletion,omitempty"`
Override bool `json:"override,omitempty"`
CopyByChunk bool `json:"copy_by_chunk,omitempty"`
Filters []ReplicationFilters `json:"filters,omitempty"`
Speed int `json:"speed,omitempty"`
}

type ReplicationFilters struct {
Expand Down
6 changes: 6 additions & 0 deletions provider/resource_replication.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ func resourceReplication() *schema.Resource {
Optional: true,
Default: true,
},
"copy_by_chunk": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
"filters": {
Type: schema.TypeSet,
Optional: true,
Expand Down Expand Up @@ -201,6 +206,7 @@ func resourceReplicationRead(d *schema.ResourceData, m interface{}) error {
d.Set("override", jsonDataReplication.Override)
d.Set("dest_namespace", jsonDataReplication.DestNamespace)
d.Set("dest_namespace_replace", jsonDataReplication.DestNamespaceReplace)
d.Set("copy_by_chunk",jsonDataReplication.CopyByChunk)

return nil
}
Expand Down
21 changes: 21 additions & 0 deletions provider/resource_replication_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,24 @@ func testReplicationPolicyDestinationNamespaceWithReplaceCount(scheduleType stri
}
`, endpoint, scheduleType, destNamepace)
}
func testReplicationPolicyWithCopyByChunk(scheduleType string, destNamepace int) string {
// endpoint := os.Getenv("HARBOR_REPLICATION_ENDPOINT")
endpoint := "https://hub.docker.com"
return fmt.Sprintf(`
resource "harbor_registry" "main" {
provider_name = "docker-hub"
name = "docker-hub-test-rep-pol"
endpoint_url = "%s"
}
resource "harbor_replication" "pull" {
name = "test_pull"
action = "pull"
registry_id = harbor_registry.main.registry_id
schedule = "%s"
dest_namespace = "nobody_cares"
dest_namespace_replace = "%d"
copy_by_chunk = "true"
}
`, endpoint, scheduleType, destNamepace)
}
1 change: 1 addition & 0 deletions templates/resources/replication.md.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ For example, the {{ .SchemaMarkdown }} template can be used to replace manual sc
- `description` (String) Description of the replication policy.
- `dest_namespace` (String) Specify the destination namespace. if empty, the resource will be put under the same namespace as the source.
- `dest_namespace_replace` (Number) Specify the destination namespace flattening policy. Integers from `-1` to `3` are valid values in the harbor API. A value of `-1` will 'Flatten All Levels', `0` means 'No Flattening', `1` 'Flatten 1 Level', `2` 'Flatten 2 Levels', `3` 'Flatten 3 Levels' (Default: `-1`, see [Replication Rules](https://goharbor.io/docs/latest/administration/configuring-replication/create-replication-rules/) for more details)
- `copy_by_chunk` (Boolean) Specify whether to enable the artifact blobs copied by chunks. (Default: `false`)
- `enabled` (Boolean) Specify whether the replication is enabled. (Default: `true`)
- `execute_on_changed` (Boolean) Specify whether to execute the replication rule if new or modified. (Default: `false`)
- `filters` (Block Set) (see [below for nested schema](#nestedblock--filters))
Expand Down

0 comments on commit 37b787f

Please sign in to comment.