Skip to content

Commit 5c1001d

Browse files
authored
feat: Add resource-policy accelerator_topology_mode (#5393)
1 parent 63f2766 commit 5c1001d

9 files changed

Lines changed: 46 additions & 18 deletions

File tree

modules/compute/gke-node-pool/README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -280,15 +280,15 @@ limitations under the License.
280280
|------|---------|
281281
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | = 1.12.2 |
282282
| <a name="requirement_google"></a> [google](#requirement\_google) | >= 7.2 |
283-
| <a name="requirement_google-beta"></a> [google-beta](#requirement\_google-beta) | >= 7.2 |
283+
| <a name="requirement_google-beta"></a> [google-beta](#requirement\_google-beta) | >= 7.24.0 |
284284
| <a name="requirement_null"></a> [null](#requirement\_null) | ~> 3.0 |
285285

286286
## Providers
287287

288288
| Name | Version |
289289
|------|---------|
290290
| <a name="provider_google"></a> [google](#provider\_google) | >= 7.2 |
291-
| <a name="provider_google-beta"></a> [google-beta](#provider\_google-beta) | >= 7.2 |
291+
| <a name="provider_google-beta"></a> [google-beta](#provider\_google-beta) | >= 7.24.0 |
292292
| <a name="provider_null"></a> [null](#provider\_null) | ~> 3.0 |
293293

294294
## Modules
@@ -316,6 +316,7 @@ limitations under the License.
316316

317317
| Name | Description | Type | Default | Required |
318318
|------|-------------|------|---------|:--------:|
319+
| <a name="input_accelerator_topology_mode"></a> [accelerator\_topology\_mode](#input\_accelerator\_topology\_mode) | The accelerator topology mode for the resource policy. It accepts values like `PROVISION_ONLY` or `AUTO_CONNECT`. Note that `enable_queued_provisioning` (DWS) is not supported when `accelerator_topology_mode` is set to `PROVISION_ONLY`. | `string` | `null` | no |
319320
| <a name="input_additional_networks"></a> [additional\_networks](#input\_additional\_networks) | Additional network interface details for GKE, if any. Providing additional networks adds additional node networks to the node pool | <pre>list(object({<br/> network = string<br/> subnetwork = string<br/> subnetwork_project = string<br/> network_ip = string<br/> nic_type = string<br/> stack_type = string<br/> queue_count = number<br/> access_config = list(object({<br/> nat_ip = string<br/> network_tier = string<br/> }))<br/> ipv6_access_config = list(object({<br/> network_tier = string<br/> }))<br/> alias_ip_range = list(object({<br/> ip_cidr_range = string<br/> subnetwork_range_name = string<br/> }))<br/> }))</pre> | `[]` | no |
320321
| <a name="input_auto_repair"></a> [auto\_repair](#input\_auto\_repair) | Whether the nodes will be automatically repaired. | `bool` | `true` | no |
321322
| <a name="input_auto_upgrade"></a> [auto\_upgrade](#input\_auto\_upgrade) | Whether the nodes will be automatically upgraded. | `bool` | `false` | no |
@@ -331,7 +332,7 @@ limitations under the License.
331332
| <a name="input_enable_gcfs"></a> [enable\_gcfs](#input\_enable\_gcfs) | Enable the Google Container Filesystem (GCFS). See [restrictions](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/container_cluster#gcfs_config). | `bool` | `false` | no |
332333
| <a name="input_enable_numa_aware_scheduling"></a> [enable\_numa\_aware\_scheduling](#input\_enable\_numa\_aware\_scheduling) | Enable [NUMA-aware](https://cloud.google.com/kubernetes-engine/distributed-cloud/bare-metal/docs/vm-runtime/numa) scheduling. | `bool` | `false` | no |
333334
| <a name="input_enable_private_nodes"></a> [enable\_private\_nodes](#input\_enable\_private\_nodes) | Whether nodes have internal IP addresses only. | `bool` | `true` | no |
334-
| <a name="input_enable_queued_provisioning"></a> [enable\_queued\_provisioning](#input\_enable\_queued\_provisioning) | If true, enables Dynamic Workload Scheduler and adds the cloud.google.com/gke-queued taint to the node pool. | `bool` | `false` | no |
335+
| <a name="input_enable_queued_provisioning"></a> [enable\_queued\_provisioning](#input\_enable\_queued\_provisioning) | If true, enables Dynamic Workload Scheduler and adds the cloud.google.com/gke-queued taint to the node pool. This cannot be true if `accelerator_topology_mode` is set to `PROVISION_ONLY`. | `bool` | `false` | no |
335336
| <a name="input_enable_secure_boot"></a> [enable\_secure\_boot](#input\_enable\_secure\_boot) | Enable secure boot for the nodes. Keep enabled unless custom kernel modules need to be loaded. See [here](https://cloud.google.com/compute/shielded-vm/docs/shielded-vm#secure-boot) for more info. | `bool` | `true` | no |
336337
| <a name="input_gke_version"></a> [gke\_version](#input\_gke\_version) | GKE version | `string` | n/a | yes |
337338
| <a name="input_guest_accelerator"></a> [guest\_accelerator](#input\_guest\_accelerator) | List of the type and count of accelerator cards attached to the instance. | <pre>list(object({<br/> type = optional(string)<br/> count = optional(number, 0)<br/> gpu_driver_installation_config = optional(object({<br/> gpu_driver_version = string<br/> }), { gpu_driver_version = "DEFAULT" })<br/> gpu_partition_size = optional(string)<br/> gpu_sharing_config = optional(object({<br/> gpu_sharing_strategy = string<br/> max_shared_clients_per_gpu = number<br/> }))<br/> }))</pre> | `[]` | no |

modules/compute/gke-node-pool/main.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,10 @@ resource "google_container_node_pool" "node_pool" {
417417
condition = var.spot == true ? (var.reservation_affinity.consume_reservation_type == "NO_RESERVATION") : true
418418
error_message = "Spot consumption option only works with reservation_affinity consume_reservation_type NO_RESERVATION."
419419
}
420+
precondition {
421+
condition = !(var.accelerator_topology_mode == "PROVISION_ONLY" && var.enable_queued_provisioning == true)
422+
error_message = "Custom accelerator topology modes (like PROVISION_ONLY) are incompatible with Dynamic Workload Scheduler (queued provisioning)."
423+
}
420424
}
421425
}
422426

modules/compute/gke-node-pool/variables.tf

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ variable "run_workload_script" {
450450
}
451451

452452
variable "enable_queued_provisioning" {
453-
description = "If true, enables Dynamic Workload Scheduler and adds the cloud.google.com/gke-queued taint to the node pool."
453+
description = "If true, enables Dynamic Workload Scheduler and adds the cloud.google.com/gke-queued taint to the node pool. This cannot be true if `accelerator_topology_mode` is set to `PROVISION_ONLY`."
454454
type = bool
455455
default = false
456456
}
@@ -525,3 +525,10 @@ variable "linux_node_config" {
525525
default = {}
526526
nullable = false
527527
}
528+
529+
530+
variable "accelerator_topology_mode" {
531+
description = "The accelerator topology mode for the resource policy. It accepts values like `PROVISION_ONLY` or `AUTO_CONNECT`. Note that `enable_queued_provisioning` (DWS) is not supported when `accelerator_topology_mode` is set to `PROVISION_ONLY`."
532+
type = string
533+
default = null
534+
}

modules/compute/gke-node-pool/versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ terraform {
2222
}
2323
google-beta = {
2424
source = "hashicorp/google-beta"
25-
version = ">= 7.2"
25+
version = ">= 7.24.0"
2626
}
2727
null = {
2828
source = "hashicorp/null"

modules/compute/resource-policy/README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ limitations under the License.
4343
| Name | Version |
4444
|------|---------|
4545
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | = 1.12.2 |
46-
| <a name="requirement_google-beta"></a> [google-beta](#requirement\_google-beta) | >= 6.29.0 |
46+
| <a name="requirement_google-beta"></a> [google-beta](#requirement\_google-beta) | >= 7.24.0 |
4747
| <a name="requirement_random"></a> [random](#requirement\_random) | ~> 3.0 |
4848
4949
## Providers
5050
5151
| Name | Version |
5252
|------|---------|
53-
| <a name="provider_google-beta"></a> [google-beta](#provider\_google-beta) | >= 6.29.0 |
53+
| <a name="provider_google-beta"></a> [google-beta](#provider\_google-beta) | >= 7.24.0 |
5454
| <a name="provider_random"></a> [random](#provider\_random) | ~> 3.0 |
5555
5656
## Modules
@@ -72,11 +72,12 @@ No modules.
7272
| <a name="input_name"></a> [name](#input\_name) | The resource policy's name. | `string` | n/a | yes |
7373
| <a name="input_project_id"></a> [project\_id](#input\_project\_id) | The project ID for the resource policy. | `string` | n/a | yes |
7474
| <a name="input_region"></a> [region](#input\_region) | The region for the the resource policy. | `string` | n/a | yes |
75-
| <a name="input_workload_policy"></a> [workload\_policy](#input\_workload\_policy) | Describes the workload policy | <pre>object({<br/> type = optional(string, null)<br/> max_topology_distance = optional(string, null)<br/> accelerator_topology = optional(string, null)<br/> })</pre> | <pre>{<br/> "accelerator_topology": null,<br/> "max_topology_distance": null,<br/> "type": null<br/>}</pre> | no |
75+
| <a name="input_workload_policy"></a> [workload\_policy](#input\_workload\_policy) | Describes the workload policy | <pre>object({<br/> type = optional(string, null)<br/> max_topology_distance = optional(string, null)<br/> accelerator_topology = optional(string, null)<br/> accelerator_topology_mode = optional(string, null)<br/> })</pre> | <pre>{<br/> "accelerator_topology": null,<br/> "accelerator_topology_mode": null,<br/> "max_topology_distance": null,<br/> "type": null<br/>}</pre> | no |
7676

7777
## Outputs
7878

7979
| Name | Description |
8080
|------|-------------|
81+
| <a name="output_accelerator_topology_mode"></a> [accelerator\_topology\_mode](#output\_accelerator\_topology\_mode) | The accelerator topology mode for the resource policy. |
8182
| <a name="output_placement_policy"></a> [placement\_policy](#output\_placement\_policy) | Group placement policy to use for placing VMs or GKE nodes placement. `COMPACT` is the only supported value for `type` currently. `name` is the name of the placement policy.<br/>It is assumed that the specified policy exists. To create a placement policy refer to https://cloud.google.com/sdk/gcloud/reference/compute/resource-policies/create/group-placement.<br/>Note: Placement policies have the [following](https://cloud.google.com/compute/docs/instances/placement-policies-overview#restrictions-compact-policies) restrictions.<br/>The value `tpu_topology` is only used for TPU node pools. The `gke-node-pool` module ensures it is configured appropriately for only TPUs during placement policy mapping. |
8283
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

modules/compute/resource-policy/main.tf

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ resource "google_compute_resource_policy" "policy" {
3131
for_each = var.workload_policy.type != null ? [1] : []
3232

3333
content {
34-
type = var.workload_policy.type
35-
max_topology_distance = var.workload_policy.max_topology_distance
36-
accelerator_topology = var.workload_policy.accelerator_topology
34+
type = var.workload_policy.type
35+
max_topology_distance = var.workload_policy.max_topology_distance
36+
accelerator_topology = var.workload_policy.accelerator_topology
37+
accelerator_topology_mode = var.workload_policy.accelerator_topology_mode
3738
}
3839
}
3940

@@ -45,4 +46,11 @@ resource "google_compute_resource_policy" "policy" {
4546
max_distance = var.group_placement_max_distance
4647
}
4748
}
49+
50+
lifecycle {
51+
precondition {
52+
condition = var.workload_policy.accelerator_topology_mode == null || (var.workload_policy.type != null && var.workload_policy.accelerator_topology != null)
53+
error_message = "Both workload_policy.type and workload_policy.accelerator_topology must be set when accelerator_topology_mode is specified."
54+
}
55+
}
4856
}

modules/compute/resource-policy/outputs.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,8 @@ output "placement_policy" {
2828
tpu_topology = (var.workload_policy.type != null) ? var.workload_policy.accelerator_topology : null
2929
}
3030
}
31+
32+
output "accelerator_topology_mode" {
33+
description = "The accelerator topology mode for the resource policy."
34+
value = var.workload_policy.accelerator_topology_mode
35+
}

modules/compute/resource-policy/variables.tf

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,16 @@ variable "group_placement_max_distance" {
5151
variable "workload_policy" {
5252
description = "Describes the workload policy"
5353
type = object({
54-
type = optional(string, null)
55-
max_topology_distance = optional(string, null)
56-
accelerator_topology = optional(string, null)
54+
type = optional(string, null)
55+
max_topology_distance = optional(string, null)
56+
accelerator_topology = optional(string, null)
57+
accelerator_topology_mode = optional(string, null)
5758
})
5859
default = {
59-
type = null
60-
max_topology_distance = null
61-
accelerator_topology = null
60+
type = null
61+
max_topology_distance = null
62+
accelerator_topology = null
63+
accelerator_topology_mode = null
6264
}
6365
nullable = false
6466
}

modules/compute/resource-policy/versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ terraform {
1818
required_providers {
1919
google-beta = {
2020
source = "hashicorp/google-beta"
21-
version = ">= 6.29.0"
21+
version = ">= 7.24.0"
2222
}
2323
random = {
2424
source = "hashicorp/random"

0 commit comments

Comments
 (0)