Skip to content

Commit

Permalink
Adding startup_cpu_boost field for cloud run v2 service. (#7732) (#14372
Browse files Browse the repository at this point in the history
)

Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician committed Apr 20, 2023
1 parent 35b9da6 commit 7a3932d
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
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/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/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

0 comments on commit 7a3932d

Please sign in to comment.