Skip to content

Commit

Permalink
fixes #419 : harbor_garbage_collection : add support for workers (#421)
Browse files Browse the repository at this point in the history
Signed-off-by: flbla <[email protected]>
  • Loading branch information
flbla authored Mar 26, 2024
1 parent 33ad1aa commit ac02d18
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 4 deletions.
1 change: 1 addition & 0 deletions client/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func GetSystemBoby(d *schema.ResourceData, scheduleType string) models.SystemBod
body.Schedule.Cron = CronStr
if scheduleType == "gc" {
body.Parameters.DeleteUntagged = d.Get("delete_untagged").(bool)
body.Parameters.Workers = d.Get("workers").(int)
} else if scheduleType == "purgeaudit" {
body.Parameters.AuditRetentionHour = d.Get("audit_retention_hour").(int)
body.Parameters.IncludeOperations = d.Get("include_operations").(string)
Expand Down
6 changes: 4 additions & 2 deletions docs/resources/garbage_collection.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ description: |-

```terraform
resource "harbor_garbage_collection" "main" {
schedule = "Daily"
delete_untagged = true
schedule = "Daily"
delete_untagged = true
workers = 1
}
```

Expand All @@ -28,6 +29,7 @@ resource "harbor_garbage_collection" "main" {
### Optional

- `delete_untagged` (Boolean) Allow garbage collection on untagged artifacts.
- `workers` (Number) Number of workers to run the garbage collection, value must be between 1 and 5.

### Read-Only

Expand Down
5 changes: 3 additions & 2 deletions examples/resources/harbor_garbage_collection/resource.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
resource "harbor_garbage_collection" "main" {
schedule = "Daily"
delete_untagged = true
schedule = "Daily"
delete_untagged = true
workers = 1
}
2 changes: 2 additions & 0 deletions models/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type JobParameters struct {
DeleteUntagged bool `json:"delete_untagged,omitempty"`
AuditRetentionHour int `json:"audit_retention_hour,omitempty"`
IncludeOperations string `json:"include_operations,omitempty"`
Workers int `json:"workers,omitempty"`
}

type SystemBody struct {
Expand All @@ -31,6 +32,7 @@ type SystemBody struct {
DeleteUntagged bool `json:"delete_untagged,omitempty"`
AuditRetentionHour int `json:"audit_retention_hour,omitempty"`
IncludeOperations string `json:"include_operations,omitempty"`
Workers int `json:"workers,omitempty"`
AdditionalProp1 bool `json:"additionalProp1,omitempty"`
AdditionalProp2 bool `json:"additionalProp2,omitempty"`
AdditionalProp3 bool `json:"additionalProp3,omitempty"`
Expand Down
13 changes: 13 additions & 0 deletions provider/resource_garbage_collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@ func resourceGC() *schema.Resource {
Type: schema.TypeBool,
Optional: true,
},
"workers": {
Type: schema.TypeInt,
Optional: true,
Default: 1,
ValidateFunc: func(i interface{}, k string) (ws []string, errors []error) {
value := i.(int)
if value < 1 || value > 5 {
errors = append(errors, fmt.Errorf("GC workers must be between 1 and 5"))
}
return
},
},
},
Create: resourceGCCreate,
Read: resourceGCRead,
Expand Down Expand Up @@ -69,6 +81,7 @@ func resourceGCRead(d *schema.ResourceData, m interface{}) error {
d.Set("schedule", jsonData.Schedule.Type)
}
d.Set("delete_untagged", jsonJobParameters.DeleteUntagged)
d.Set("workers", jsonJobParameters.Workers)
return nil
}

Expand Down
1 change: 1 addition & 0 deletions provider/resource_garbage_collection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ func testAccCheckGCUpdate() string {
resource "harbor_garbage_collection" "main" {
schedule = "Hourly"
delete_untagged = true
workers = 2
}
`)
}
1 change: 1 addition & 0 deletions templates/resources/garbage_collection.md.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ For example, the {{ .SchemaMarkdown }} template can be used to replace manual sc
### Optional

- `delete_untagged` (Boolean) Allow garbage collection on untagged artifacts.
- `workers` (Number) Number of workers to run the garbage collection, value must be between 1 and 5.

### Read-Only

Expand Down

0 comments on commit ac02d18

Please sign in to comment.