Skip to content

Commit b62bd0b

Browse files
feat: ip_range_services to optional value (#1949) (#2365)
1 parent 0938309 commit b62bd0b

File tree

54 files changed

+113
-73
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+113
-73
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ Then perform the following commands on the root folder:
204204
| ip\_masq\_link\_local | Whether to masquerade traffic to the link-local prefix (169.254.0.0/16). | `bool` | `false` | no |
205205
| ip\_masq\_resync\_interval | The interval at which the agent attempts to sync its ConfigMap file from the disk. | `string` | `"60s"` | no |
206206
| ip\_range\_pods | The _name_ of the secondary subnet ip range to use for pods | `string` | n/a | yes |
207-
| ip\_range\_services | The _name_ of the secondary subnet range to use for services | `string` | n/a | yes |
207+
| ip\_range\_services | The _name_ of the secondary subnet range to use for services. If not provided, the default `34.118.224.0/20` range will be used. | `string` | `null` | no |
208208
| issue\_client\_certificate | Issues a client certificate to authenticate to the cluster endpoint. To maximize the security of your cluster, leave this option disabled. Client certificates don't automatically rotate and aren't easily revocable. WARNING: changing this after cluster creation is destructive! | `bool` | `false` | no |
209209
| kubernetes\_version | The Kubernetes version of the masters. If set to 'latest' it will pull latest available version in the selected region. | `string` | `"latest"` | no |
210210
| logging\_enabled\_components | List of services to monitor: SYSTEM\_COMPONENTS, APISERVER, CONTROLLER\_MANAGER, KCP\_CONNECTION, KCP\_SSHD, KCP\_HPA, SCHEDULER, and WORKLOADS. Empty list is default GKE configuration. | `list(string)` | `[]` | no |

autogen/main/cluster.tf.tmpl

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -526,11 +526,21 @@ resource "google_container_cluster" "primary" {
526526
}
527527
}
528528

529-
{% if autopilot_cluster != true %}
530529
lifecycle {
530+
precondition {
531+
{% if autopilot_cluster %}
532+
condition = var.ip_range_services == null && var.kubernetes_version != "latest" ? tonumber(split(".", var.kubernetes_version)[0]) >= 1 && tonumber(split(".", var.kubernetes_version)[1]) >= 27 : true
533+
error_message = "Setting ip_range_services is required for this GKE version. Please set ip_range_services or use kubernetes_version 1.27 or later."
534+
{% else %}
535+
condition = var.ip_range_services == null && var.kubernetes_version != "latest" ? tonumber(split(".", var.kubernetes_version)[0]) >= 1 && tonumber(split(".", var.kubernetes_version)[1]) >= 29 : true
536+
error_message = "Setting ip_range_services is required for this GKE version. Please set ip_range_services or use kubernetes_version 1.29 or later."
537+
{% endif %}
538+
}
539+
540+
{% if autopilot_cluster != true %}
531541
ignore_changes = [node_pool, initial_node_count, resource_labels["asmv"]]
542+
{% endif %}
532543
}
533-
{% endif %}
534544

