Skip to content

Commit 7a3932d

Browse files
Adding startup_cpu_boost field for cloud run v2 service. (#7732) (#14372)
Signed-off-by: Modular Magician <[email protected]>
1 parent 35b9da6 commit 7a3932d

File tree

4 files changed

+31
-0
lines changed

4 files changed

+31
-0
lines changed

.changelog/7732.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
cloudrunv2: added field `startupCpuBoost` to resource `service`
3+
```

google/resource_cloud_run_v2_service.go

+22
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,11 @@ If omitted, a port number will be chosen and passed to the container through the
303303
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`,
304304
Elem: &schema.Schema{Type: schema.TypeString},
305305
},
306+
"startup_cpu_boost": {
307+
Type: schema.TypeBool,
308+
Optional: true,
309+
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.`,
310+
},
306311
},
307312
},
308313
},
@@ -1618,6 +1623,8 @@ func flattenCloudRunV2ServiceTemplateContainersResources(v interface{}, d *schem
16181623
flattenCloudRunV2ServiceTemplateContainersResourcesLimits(original["limits"], d, config)
16191624
transformed["cpu_idle"] =
16201625
flattenCloudRunV2ServiceTemplateContainersResourcesCpuIdle(original["cpuIdle"], d, config)
1626+
transformed["startup_cpu_boost"] =
1627+
flattenCloudRunV2ServiceTemplateContainersResourcesStartupCpuBoost(original["startupCpuBoost"], d, config)
16211628
return []interface{}{transformed}
16221629
}
16231630
func flattenCloudRunV2ServiceTemplateContainersResourcesLimits(v interface{}, d *schema.ResourceData, config *Config) interface{} {
@@ -1628,6 +1635,10 @@ func flattenCloudRunV2ServiceTemplateContainersResourcesCpuIdle(v interface{}, d
16281635
return v
16291636
}
16301637

1638+
func flattenCloudRunV2ServiceTemplateContainersResourcesStartupCpuBoost(v interface{}, d *schema.ResourceData, config *Config) interface{} {
1639+
return v
1640+
}
1641+
16311642
func flattenCloudRunV2ServiceTemplateContainersPorts(v interface{}, d *schema.ResourceData, config *Config) interface{} {
16321643
if v == nil {
16331644
return v
@@ -3036,6 +3047,13 @@ func expandCloudRunV2ServiceTemplateContainersResources(v interface{}, d Terrafo
30363047
transformed["cpuIdle"] = transformedCpuIdle
30373048
}
30383049

3050+
transformedStartupCpuBoost, err := expandCloudRunV2ServiceTemplateContainersResourcesStartupCpuBoost(original["startup_cpu_boost"], d, config)
3051+
if err != nil {
3052+
return nil, err
3053+
} else if val := reflect.ValueOf(transformedStartupCpuBoost); val.IsValid() && !isEmptyValue(val) {
3054+
transformed["startupCpuBoost"] = transformedStartupCpuBoost
3055+
}
3056+
30393057
return transformed, nil
30403058
}
30413059

@@ -3054,6 +3072,10 @@ func expandCloudRunV2ServiceTemplateContainersResourcesCpuIdle(v interface{}, d
30543072
return v, nil
30553073
}
30563074

3075+
func expandCloudRunV2ServiceTemplateContainersResourcesStartupCpuBoost(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
3076+
return v, nil
3077+
}
3078+
30573079
func expandCloudRunV2ServiceTemplateContainersPorts(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
30583080
l := v.([]interface{})
30593081
req := make([]interface{}, 0, len(l))

google/resource_cloud_run_v2_service_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ resource "google_cloud_run_v2_service" "default" {
8989
}
9090
resources {
9191
cpu_idle = true
92+
startup_cpu_boost = true
9293
limits = {
9394
cpu = "4"
9495
memory = "2Gi"
@@ -157,6 +158,7 @@ resource "google_cloud_run_v2_service" "default" {
157158
}
158159
resources {
159160
cpu_idle = true
161+
startup_cpu_boost = false
160162
limits = {
161163
cpu = "2"
162164
memory = "8Gi"

website/docs/r/cloud_run_v2_service.html.markdown

+4
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,10 @@ The following arguments are supported:
473473
(Optional)
474474
Determines whether CPU should be throttled or not outside of requests.
475475

476+
* `startup_cpu_boost` -
477+
(Optional)
478+
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.
479+
476480
<a name="nested_ports"></a>The `ports` block supports:
477481

478482
* `name` -

0 commit comments

Comments
 (0)