Skip to content

Commit c864135

Browse files
Adding changes to tpu-definition and gke-node-pool for workload_policy
1 parent 3c0e259 commit c864135

File tree

4 files changed

+10
-8
lines changed

4 files changed

+10
-8
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ resource "google_container_node_pool" "node_pool" {
113113
content {
114114
type = var.placement_policy.type
115115
policy_name = var.placement_policy.name
116-
tpu_topology = var.placement_policy.tpu_topology
116+
tpu_topology = module.tpu.is_tpu ? var.placement_policy.tpu_topology : null
117117
}
118118
}
119119

modules/compute/resource-policy/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,5 +78,5 @@ No modules.
7878

7979
| Name | Description |
8080
|------|-------------|
81-
| <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. |
81+
| <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. |
8282
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

modules/compute/resource-policy/outputs.tf

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@ output "placement_policy" {
1919
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.
2020
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.
2121
Note: Placement policies have the [following](https://cloud.google.com/compute/docs/instances/placement-policies-overview#restrictions-compact-policies) restrictions.
22+
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.
2223
EOT
2324

2425
value = {
25-
type = (var.group_placement_max_distance > 0 || var.workload_policy.type != null) ? "COMPACT" : null
26-
name = (var.group_placement_max_distance > 0 || var.workload_policy.type != null) ? local.name : null
26+
type = (var.group_placement_max_distance > 0 || var.workload_policy.type != null) ? "COMPACT" : null
27+
name = (var.group_placement_max_distance > 0 || var.workload_policy.type != null) ? local.name : null
28+
tpu_topology = (var.workload_policy.type != null) ? var.workload_policy.accelerator_topology : null
2729
}
2830
}

modules/internal/tpu-definition/main.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@
1515
*/
1616

1717
locals {
18-
# Safely check for the existence of a TPU topology.
19-
is_tpu = try(var.placement_policy.tpu_topology, null) != null && try(var.placement_policy.tpu_topology, "") != ""
18+
# Determine if this is a TPU node pool by checking if the machine_type exists in our authoritative map of TPU machine types.
19+
is_tpu = contains(keys(local.tpu_chip_count_map), var.machine_type)
2020

2121
tpu_taint = local.is_tpu ? [{
2222
key = "google.com/tpu"
2323
value = "present"
2424
effect = "NO_SCHEDULE"
2525
}] : []
2626

27-
# Exhaustive map of machine prefixes to GKE accelerator labels.
27+
# Map of machine prefixes to GKE accelerator labels.
2828
tpu_accelerator_map = {
2929
"ct4p" = "tpu-v4-podslice" # TPU v4
3030
"ct5lp" = "tpu-v5-lite-podslice" # TPU v5e
@@ -33,7 +33,7 @@ locals {
3333
}
3434

3535
# Map specific GCE machine types to the number of TPU chips per node (VM).
36-
# Based on public Google Cloud TPU documentation.
36+
# The machine-type map must be updated to reflect new TPU releases with reference to public documentation: https://docs.cloud.google.com/tpu/docs/intro-to-tpu
3737
tpu_chip_count_map = {
3838
# v4 - ct4p
3939
"ct4p-hightpu-4t" = 4

0 commit comments

Comments
 (0)