535545
{% if autopilot_cluster != true %}
536546
dynamic "dns_config" {

autogen/main/variables.tf.tmpl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,8 @@ variable "additional_ip_range_pods" {
176176

177177
variable "ip_range_services" {
178178
type = string
179-
description = "The _name_ of the secondary subnet range to use for services"
179+
description = "The _name_ of the secondary subnet range to use for services. If not provided, the default `34.118.224.0/20` range will be used."
180+
default = null
180181
}
181182

182183
variable "stack_type" {

autogen/safer-cluster/variables.tf.tmpl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ variable "ip_range_pods" {
138138

139139
variable "ip_range_services" {
140140
type = string
141-
description = "The _name_ of the secondary subnet range to use for services"
141+
description = "The _name_ of the secondary subnet range to use for services. If not provided, the default `34.118.224.0/20` range will be used."
142+
default = null
142143
}
143144

144145
variable "initial_node_count" {

cluster.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,11 @@ resource "google_container_cluster" "primary" {
397397
}
398398

399399
lifecycle {
400+
precondition {
401+
condition = var.ip_range_services == null && var.kubernetes_version != "latest" ? tonumber(split(".", var.kubernetes_version)[0]) >= 1 && tonumber(split(".", var.kubernetes_version)[1]) >= 29 : true
402+
error_message = "Setting ip_range_services is required for this GKE version. Please set ip_range_services or use kubernetes_version 1.29 or later."
403+
}
404+
400405
ignore_changes = [node_pool, initial_node_count, resource_labels["asmv"]]
401406
}
402407

examples/simple_autopilot_private/main.tf

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ locals {
2020
subnet_name = "simple-autopilot-private-subnet"
2121
master_auth_subnetwork = "simple-autopilot-private-master-subnet"
2222
pods_range_name = "ip-range-pods-simple-autopilot-private"
23-
svc_range_name = "ip-range-svc-simple-autopilot-private"
2423
subnet_names = [for subnet_self_link in module.gcp-network.subnets_self_links : split("/", subnet_self_link)[length(split("/", subnet_self_link)) - 1]]
2524
}
2625

@@ -44,7 +43,6 @@ module "gke" {
4443
network = module.gcp-network.network_name
4544
subnetwork = local.subnet_names[index(module.gcp-network.subnets_names, local.subnet_name)]
4645
ip_range_pods = local.pods_range_name
47-
ip_range_services = local.svc_range_name
4846
release_channel = "REGULAR"
4947
enable_vertical_pod_autoscaling = true
5048
enable_private_endpoint = true

examples/simple_autopilot_private/network.tf

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,6 @@ module "gcp-network" {
4141
range_name = local.pods_range_name
4242
ip_cidr_range = "192.168.0.0/18"
4343
},
44-
{
45-
range_name = local.svc_range_name
46-
ip_cidr_range = "192.168.64.0/18"
47-
},
4844
]
4945
}
5046
}

examples/simple_regional_private/README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ This example illustrates how to create a simple private cluster.
1010
| cluster\_name\_suffix | A suffix to append to the default cluster name | `string` | `""` | no |
1111
| compute\_engine\_service\_account | Service account to associate to the nodes in the cluster | `any` | n/a | yes |
1212
| ip\_range\_pods | The secondary ip range to use for pods | `any` | n/a | yes |
13-
| ip\_range\_services | The secondary ip range to use for services | `any` | n/a | yes |
1413
| network | The VPC network to host the cluster in | `any` | n/a | yes |
1514
| project\_id | The project ID to host the cluster in | `any` | n/a | yes |
1615
| region | The region to host the cluster in | `any` | n/a | yes |
@@ -24,7 +23,6 @@ This example illustrates how to create a simple private cluster.
2423
| client\_token | n/a |
2524
| cluster\_name | Cluster name |
2625
| ip\_range\_pods | The secondary IP range used for pods |
27-
| ip\_range\_services | The secondary IP range used for services |
2826
| kubernetes\_endpoint | n/a |
2927
| location | n/a |
3028
| master\_kubernetes\_version | The master Kubernetes version |

examples/simple_regional_private/main.tf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ module "gke" {
4343
network = var.network
4444
subnetwork = var.subnetwork
4545
ip_range_pods = var.ip_range_pods
46-
ip_range_services = var.ip_range_services
4746
create_service_account = false
4847
service_account = var.compute_engine_service_account
4948
enable_private_endpoint = true

examples/simple_regional_private/test_outputs.tf

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,6 @@ output "ip_range_pods" {
4747
value = var.ip_range_pods
4848
}
4949

50-
output "ip_range_services" {
51-
description = "The secondary IP range used for services"
52-
value = var.ip_range_services
53-
}
54-
5550
output "zones" {
5651
description = "List of zones in which the cluster resides"
5752
value = module.gke.zones

0 commit comments

Comments
 (0)