Skip to content

Commit fff0078

Browse files
authored
feat: Add support for TPUs on beta clusters (#810)
* Add TPU support in template files * Add autogenerated files for TPU support
1 parent bf4d0da commit fff0078

File tree

24 files changed

+89
-8
lines changed

24 files changed

+89
-8
lines changed

autogen/main/cluster.tf.tmpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ resource "google_container_cluster" "primary" {
110110
{% if beta_cluster %}
111111
enable_intranode_visibility = var.enable_intranode_visibility
112112
enable_kubernetes_alpha = var.enable_kubernetes_alpha
113+
enable_tpu = var.enable_tpu
113114

114115
dynamic "pod_security_policy_config" {
115116
for_each = var.enable_pod_security_policy ? [var.enable_pod_security_policy] : []

autogen/main/firewall.tf.tmpl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,20 @@ resource "google_compute_firewall" "intra_egress" {
3434
direction = "EGRESS"
3535

3636
target_tags = [local.cluster_network_tag]
37+
{% if beta_cluster %}
38+
destination_ranges = compact([
39+
local.cluster_endpoint_for_nodes,
40+
local.cluster_subnet_cidr,
41+
local.cluster_alias_ranges_cidr[var.ip_range_pods],
42+
google_container_cluster.primary.tpu_ipv4_cidr_block,
43+
])
44+
{% else %}
3745
destination_ranges = [
3846
local.cluster_endpoint_for_nodes,
3947
local.cluster_subnet_cidr,
4048
local.cluster_alias_ranges_cidr[var.ip_range_pods],
4149
]
50+
{% endif %}
4251

4352
# Allow all possible protocols
4453
allow { protocol = "tcp" }

autogen/main/outputs.tf.tmpl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,4 +178,9 @@ output "vertical_pod_autoscaling_enabled" {
178178
description = "Whether veritical pod autoscaling is enabled"
179179
value = local.cluster_vertical_pod_autoscaling_enabled
180180
}
181+
182+
output "tpu_ipv4_cidr_block" {
183+
description = "The IP range in CIDR notation used for the TPUs"
184+
value = var.enable_tpu ? google_container_cluster.primary.tpu_ipv4_cidr_block : null
185+
}
181186
{% endif %}

autogen/main/variables.tf.tmpl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,4 +600,10 @@ variable "notification_config_topic" {
600600
description = "The desired Pub/Sub topic to which notifications will be sent by GKE. Format is projects/{project}/topics/{topic}."
601601
default = ""
602602
}
603+
604+
variable "enable_tpu" {
605+
type = bool
606+
description = "Enable Cloud TPU resources in the cluster. WARNING: changing this after cluster creation is destructive!"
607+
default = false
608+
}
603609
{% endif %}

modules/beta-private-cluster-update-variant/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ Then perform the following commands on the root folder:
183183
| enable\_private\_nodes | (Beta) Whether nodes have internal IP addresses only | `bool` | `false` | no |
184184
| enable\_resource\_consumption\_export | Whether to enable resource consumption metering on this cluster. When enabled, a table will be created in the resource export BigQuery dataset to store resource consumption data. The resulting table can be joined with the resource usage table or with BigQuery billing export. | `bool` | `true` | no |
185185
| enable\_shielded\_nodes | Enable Shielded Nodes features on all nodes in this cluster | `bool` | `true` | no |
186+
| enable\_tpu | Enable Cloud TPU resources in the cluster. WARNING: changing this after cluster creation is destructive! | `bool` | `false` | no |
186187
| enable\_vertical\_pod\_autoscaling | Vertical Pod Autoscaling automatically adjusts the resources of pods controlled by it | `bool` | `false` | no |
187188
| firewall\_inbound\_ports | List of TCP ports for admission/webhook controllers | `list(string)` | <pre>[<br> "8443",<br> "9443",<br> "15017"<br>]</pre> | no |
188189
| firewall\_priority | Priority rule for firewall rules | `number` | `1000` | no |
@@ -272,6 +273,7 @@ Then perform the following commands on the root folder:
272273
| region | Cluster region |
273274
| release\_channel | The release channel of this cluster |
274275
| service\_account | The service account to default running nodes as if not overridden in `node_pools`. |
276+
| tpu\_ipv4\_cidr\_block | The IP range in CIDR notation used for the TPUs |
275277
| type | Cluster type (regional / zonal) |
276278
| vertical\_pod\_autoscaling\_enabled | Whether veritical pod autoscaling is enabled |
277279
| zones | List of zones in which the cluster resides |

modules/beta-private-cluster-update-variant/cluster.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ resource "google_container_cluster" "primary" {
9696
enable_binary_authorization = var.enable_binary_authorization
9797
enable_intranode_visibility = var.enable_intranode_visibility
9898
enable_kubernetes_alpha = var.enable_kubernetes_alpha
99+
enable_tpu = var.enable_tpu
99100

100101
dynamic "pod_security_policy_config" {
101102
for_each = var.enable_pod_security_policy ? [var.enable_pod_security_policy] : []

modules/beta-private-cluster-update-variant/firewall.tf

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,12 @@ resource "google_compute_firewall" "intra_egress" {
3434
direction = "EGRESS"
3535

3636
target_tags = [local.cluster_network_tag]
37-
destination_ranges = [
37+
destination_ranges = compact([
3838
local.cluster_endpoint_for_nodes,
3939
local.cluster_subnet_cidr,
4040
local.cluster_alias_ranges_cidr[var.ip_range_pods],
41-
]
41+
google_container_cluster.primary.tpu_ipv4_cidr_block,
42+
])
4243

4344
# Allow all possible protocols
4445
allow { protocol = "tcp" }

modules/beta-private-cluster-update-variant/outputs.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,3 +175,8 @@ output "vertical_pod_autoscaling_enabled" {
175175
description = "Whether veritical pod autoscaling is enabled"
176176
value = local.cluster_vertical_pod_autoscaling_enabled
177177
}
178+
179+
output "tpu_ipv4_cidr_block" {
180+
description = "The IP range in CIDR notation used for the TPUs"
181+
value = var.enable_tpu ? google_container_cluster.primary.tpu_ipv4_cidr_block : null
182+
}

modules/beta-private-cluster-update-variant/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,3 +579,9 @@ variable "notification_config_topic" {
579579
description = "The desired Pub/Sub topic to which notifications will be sent by GKE. Format is projects/{project}/topics/{topic}."
580580
default = ""
581581
}
582+
583+
variable "enable_tpu" {
584+
type = bool
585+
description = "Enable Cloud TPU resources in the cluster. WARNING: changing this after cluster creation is destructive!"
586+
default = false
587+
}

modules/beta-private-cluster/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ Then perform the following commands on the root folder:
161161
| enable\_private\_nodes | (Beta) Whether nodes have internal IP addresses only | `bool` | `false` | no |
162162
| enable\_resource\_consumption\_export | Whether to enable resource consumption metering on this cluster. When enabled, a table will be created in the resource export BigQuery dataset to store resource consumption data. The resulting table can be joined with the resource usage table or with BigQuery billing export. | `bool` | `true` | no |
163163
| enable\_shielded\_nodes | Enable Shielded Nodes features on all nodes in this cluster | `bool` | `true` | no |
164+
| enable\_tpu | Enable Cloud TPU resources in the cluster. WARNING: changing this after cluster creation is destructive! | `bool` | `false` | no |
164165
| enable\_vertical\_pod\_autoscaling | Vertical Pod Autoscaling automatically adjusts the resources of pods controlled by it | `bool` | `false` | no |
165166
| firewall\_inbound\_ports | List of TCP ports for admission/webhook controllers | `list(string)` | <pre>[<br> "8443",<br> "9443",<br> "15017"<br>]</pre> | no |
166167
| firewall\_priority | Priority rule for firewall rules | `number` | `1000` | no |
@@ -250,6 +251,7 @@ Then perform the following commands on the root folder:
250251
| region | Cluster region |
251252
| release\_channel | The release channel of this cluster |
252253
| service\_account | The service account to default running nodes as if not overridden in `node_pools`. |
254+
| tpu\_ipv4\_cidr\_block | The IP range in CIDR notation used for the TPUs |
253255
| type | Cluster type (regional / zonal) |
254256
| vertical\_pod\_autoscaling\_enabled | Whether veritical pod autoscaling is enabled |
255257
| zones | List of zones in which the cluster resides |

0 commit comments

Comments
 (0)