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

Adding startup_cpu_boost field for cloud run v2 service. #5521

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
3 changes: 3 additions & 0 deletions .changelog/7732.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
cloudrunv2: added field `startupCpuBoost` to resource `service`
```
22 changes: 22 additions & 0 deletions google-beta/resource_cloud_run_v2_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,11 @@ If omitted, a port number will be chosen and passed to the container through the
Description: `Only memory and CPU are supported. Note: The only supported values for CPU are '1', '2', '4', and '8'. Setting 4 CPU requires at least 2Gi of memory. The values of the map is string form of the 'quantity' k8s type: https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/apimachinery/pkg/api/resource/quantity.go`,
Elem: &schema.Schema{Type: schema.TypeString},
},
"startup_cpu_boost": {
Type: schema.TypeBool,
Optional: true,
Description: `Determines whether CPU should be boosted on startup of a new container instance above the requested CPU threshold, this can help reduce cold-start latency.`,
},
},
},
},
Expand Down Expand Up @@ -1618,6 +1623,8 @@ func flattenCloudRunV2ServiceTemplateContainersResources(v interface{}, d *schem
flattenCloudRunV2ServiceTemplateContainersResourcesLimits(original["limits"], d, config)
transformed["cpu_idle"] =
flattenCloudRunV2ServiceTemplateContainersResourcesCpuIdle(original["cpuIdle"], d, config)
transformed["startup_cpu_boost"] =
flattenCloudRunV2ServiceTemplateContainersResourcesStartupCpuBoost(original["startupCpuBoost"], d, config)
return []interface{}{transformed}
}
func flattenCloudRunV2ServiceTemplateContainersResourcesLimits(v interface{}, d *schema.ResourceData, config *Config) interface{} {
Expand All @@ -1628,6 +1635,10 @@ func flattenCloudRunV2ServiceTemplateContainersResourcesCpuIdle(v interface{}, d
return v
}

func flattenCloudRunV2ServiceTemplateContainersResourcesStartupCpuBoost(v interface{}, d *schema.ResourceData, config *Config) interface{} {
return v
}

func flattenCloudRunV2ServiceTemplateContainersPorts(v interface{}, d *schema.ResourceData, config *Config) interface{} {
if v == nil {
return v
Expand Down Expand Up @@ -3036,6 +3047,13 @@ func expandCloudRunV2ServiceTemplateContainersResources(v interface{}, d Terrafo
transformed["cpuIdle"] = transformedCpuIdle
}

transformedStartupCpuBoost, err := expandCloudRunV2ServiceTemplateContainersResourcesStartupCpuBoost(original["startup_cpu_boost"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedStartupCpuBoost); val.IsValid() && !isEmptyValue(val) {
transformed["startupCpuBoost"] = transformedStartupCpuBoost
}

return transformed, nil
}

Expand All @@ -3054,6 +3072,10 @@ func expandCloudRunV2ServiceTemplateContainersResourcesCpuIdle(v interface{}, d
return v, nil
}

func expandCloudRunV2ServiceTemplateContainersResourcesStartupCpuBoost(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}

func expandCloudRunV2ServiceTemplateContainersPorts(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
l := v.([]interface{})
req := make([]interface{}, 0, len(l))
Expand Down
2 changes: 2 additions & 0 deletions google-beta/resource_cloud_run_v2_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ resource "google_cloud_run_v2_service" "default" {
}
resources {
cpu_idle = true
startup_cpu_boost = true
limits = {
cpu = "4"
memory = "2Gi"
Expand Down Expand Up @@ -157,6 +158,7 @@ resource "google_cloud_run_v2_service" "default" {
}
resources {
cpu_idle = true
startup_cpu_boost = false
limits = {
cpu = "2"
memory = "8Gi"
Expand Down
4 changes: 4 additions & 0 deletions website/docs/r/cloud_run_v2_service.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,10 @@ The following arguments are supported:
(Optional)
Determines whether CPU should be throttled or not outside of requests.

* `startup_cpu_boost` -
(Optional)
Determines whether CPU should be boosted on startup of a new container instance above the requested CPU threshold, this can help reduce cold-start latency.

<a name="nested_ports"></a>The `ports` block supports:

* `name` -
Expand Down