From 7cc06267bb8654194eb0031772b0345863030457 Mon Sep 17 00:00:00 2001 From: Ilia Lazebnik Date: Thu, 29 Aug 2024 16:52:39 -0400 Subject: [PATCH] feat: support reservation affinity (#2010) Signed-off-by: drfaust92 Co-authored-by: Andrew Peabody --- README.md | 3 +++ autogen/main/README.md | 3 +++ autogen/main/cluster.tf.tmpl | 9 +++++++-- cluster.tf | 12 ++++++++---- .../beta-private-cluster-update-variant/README.md | 3 +++ .../cluster.tf | 15 +++++++++++---- modules/beta-private-cluster/README.md | 3 +++ modules/beta-private-cluster/cluster.tf | 12 ++++++++---- .../beta-public-cluster-update-variant/README.md | 3 +++ .../beta-public-cluster-update-variant/cluster.tf | 15 +++++++++++---- modules/beta-public-cluster/README.md | 3 +++ modules/beta-public-cluster/cluster.tf | 12 ++++++++---- modules/private-cluster-update-variant/README.md | 3 +++ modules/private-cluster-update-variant/cluster.tf | 15 +++++++++++---- modules/private-cluster/README.md | 3 +++ modules/private-cluster/cluster.tf | 12 ++++++++---- 16 files changed, 96 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index 53b69a88b9..71b21d0060 100644 --- a/README.md +++ b/README.md @@ -358,6 +358,9 @@ The node_pools variable takes the following parameters: | queued_provisioning | Makes nodes obtainable through the ProvisioningRequest API exclusively. | | Optional | | gpu_sharing_strategy | The type of GPU sharing strategy to enable on the GPU node. Accepted values are: "TIME_SHARING" and "MPS". | | Optional | | max_shared_clients_per_gpu | The maximum number of containers that can share a GPU. | | Optional | +| consume_reservation_type | The type of reservation consumption. Accepted values are: "UNSPECIFIED": Default value (should not be specified). "NO_RESERVATION": Do not consume from any reserved capacity, "ANY_RESERVATION": Consume any reservation available, "SPECIFIC_RESERVATION": Must consume from a specific reservation. Must specify key value fields for specifying the reservations. | | Optional | +| reservation_affinity_key | The label key of a reservation resource. To target a SPECIFIC_RESERVATION by name, specify "compute.googleapis.com/reservation-name" as the key and specify the name of your reservation as its value. | | Optional | +| reservation_affinity_values | The list of label values of reservation resources. For example: the name of the specific reservation when using a key of "compute.googleapis.com/reservation-name". This should be passed as comma separated string. | | Optional | ## windows_node_pools variable The windows_node_pools variable takes the same parameters as [node_pools](#node\_pools-variable) but is reserved for provisioning Windows based node pools only. This variable is introduced to satisfy a [specific requirement](https://cloud.google.com/kubernetes-engine/docs/how-to/creating-a-cluster-windows#create_a_cluster_and_node_pools) for the presence of at least one linux based node pool in the cluster before a windows based node pool can be created. diff --git a/autogen/main/README.md b/autogen/main/README.md index 89b4864b62..9031338c76 100644 --- a/autogen/main/README.md +++ b/autogen/main/README.md @@ -261,6 +261,9 @@ The node_pools variable takes the following parameters: | queued_provisioning | Makes nodes obtainable through the ProvisioningRequest API exclusively. | | Optional | | gpu_sharing_strategy | The type of GPU sharing strategy to enable on the GPU node. Accepted values are: "TIME_SHARING" and "MPS". | | Optional | | max_shared_clients_per_gpu | The maximum number of containers that can share a GPU. | | Optional | +| consume_reservation_type | The type of reservation consumption. Accepted values are: "UNSPECIFIED": Default value (should not be specified). "NO_RESERVATION": Do not consume from any reserved capacity, "ANY_RESERVATION": Consume any reservation available, "SPECIFIC_RESERVATION": Must consume from a specific reservation. Must specify key value fields for specifying the reservations. | | Optional | +| reservation_affinity_key | The label key of a reservation resource. To target a SPECIFIC_RESERVATION by name, specify "compute.googleapis.com/reservation-name" as the key and specify the name of your reservation as its value. | | Optional | +| reservation_affinity_values | The list of label values of reservation resources. For example: the name of the specific reservation when using a key of "compute.googleapis.com/reservation-name". This should be passed as comma separated string. | | Optional | ## windows_node_pools variable The windows_node_pools variable takes the same parameters as [node_pools](#node\_pools-variable) but is reserved for provisioning Windows based node pools only. This variable is introduced to satisfy a [specific requirement](https://cloud.google.com/kubernetes-engine/docs/how-to/creating-a-cluster-windows#create_a_cluster_and_node_pools) for the presence of at least one linux based node pool in the cluster before a windows based node pool can be created. diff --git a/autogen/main/cluster.tf.tmpl b/autogen/main/cluster.tf.tmpl index b1a305ccf4..175065a9a8 100644 --- a/autogen/main/cluster.tf.tmpl +++ b/autogen/main/cluster.tf.tmpl @@ -718,6 +718,9 @@ locals { "boot_disk_kms_key", "queued_provisioning", "enable_confidential_storage", + "consume_reservation_type", + "reservation_affinity_key", + "reservation_affinity_values" ] } @@ -896,9 +899,11 @@ resource "google_container_node_pool" "windows_pools" { } } dynamic "reservation_affinity" { - for_each = lookup(each.value, "queued_provisioning", false) ? [true] : [] + for_each = lookup(each.value, "queued_provisioning", false) || lookup(each.value, "consume_reservation_type", "") != "" ? [each.value] : [] content { - consume_reservation_type = "NO_RESERVATION" + consume_reservation_type = lookup(reservation_affinity.value, "queued_provisioning", false) ? "NO_RESERVATION" : lookup(reservation_affinity.value, "consume_reservation_type", null) + key = lookup(reservation_affinity.value, "reservation_affinity_key", null) + values = lookup(reservation_affinity.value, "reservation_affinity_values", null) == null ? null : [for s in split(",", lookup(reservation_affinity.value, "reservation_affinity_values", null)) : trimspace(s)] } } labels = merge( diff --git a/cluster.tf b/cluster.tf index d8fc73abc8..bf913825d4 100644 --- a/cluster.tf +++ b/cluster.tf @@ -605,9 +605,11 @@ resource "google_container_node_pool" "pools" { } } dynamic "reservation_affinity" { - for_each = lookup(each.value, "queued_provisioning", false) ? [true] : [] + for_each = lookup(each.value, "queued_provisioning", false) || lookup(each.value, "consume_reservation_type", "") != "" ? [each.value] : [] content { - consume_reservation_type = "NO_RESERVATION" + consume_reservation_type = lookup(reservation_affinity.value, "queued_provisioning", false) ? "NO_RESERVATION" : lookup(reservation_affinity.value, "consume_reservation_type", null) + key = lookup(reservation_affinity.value, "reservation_affinity_key", null) + values = lookup(reservation_affinity.value, "reservation_affinity_values", null) == null ? null : [for s in split(",", lookup(reservation_affinity.value, "reservation_affinity_values", null)) : trimspace(s)] } } labels = merge( @@ -885,9 +887,11 @@ resource "google_container_node_pool" "windows_pools" { } } dynamic "reservation_affinity" { - for_each = lookup(each.value, "queued_provisioning", false) ? [true] : [] + for_each = lookup(each.value, "queued_provisioning", false) || lookup(each.value, "consume_reservation_type", "") != "" ? [each.value] : [] content { - consume_reservation_type = "NO_RESERVATION" + consume_reservation_type = lookup(reservation_affinity.value, "queued_provisioning", false) ? "NO_RESERVATION" : lookup(reservation_affinity.value, "consume_reservation_type", null) + key = lookup(reservation_affinity.value, "reservation_affinity_key", null) + values = lookup(reservation_affinity.value, "reservation_affinity_values", null) == null ? null : [for s in split(",", lookup(reservation_affinity.value, "reservation_affinity_values", null)) : trimspace(s)] } } labels = merge( diff --git a/modules/beta-private-cluster-update-variant/README.md b/modules/beta-private-cluster-update-variant/README.md index 291c5ac550..7b39d3fdf1 100644 --- a/modules/beta-private-cluster-update-variant/README.md +++ b/modules/beta-private-cluster-update-variant/README.md @@ -417,6 +417,9 @@ The node_pools variable takes the following parameters: | queued_provisioning | Makes nodes obtainable through the ProvisioningRequest API exclusively. | | Optional | | gpu_sharing_strategy | The type of GPU sharing strategy to enable on the GPU node. Accepted values are: "TIME_SHARING" and "MPS". | | Optional | | max_shared_clients_per_gpu | The maximum number of containers that can share a GPU. | | Optional | +| consume_reservation_type | The type of reservation consumption. Accepted values are: "UNSPECIFIED": Default value (should not be specified). "NO_RESERVATION": Do not consume from any reserved capacity, "ANY_RESERVATION": Consume any reservation available, "SPECIFIC_RESERVATION": Must consume from a specific reservation. Must specify key value fields for specifying the reservations. | | Optional | +| reservation_affinity_key | The label key of a reservation resource. To target a SPECIFIC_RESERVATION by name, specify "compute.googleapis.com/reservation-name" as the key and specify the name of your reservation as its value. | | Optional | +| reservation_affinity_values | The list of label values of reservation resources. For example: the name of the specific reservation when using a key of "compute.googleapis.com/reservation-name". This should be passed as comma separated string. | | Optional | ## windows_node_pools variable The windows_node_pools variable takes the same parameters as [node_pools](#node\_pools-variable) but is reserved for provisioning Windows based node pools only. This variable is introduced to satisfy a [specific requirement](https://cloud.google.com/kubernetes-engine/docs/how-to/creating-a-cluster-windows#create_a_cluster_and_node_pools) for the presence of at least one linux based node pool in the cluster before a windows based node pool can be created. diff --git a/modules/beta-private-cluster-update-variant/cluster.tf b/modules/beta-private-cluster-update-variant/cluster.tf index d3401ca09c..a03e04ba55 100644 --- a/modules/beta-private-cluster-update-variant/cluster.tf +++ b/modules/beta-private-cluster-update-variant/cluster.tf @@ -614,6 +614,9 @@ locals { "boot_disk_kms_key", "queued_provisioning", "enable_confidential_storage", + "consume_reservation_type", + "reservation_affinity_key", + "reservation_affinity_values" ] } @@ -769,9 +772,11 @@ resource "google_container_node_pool" "pools" { } } dynamic "reservation_affinity" { - for_each = lookup(each.value, "queued_provisioning", false) ? [true] : [] + for_each = lookup(each.value, "queued_provisioning", false) || lookup(each.value, "consume_reservation_type", "") != "" ? [each.value] : [] content { - consume_reservation_type = "NO_RESERVATION" + consume_reservation_type = lookup(reservation_affinity.value, "queued_provisioning", false) ? "NO_RESERVATION" : lookup(reservation_affinity.value, "consume_reservation_type", null) + key = lookup(reservation_affinity.value, "reservation_affinity_key", null) + values = lookup(reservation_affinity.value, "reservation_affinity_values", null) == null ? null : [for s in split(",", lookup(reservation_affinity.value, "reservation_affinity_values", null)) : trimspace(s)] } } labels = merge( @@ -1063,9 +1068,11 @@ resource "google_container_node_pool" "windows_pools" { } } dynamic "reservation_affinity" { - for_each = lookup(each.value, "queued_provisioning", false) ? [true] : [] + for_each = lookup(each.value, "queued_provisioning", false) || lookup(each.value, "consume_reservation_type", "") != "" ? [each.value] : [] content { - consume_reservation_type = "NO_RESERVATION" + consume_reservation_type = lookup(reservation_affinity.value, "queued_provisioning", false) ? "NO_RESERVATION" : lookup(reservation_affinity.value, "consume_reservation_type", null) + key = lookup(reservation_affinity.value, "reservation_affinity_key", null) + values = lookup(reservation_affinity.value, "reservation_affinity_values", null) == null ? null : [for s in split(",", lookup(reservation_affinity.value, "reservation_affinity_values", null)) : trimspace(s)] } } labels = merge( diff --git a/modules/beta-private-cluster/README.md b/modules/beta-private-cluster/README.md index 5db9fc0ddb..f10cc3e03b 100644 --- a/modules/beta-private-cluster/README.md +++ b/modules/beta-private-cluster/README.md @@ -395,6 +395,9 @@ The node_pools variable takes the following parameters: | queued_provisioning | Makes nodes obtainable through the ProvisioningRequest API exclusively. | | Optional | | gpu_sharing_strategy | The type of GPU sharing strategy to enable on the GPU node. Accepted values are: "TIME_SHARING" and "MPS". | | Optional | | max_shared_clients_per_gpu | The maximum number of containers that can share a GPU. | | Optional | +| consume_reservation_type | The type of reservation consumption. Accepted values are: "UNSPECIFIED": Default value (should not be specified). "NO_RESERVATION": Do not consume from any reserved capacity, "ANY_RESERVATION": Consume any reservation available, "SPECIFIC_RESERVATION": Must consume from a specific reservation. Must specify key value fields for specifying the reservations. | | Optional | +| reservation_affinity_key | The label key of a reservation resource. To target a SPECIFIC_RESERVATION by name, specify "compute.googleapis.com/reservation-name" as the key and specify the name of your reservation as its value. | | Optional | +| reservation_affinity_values | The list of label values of reservation resources. For example: the name of the specific reservation when using a key of "compute.googleapis.com/reservation-name". This should be passed as comma separated string. | | Optional | ## windows_node_pools variable The windows_node_pools variable takes the same parameters as [node_pools](#node\_pools-variable) but is reserved for provisioning Windows based node pools only. This variable is introduced to satisfy a [specific requirement](https://cloud.google.com/kubernetes-engine/docs/how-to/creating-a-cluster-windows#create_a_cluster_and_node_pools) for the presence of at least one linux based node pool in the cluster before a windows based node pool can be created. diff --git a/modules/beta-private-cluster/cluster.tf b/modules/beta-private-cluster/cluster.tf index f073f632be..0ccdc462ae 100644 --- a/modules/beta-private-cluster/cluster.tf +++ b/modules/beta-private-cluster/cluster.tf @@ -690,9 +690,11 @@ resource "google_container_node_pool" "pools" { } } dynamic "reservation_affinity" { - for_each = lookup(each.value, "queued_provisioning", false) ? [true] : [] + for_each = lookup(each.value, "queued_provisioning", false) || lookup(each.value, "consume_reservation_type", "") != "" ? [each.value] : [] content { - consume_reservation_type = "NO_RESERVATION" + consume_reservation_type = lookup(reservation_affinity.value, "queued_provisioning", false) ? "NO_RESERVATION" : lookup(reservation_affinity.value, "consume_reservation_type", null) + key = lookup(reservation_affinity.value, "reservation_affinity_key", null) + values = lookup(reservation_affinity.value, "reservation_affinity_values", null) == null ? null : [for s in split(",", lookup(reservation_affinity.value, "reservation_affinity_values", null)) : trimspace(s)] } } labels = merge( @@ -983,9 +985,11 @@ resource "google_container_node_pool" "windows_pools" { } } dynamic "reservation_affinity" { - for_each = lookup(each.value, "queued_provisioning", false) ? [true] : [] + for_each = lookup(each.value, "queued_provisioning", false) || lookup(each.value, "consume_reservation_type", "") != "" ? [each.value] : [] content { - consume_reservation_type = "NO_RESERVATION" + consume_reservation_type = lookup(reservation_affinity.value, "queued_provisioning", false) ? "NO_RESERVATION" : lookup(reservation_affinity.value, "consume_reservation_type", null) + key = lookup(reservation_affinity.value, "reservation_affinity_key", null) + values = lookup(reservation_affinity.value, "reservation_affinity_values", null) == null ? null : [for s in split(",", lookup(reservation_affinity.value, "reservation_affinity_values", null)) : trimspace(s)] } } labels = merge( diff --git a/modules/beta-public-cluster-update-variant/README.md b/modules/beta-public-cluster-update-variant/README.md index a5417cdabc..c996793ae4 100644 --- a/modules/beta-public-cluster-update-variant/README.md +++ b/modules/beta-public-cluster-update-variant/README.md @@ -404,6 +404,9 @@ The node_pools variable takes the following parameters: | queued_provisioning | Makes nodes obtainable through the ProvisioningRequest API exclusively. | | Optional | | gpu_sharing_strategy | The type of GPU sharing strategy to enable on the GPU node. Accepted values are: "TIME_SHARING" and "MPS". | | Optional | | max_shared_clients_per_gpu | The maximum number of containers that can share a GPU. | | Optional | +| consume_reservation_type | The type of reservation consumption. Accepted values are: "UNSPECIFIED": Default value (should not be specified). "NO_RESERVATION": Do not consume from any reserved capacity, "ANY_RESERVATION": Consume any reservation available, "SPECIFIC_RESERVATION": Must consume from a specific reservation. Must specify key value fields for specifying the reservations. | | Optional | +| reservation_affinity_key | The label key of a reservation resource. To target a SPECIFIC_RESERVATION by name, specify "compute.googleapis.com/reservation-name" as the key and specify the name of your reservation as its value. | | Optional | +| reservation_affinity_values | The list of label values of reservation resources. For example: the name of the specific reservation when using a key of "compute.googleapis.com/reservation-name". This should be passed as comma separated string. | | Optional | ## windows_node_pools variable The windows_node_pools variable takes the same parameters as [node_pools](#node\_pools-variable) but is reserved for provisioning Windows based node pools only. This variable is introduced to satisfy a [specific requirement](https://cloud.google.com/kubernetes-engine/docs/how-to/creating-a-cluster-windows#create_a_cluster_and_node_pools) for the presence of at least one linux based node pool in the cluster before a windows based node pool can be created. diff --git a/modules/beta-public-cluster-update-variant/cluster.tf b/modules/beta-public-cluster-update-variant/cluster.tf index 6c68b5264d..cf9f095861 100644 --- a/modules/beta-public-cluster-update-variant/cluster.tf +++ b/modules/beta-public-cluster-update-variant/cluster.tf @@ -593,6 +593,9 @@ locals { "boot_disk_kms_key", "queued_provisioning", "enable_confidential_storage", + "consume_reservation_type", + "reservation_affinity_key", + "reservation_affinity_values" ] } @@ -748,9 +751,11 @@ resource "google_container_node_pool" "pools" { } } dynamic "reservation_affinity" { - for_each = lookup(each.value, "queued_provisioning", false) ? [true] : [] + for_each = lookup(each.value, "queued_provisioning", false) || lookup(each.value, "consume_reservation_type", "") != "" ? [each.value] : [] content { - consume_reservation_type = "NO_RESERVATION" + consume_reservation_type = lookup(reservation_affinity.value, "queued_provisioning", false) ? "NO_RESERVATION" : lookup(reservation_affinity.value, "consume_reservation_type", null) + key = lookup(reservation_affinity.value, "reservation_affinity_key", null) + values = lookup(reservation_affinity.value, "reservation_affinity_values", null) == null ? null : [for s in split(",", lookup(reservation_affinity.value, "reservation_affinity_values", null)) : trimspace(s)] } } labels = merge( @@ -1042,9 +1047,11 @@ resource "google_container_node_pool" "windows_pools" { } } dynamic "reservation_affinity" { - for_each = lookup(each.value, "queued_provisioning", false) ? [true] : [] + for_each = lookup(each.value, "queued_provisioning", false) || lookup(each.value, "consume_reservation_type", "") != "" ? [each.value] : [] content { - consume_reservation_type = "NO_RESERVATION" + consume_reservation_type = lookup(reservation_affinity.value, "queued_provisioning", false) ? "NO_RESERVATION" : lookup(reservation_affinity.value, "consume_reservation_type", null) + key = lookup(reservation_affinity.value, "reservation_affinity_key", null) + values = lookup(reservation_affinity.value, "reservation_affinity_values", null) == null ? null : [for s in split(",", lookup(reservation_affinity.value, "reservation_affinity_values", null)) : trimspace(s)] } } labels = merge( diff --git a/modules/beta-public-cluster/README.md b/modules/beta-public-cluster/README.md index 00654e1b3e..61cd7ab92f 100644 --- a/modules/beta-public-cluster/README.md +++ b/modules/beta-public-cluster/README.md @@ -382,6 +382,9 @@ The node_pools variable takes the following parameters: | queued_provisioning | Makes nodes obtainable through the ProvisioningRequest API exclusively. | | Optional | | gpu_sharing_strategy | The type of GPU sharing strategy to enable on the GPU node. Accepted values are: "TIME_SHARING" and "MPS". | | Optional | | max_shared_clients_per_gpu | The maximum number of containers that can share a GPU. | | Optional | +| consume_reservation_type | The type of reservation consumption. Accepted values are: "UNSPECIFIED": Default value (should not be specified). "NO_RESERVATION": Do not consume from any reserved capacity, "ANY_RESERVATION": Consume any reservation available, "SPECIFIC_RESERVATION": Must consume from a specific reservation. Must specify key value fields for specifying the reservations. | | Optional | +| reservation_affinity_key | The label key of a reservation resource. To target a SPECIFIC_RESERVATION by name, specify "compute.googleapis.com/reservation-name" as the key and specify the name of your reservation as its value. | | Optional | +| reservation_affinity_values | The list of label values of reservation resources. For example: the name of the specific reservation when using a key of "compute.googleapis.com/reservation-name". This should be passed as comma separated string. | | Optional | ## windows_node_pools variable The windows_node_pools variable takes the same parameters as [node_pools](#node\_pools-variable) but is reserved for provisioning Windows based node pools only. This variable is introduced to satisfy a [specific requirement](https://cloud.google.com/kubernetes-engine/docs/how-to/creating-a-cluster-windows#create_a_cluster_and_node_pools) for the presence of at least one linux based node pool in the cluster before a windows based node pool can be created. diff --git a/modules/beta-public-cluster/cluster.tf b/modules/beta-public-cluster/cluster.tf index e844bf1f01..5f8c5d1556 100644 --- a/modules/beta-public-cluster/cluster.tf +++ b/modules/beta-public-cluster/cluster.tf @@ -669,9 +669,11 @@ resource "google_container_node_pool" "pools" { } } dynamic "reservation_affinity" { - for_each = lookup(each.value, "queued_provisioning", false) ? [true] : [] + for_each = lookup(each.value, "queued_provisioning", false) || lookup(each.value, "consume_reservation_type", "") != "" ? [each.value] : [] content { - consume_reservation_type = "NO_RESERVATION" + consume_reservation_type = lookup(reservation_affinity.value, "queued_provisioning", false) ? "NO_RESERVATION" : lookup(reservation_affinity.value, "consume_reservation_type", null) + key = lookup(reservation_affinity.value, "reservation_affinity_key", null) + values = lookup(reservation_affinity.value, "reservation_affinity_values", null) == null ? null : [for s in split(",", lookup(reservation_affinity.value, "reservation_affinity_values", null)) : trimspace(s)] } } labels = merge( @@ -962,9 +964,11 @@ resource "google_container_node_pool" "windows_pools" { } } dynamic "reservation_affinity" { - for_each = lookup(each.value, "queued_provisioning", false) ? [true] : [] + for_each = lookup(each.value, "queued_provisioning", false) || lookup(each.value, "consume_reservation_type", "") != "" ? [each.value] : [] content { - consume_reservation_type = "NO_RESERVATION" + consume_reservation_type = lookup(reservation_affinity.value, "queued_provisioning", false) ? "NO_RESERVATION" : lookup(reservation_affinity.value, "consume_reservation_type", null) + key = lookup(reservation_affinity.value, "reservation_affinity_key", null) + values = lookup(reservation_affinity.value, "reservation_affinity_values", null) == null ? null : [for s in split(",", lookup(reservation_affinity.value, "reservation_affinity_values", null)) : trimspace(s)] } } labels = merge( diff --git a/modules/private-cluster-update-variant/README.md b/modules/private-cluster-update-variant/README.md index db5fb5784f..707fbc9237 100644 --- a/modules/private-cluster-update-variant/README.md +++ b/modules/private-cluster-update-variant/README.md @@ -393,6 +393,9 @@ The node_pools variable takes the following parameters: | queued_provisioning | Makes nodes obtainable through the ProvisioningRequest API exclusively. | | Optional | | gpu_sharing_strategy | The type of GPU sharing strategy to enable on the GPU node. Accepted values are: "TIME_SHARING" and "MPS". | | Optional | | max_shared_clients_per_gpu | The maximum number of containers that can share a GPU. | | Optional | +| consume_reservation_type | The type of reservation consumption. Accepted values are: "UNSPECIFIED": Default value (should not be specified). "NO_RESERVATION": Do not consume from any reserved capacity, "ANY_RESERVATION": Consume any reservation available, "SPECIFIC_RESERVATION": Must consume from a specific reservation. Must specify key value fields for specifying the reservations. | | Optional | +| reservation_affinity_key | The label key of a reservation resource. To target a SPECIFIC_RESERVATION by name, specify "compute.googleapis.com/reservation-name" as the key and specify the name of your reservation as its value. | | Optional | +| reservation_affinity_values | The list of label values of reservation resources. For example: the name of the specific reservation when using a key of "compute.googleapis.com/reservation-name". This should be passed as comma separated string. | | Optional | ## windows_node_pools variable The windows_node_pools variable takes the same parameters as [node_pools](#node\_pools-variable) but is reserved for provisioning Windows based node pools only. This variable is introduced to satisfy a [specific requirement](https://cloud.google.com/kubernetes-engine/docs/how-to/creating-a-cluster-windows#create_a_cluster_and_node_pools) for the presence of at least one linux based node pool in the cluster before a windows based node pool can be created. diff --git a/modules/private-cluster-update-variant/cluster.tf b/modules/private-cluster-update-variant/cluster.tf index 2ab271cd5f..59c6b01da2 100644 --- a/modules/private-cluster-update-variant/cluster.tf +++ b/modules/private-cluster-update-variant/cluster.tf @@ -550,6 +550,9 @@ locals { "boot_disk_kms_key", "queued_provisioning", "enable_confidential_storage", + "consume_reservation_type", + "reservation_affinity_key", + "reservation_affinity_values" ] } @@ -705,9 +708,11 @@ resource "google_container_node_pool" "pools" { } } dynamic "reservation_affinity" { - for_each = lookup(each.value, "queued_provisioning", false) ? [true] : [] + for_each = lookup(each.value, "queued_provisioning", false) || lookup(each.value, "consume_reservation_type", "") != "" ? [each.value] : [] content { - consume_reservation_type = "NO_RESERVATION" + consume_reservation_type = lookup(reservation_affinity.value, "queued_provisioning", false) ? "NO_RESERVATION" : lookup(reservation_affinity.value, "consume_reservation_type", null) + key = lookup(reservation_affinity.value, "reservation_affinity_key", null) + values = lookup(reservation_affinity.value, "reservation_affinity_values", null) == null ? null : [for s in split(",", lookup(reservation_affinity.value, "reservation_affinity_values", null)) : trimspace(s)] } } labels = merge( @@ -986,9 +991,11 @@ resource "google_container_node_pool" "windows_pools" { } } dynamic "reservation_affinity" { - for_each = lookup(each.value, "queued_provisioning", false) ? [true] : [] + for_each = lookup(each.value, "queued_provisioning", false) || lookup(each.value, "consume_reservation_type", "") != "" ? [each.value] : [] content { - consume_reservation_type = "NO_RESERVATION" + consume_reservation_type = lookup(reservation_affinity.value, "queued_provisioning", false) ? "NO_RESERVATION" : lookup(reservation_affinity.value, "consume_reservation_type", null) + key = lookup(reservation_affinity.value, "reservation_affinity_key", null) + values = lookup(reservation_affinity.value, "reservation_affinity_values", null) == null ? null : [for s in split(",", lookup(reservation_affinity.value, "reservation_affinity_values", null)) : trimspace(s)] } } labels = merge( diff --git a/modules/private-cluster/README.md b/modules/private-cluster/README.md index 590004ace3..b6d3eaa10e 100644 --- a/modules/private-cluster/README.md +++ b/modules/private-cluster/README.md @@ -371,6 +371,9 @@ The node_pools variable takes the following parameters: | queued_provisioning | Makes nodes obtainable through the ProvisioningRequest API exclusively. | | Optional | | gpu_sharing_strategy | The type of GPU sharing strategy to enable on the GPU node. Accepted values are: "TIME_SHARING" and "MPS". | | Optional | | max_shared_clients_per_gpu | The maximum number of containers that can share a GPU. | | Optional | +| consume_reservation_type | The type of reservation consumption. Accepted values are: "UNSPECIFIED": Default value (should not be specified). "NO_RESERVATION": Do not consume from any reserved capacity, "ANY_RESERVATION": Consume any reservation available, "SPECIFIC_RESERVATION": Must consume from a specific reservation. Must specify key value fields for specifying the reservations. | | Optional | +| reservation_affinity_key | The label key of a reservation resource. To target a SPECIFIC_RESERVATION by name, specify "compute.googleapis.com/reservation-name" as the key and specify the name of your reservation as its value. | | Optional | +| reservation_affinity_values | The list of label values of reservation resources. For example: the name of the specific reservation when using a key of "compute.googleapis.com/reservation-name". This should be passed as comma separated string. | | Optional | ## windows_node_pools variable The windows_node_pools variable takes the same parameters as [node_pools](#node\_pools-variable) but is reserved for provisioning Windows based node pools only. This variable is introduced to satisfy a [specific requirement](https://cloud.google.com/kubernetes-engine/docs/how-to/creating-a-cluster-windows#create_a_cluster_and_node_pools) for the presence of at least one linux based node pool in the cluster before a windows based node pool can be created. diff --git a/modules/private-cluster/cluster.tf b/modules/private-cluster/cluster.tf index 6ee3c32c6c..e257f9b0da 100644 --- a/modules/private-cluster/cluster.tf +++ b/modules/private-cluster/cluster.tf @@ -626,9 +626,11 @@ resource "google_container_node_pool" "pools" { } } dynamic "reservation_affinity" { - for_each = lookup(each.value, "queued_provisioning", false) ? [true] : [] + for_each = lookup(each.value, "queued_provisioning", false) || lookup(each.value, "consume_reservation_type", "") != "" ? [each.value] : [] content { - consume_reservation_type = "NO_RESERVATION" + consume_reservation_type = lookup(reservation_affinity.value, "queued_provisioning", false) ? "NO_RESERVATION" : lookup(reservation_affinity.value, "consume_reservation_type", null) + key = lookup(reservation_affinity.value, "reservation_affinity_key", null) + values = lookup(reservation_affinity.value, "reservation_affinity_values", null) == null ? null : [for s in split(",", lookup(reservation_affinity.value, "reservation_affinity_values", null)) : trimspace(s)] } } labels = merge( @@ -906,9 +908,11 @@ resource "google_container_node_pool" "windows_pools" { } } dynamic "reservation_affinity" { - for_each = lookup(each.value, "queued_provisioning", false) ? [true] : [] + for_each = lookup(each.value, "queued_provisioning", false) || lookup(each.value, "consume_reservation_type", "") != "" ? [each.value] : [] content { - consume_reservation_type = "NO_RESERVATION" + consume_reservation_type = lookup(reservation_affinity.value, "queued_provisioning", false) ? "NO_RESERVATION" : lookup(reservation_affinity.value, "consume_reservation_type", null) + key = lookup(reservation_affinity.value, "reservation_affinity_key", null) + values = lookup(reservation_affinity.value, "reservation_affinity_values", null) == null ? null : [for s in split(",", lookup(reservation_affinity.value, "reservation_affinity_values", null)) : trimspace(s)] } } labels = merge(