Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Harbor config system project quota #367

Merged
merged 4 commits into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions client/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,18 @@ import (

func GetConfigSystem(d *schema.ResourceData) models.ConfigBodySystemPost {
var body models.ConfigBodySystemPost
storage := d.Get("storage_per_project").(int)
if storage > 0 {
storage *= 1073741824 // GB to Byte
}
body = models.ConfigBodySystemPost{
ProjectCreationRestriction: d.Get("project_creation_restriction").(string),
ReadOnly: d.Get("read_only").(bool),
ScannerSkipUpdatePulltime: d.Get("scanner_skip_update_pulltime").(bool),
RobotTokenDuration: d.Get("robot_token_expiration").(int),
QuotaPerProjectEnable: true,
RobotNamePrefix: d.Get("robot_name_prefix").(string),
StoragePerProject: storage,
}
log.Printf("[DEBUG] %+v\n ", body)
return body
Expand Down
3 changes: 3 additions & 0 deletions docs/resources/config_system.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ resource "harbor_config_system" "main" {
project_creation_restriction = "adminonly"
robot_token_expiration = 30
robot_name_prefix = "harbor@"
storage_per_project = 100
}
```

Expand All @@ -22,3 +23,5 @@ The following arguments are supported:

* **scanner_skip_update_pulltime** - (Optional) Whether or not to skip update pull time for scanner.
`NOTE: "scanner_skip_update_pulltime" can only be used with harbor version v2.8.0 and above`

* **storage_per_project** - (Optional) Default quota space per project in GIB. Default is -1 (unlimited).
2 changes: 1 addition & 1 deletion models/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ type ConfigBodySystemPost struct {
RobotTokenDuration int `json:"robot_token_duration,omitempty"`
QuotaPerProjectEnable bool `json:"quota_per_project_enable"`
RobotNamePrefix string `json:"robot_name_prefix,omitempty"`
StoragePerProject string `json:"storage_per_project,omitempty"`
StoragePerProject int `json:"storage_per_project,omitempty"`
ScannerSkipUpdatePulltime bool `json:"scanner_skip_update_pulltime"`
}

Expand Down
10 changes: 10 additions & 0 deletions provider/resource_config_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ func resourceConfigSystem() *schema.Resource {
Optional: true,
Default: false,
},
"storage_per_project": {
Type: schema.TypeInt,
Optional: true,
Default: -1,
},
},
Create: resourceConfigSystemCreate,
Read: resourceConfigSystemRead,
Expand Down Expand Up @@ -78,12 +83,17 @@ func resourceConfigSystemRead(d *schema.ResourceData, m interface{}) error {
if err != nil {
return fmt.Errorf("Error getting system configuration %s", err)
}
storage := jsonData.StoragePerProject.Value

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should accept the user input for storage quota in GB and then only convert it to bytes while making the API call?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I’m aware the api accept bytes. Did the converter to GB since we use it in other places as well which is an argument to DRY this part as well.

if storage > 0 {
storage /= 1073741824 // Byte to GB
}

d.Set("project_creation_restriction", jsonData.ProjectCreationRestriction.Value)
d.Set("read_only", jsonData.ReadOnly.Value)
d.Set("robot_token_expiration", jsonData.RobotTokenDuration.Value)
d.Set("robot_name_prefix", jsonData.RobotNamePrefix.Value)
d.Set("scanner_skip_update_pulltime", jsonData.ScannerSkipUpdatePulltime.Value)
d.Set("storage_per_project", storage)

d.SetId("configuration/system")
return nil
Expand Down
Loading