Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add network_config to node_pool #984

Merged
merged 14 commits into from
Aug 24, 2021
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,10 @@ The node_pools variable takes the following parameters:
| max_count | Maximum number of nodes in the NodePool. Must be >= min_count | 100 | Optional |
| min_count | Minimum number of nodes in the NodePool. Must be >=0 and <= max_count. Should be used when autoscaling is true | 1 | Optional |
| name | The name of the node pool | | Required |
| network_config | Configuration for Adding Pod IP address ranges to the node pool. | | Optional |
| create_pod_range | Whether to create a new range for pod IPs in this node pool. Defaults are provided for pod_range and pod_ipv4_cidr_block if they are not specified. | false | Optional |
| pod_ipv4_cidr_block | The IP address range for pod IPs in this node pool. Only applicable if create_pod_range is true. | | Optional |
| pod_range | The ID of the secondary range for pod IPs. If create_pod_range is true, this ID is used for the new range. If create_pod_range is false, uses an existing secondary range with this ID. | | Optional |
| node_count | The number of nodes in the nodepool when autoscaling is false. Otherwise defaults to 1. Only valid for non-autoscaling clusers | | Required |
| node_locations | The list of zones in which the cluster's nodes are located. Nodes must be in the region of their regional cluster or in the same region as their cluster's zone for zonal clusters. Defaults to cluster level node locations if nothing is specified | " " | Optional |
| node_metadata | Options to expose the node metadata to the workload running on the node | | Optional |
Expand Down
4 changes: 4 additions & 0 deletions autogen/main/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@ The node_pools variable takes the following parameters:
{% endif %}
| min_count | Minimum number of nodes in the NodePool. Must be >=0 and <= max_count. Should be used when autoscaling is true | 1 | Optional |
| name | The name of the node pool | | Required |
| network_config | Configuration for Adding Pod IP address ranges to the node pool. | | Optional |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since only pod_range is used now, could we collapse this into being the only variable? So network_config doesn't need to be supplied at all?

Copy link
Contributor Author

@DrFaust92 DrFaust92 Aug 24, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

future proofing? what if there will an additional var there?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

YAGNI - we shouldn't add complexity for hypothetical gains.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough. changed.

| create_pod_range | Whether to create a new range for pod IPs in this node pool. Defaults are provided for pod_range and pod_ipv4_cidr_block if they are not specified. | false | Optional |
| pod_ipv4_cidr_block | The IP address range for pod IPs in this node pool. Only applicable if create_pod_range is true. | | Optional |
| pod_range | The ID of the secondary range for pod IPs. If create_pod_range is true, this ID is used for the new range. If create_pod_range is false, uses an existing secondary range with this ID. | | Optional |
| node_count | The number of nodes in the nodepool when autoscaling is false. Otherwise defaults to 1. Only valid for non-autoscaling clusers | | Required |
| node_locations | The list of zones in which the cluster's nodes are located. Nodes must be in the region of their regional cluster or in the same region as their cluster's zone for zonal clusters. Defaults to cluster level node locations if nothing is specified | " " | Optional |
| node_metadata | Options to expose the node metadata to the workload running on the node | | Optional |
Expand Down
11 changes: 11 additions & 0 deletions autogen/main/cluster.tf.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,17 @@ resource "google_container_node_pool" "pools" {
}
}

{% if beta_cluster %}
dynamic "network_config" {
for_each = lookup(each.value, "network_config", false) ? [each.value] : []
content {
create_pod_range = lookup(network_config.value, "create_pod_range", false)
pod_ipv4_cidr_block = lookup(network_config.value, "pod_ipv4_cidr_block", null)
pod_range = lookup(network_config.value, "pod_range", null)
}
}
{% endif %}

management {
auto_repair = lookup(each.value, "auto_repair", true)
auto_upgrade = lookup(each.value, "auto_upgrade", local.default_auto_upgrade)
Expand Down
1 change: 1 addition & 0 deletions cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ resource "google_container_node_pool" "pools" {
}
}


management {
auto_repair = lookup(each.value, "auto_repair", true)
auto_upgrade = lookup(each.value, "auto_upgrade", local.default_auto_upgrade)
Expand Down
2 changes: 2 additions & 0 deletions examples/node_pool/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ This example illustrates how to create a cluster with multiple custom node-pool
| ip\_range\_pods | The secondary ip range to use for pods | `any` | n/a | yes |
| ip\_range\_services | The secondary ip range to use for services | `any` | n/a | yes |
| network | The VPC network to host the cluster in | `any` | n/a | yes |
| network\_config | network configuration override for node pools | `any` | n/a | yes |
| pod\_range | The ID of the secondary range for pod IPs. If create\_pod\_range is true, this ID is used for the new range. | `any` | n/a | yes |
| project\_id | The project ID to host the cluster in | `any` | n/a | yes |
| region | The region to host the cluster in | `any` | n/a | yes |
| subnetwork | The subnetwork to host the cluster in | `any` | n/a | yes |
Expand Down
4 changes: 3 additions & 1 deletion examples/node_pool/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ locals {
}

provider "google-beta" {
version = "~> 3.63.0"
version = "~> 3.79.0"
region = var.region
}

Expand Down Expand Up @@ -77,6 +77,8 @@ module "gke" {
image_type = "COS"
auto_upgrade = true
service_account = var.compute_engine_service_account
network_config = var.network_config
pod_range = var.pod_range
},
]

Expand Down
8 changes: 8 additions & 0 deletions examples/node_pool/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,11 @@ variable "cluster_autoscaling" {
}
description = "Cluster autoscaling configuration. See [more details](https://cloud.google.com/kubernetes-engine/docs/reference/rest/v1beta1/projects.locations.clusters#clusterautoscaling)"
}

variable "network_config" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't make this a variable. Just hard code it. Examples can and should use hardcoding extensively.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

np, it just will make an assumption on users env. will change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

description = "network configuration override for node pools"
}

variable "pod_range" {
description = "The ID of the secondary range for pod IPs. If create_pod_range is true, this ID is used for the new range."
}
2 changes: 1 addition & 1 deletion examples/node_pool_update_variant_beta/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ locals {
}

provider "google-beta" {
version = "~> 3.63.0"
version = "~> 3.79.0"
credentials = file(var.credentials_path)
region = var.region
}
Expand Down
2 changes: 1 addition & 1 deletion examples/node_pool_update_variant_public_beta/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ locals {
}

provider "google-beta" {
version = "~> 3.63.0"
version = "~> 3.79.0"
credentials = file(var.credentials_path)
region = var.region
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ provider "google" {
}

provider "google-beta" {
version = "~> 3.63.0"
version = "~> 3.79.0"
}

data "google_client_config" "default" {}
Expand Down
2 changes: 1 addition & 1 deletion examples/safer_cluster/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ provider "google" {
}

provider "google-beta" {
version = "~> 3.63.0"
version = "~> 3.79.0"
}

data "google_client_config" "default" {}
Expand Down
2 changes: 1 addition & 1 deletion examples/safer_cluster_iap_bastion/provider.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ provider "google" {
}

provider "google-beta" {
version = "~> 3.63.0"
version = "~> 3.79.0"
}

data "google_client_config" "default" {}
Expand Down
2 changes: 1 addition & 1 deletion examples/simple_regional_beta/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ locals {
}

provider "google-beta" {
version = "~> 3.63.0"
version = "~> 3.79.0"
region = var.region
}

Expand Down
2 changes: 1 addition & 1 deletion examples/simple_regional_private_beta/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ provider "google" {
}

provider "google-beta" {
version = "~> 3.63.0"
version = "~> 3.79.0"
region = var.region
}

Expand Down
2 changes: 1 addition & 1 deletion examples/simple_zonal_with_asm/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ locals {
}

provider "google-beta" {
version = "~> 3.63.0"
version = "~> 3.79.0"
region = var.region
}

Expand Down
2 changes: 1 addition & 1 deletion examples/workload_metadata_config/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ locals {
}

provider "google-beta" {
version = "~> 3.63.0"
version = "~> 3.79.0"
region = var.region
}

Expand Down
4 changes: 4 additions & 0 deletions modules/beta-private-cluster-update-variant/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,10 @@ The node_pools variable takes the following parameters:
| max_unavailable | The number of nodes that can be simultaneously unavailable during an upgrade. Increasing max_unavailable raises the number of nodes that can be upgraded in parallel. Can be set to 0 or greater. | 0 | Optional |
| min_count | Minimum number of nodes in the NodePool. Must be >=0 and <= max_count. Should be used when autoscaling is true | 1 | Optional |
| name | The name of the node pool | | Required |
| network_config | Configuration for Adding Pod IP address ranges to the node pool. | | Optional |
| create_pod_range | Whether to create a new range for pod IPs in this node pool. Defaults are provided for pod_range and pod_ipv4_cidr_block if they are not specified. | false | Optional |
| pod_ipv4_cidr_block | The IP address range for pod IPs in this node pool. Only applicable if create_pod_range is true. | | Optional |
| pod_range | The ID of the secondary range for pod IPs. If create_pod_range is true, this ID is used for the new range. If create_pod_range is false, uses an existing secondary range with this ID. | | Optional |
| node_count | The number of nodes in the nodepool when autoscaling is false. Otherwise defaults to 1. Only valid for non-autoscaling clusers | | Required |
| node_locations | The list of zones in which the cluster's nodes are located. Nodes must be in the region of their regional cluster or in the same region as their cluster's zone for zonal clusters. Defaults to cluster level node locations if nothing is specified | " " | Optional |
| node_metadata | Options to expose the node metadata to the workload running on the node | | Optional |
Expand Down
9 changes: 9 additions & 0 deletions modules/beta-private-cluster-update-variant/cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,15 @@ resource "google_container_node_pool" "pools" {
}
}

dynamic "network_config" {
for_each = lookup(each.value, "network_config", false) ? [each.value] : []
DrFaust92 marked this conversation as resolved.
Show resolved Hide resolved
content {
create_pod_range = lookup(network_config.value, "create_pod_range", false)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure we want to dynamically create the range on demand, since that's not very declarative.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, ill remove both create_pod_range and cidr vars.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi fellows, why not giving the possibility to customize the CIDR if set? Looks like pod_ipv4_cidr_block can not be set so it is set to a default. How can we set this to some CIDR range of our choosing? Thanks!

pod_ipv4_cidr_block = lookup(network_config.value, "pod_ipv4_cidr_block", null)
pod_range = lookup(network_config.value, "pod_range", null)
}
}

management {
auto_repair = lookup(each.value, "auto_repair", true)
auto_upgrade = lookup(each.value, "auto_upgrade", local.default_auto_upgrade)
Expand Down
4 changes: 4 additions & 0 deletions modules/beta-private-cluster/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,10 @@ The node_pools variable takes the following parameters:
| max_unavailable | The number of nodes that can be simultaneously unavailable during an upgrade. Increasing max_unavailable raises the number of nodes that can be upgraded in parallel. Can be set to 0 or greater. | 0 | Optional |
| min_count | Minimum number of nodes in the NodePool. Must be >=0 and <= max_count. Should be used when autoscaling is true | 1 | Optional |
| name | The name of the node pool | | Required |
| network_config | Configuration for Adding Pod IP address ranges to the node pool. | | Optional |
| create_pod_range | Whether to create a new range for pod IPs in this node pool. Defaults are provided for pod_range and pod_ipv4_cidr_block if they are not specified. | false | Optional |
| pod_ipv4_cidr_block | The IP address range for pod IPs in this node pool. Only applicable if create_pod_range is true. | | Optional |
| pod_range | The ID of the secondary range for pod IPs. If create_pod_range is true, this ID is used for the new range. If create_pod_range is false, uses an existing secondary range with this ID. | | Optional |
| node_count | The number of nodes in the nodepool when autoscaling is false. Otherwise defaults to 1. Only valid for non-autoscaling clusers | | Required |
| node_locations | The list of zones in which the cluster's nodes are located. Nodes must be in the region of their regional cluster or in the same region as their cluster's zone for zonal clusters. Defaults to cluster level node locations if nothing is specified | " " | Optional |
| node_metadata | Options to expose the node metadata to the workload running on the node | | Optional |
Expand Down
9 changes: 9 additions & 0 deletions modules/beta-private-cluster/cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,15 @@ resource "google_container_node_pool" "pools" {
}
}

dynamic "network_config" {
for_each = lookup(each.value, "network_config", false) ? [each.value] : []
content {
create_pod_range = lookup(network_config.value, "create_pod_range", false)
pod_ipv4_cidr_block = lookup(network_config.value, "pod_ipv4_cidr_block", null)
pod_range = lookup(network_config.value, "pod_range", null)
}
}

management {
auto_repair = lookup(each.value, "auto_repair", true)
auto_upgrade = lookup(each.value, "auto_upgrade", local.default_auto_upgrade)
Expand Down
4 changes: 4 additions & 0 deletions modules/beta-public-cluster-update-variant/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,10 @@ The node_pools variable takes the following parameters:
| max_unavailable | The number of nodes that can be simultaneously unavailable during an upgrade. Increasing max_unavailable raises the number of nodes that can be upgraded in parallel. Can be set to 0 or greater. | 0 | Optional |
| min_count | Minimum number of nodes in the NodePool. Must be >=0 and <= max_count. Should be used when autoscaling is true | 1 | Optional |
| name | The name of the node pool | | Required |
| network_config | Configuration for Adding Pod IP address ranges to the node pool. | | Optional |
| create_pod_range | Whether to create a new range for pod IPs in this node pool. Defaults are provided for pod_range and pod_ipv4_cidr_block if they are not specified. | false | Optional |
| pod_ipv4_cidr_block | The IP address range for pod IPs in this node pool. Only applicable if create_pod_range is true. | | Optional |
| pod_range | The ID of the secondary range for pod IPs. If create_pod_range is true, this ID is used for the new range. If create_pod_range is false, uses an existing secondary range with this ID. | | Optional |
| node_count | The number of nodes in the nodepool when autoscaling is false. Otherwise defaults to 1. Only valid for non-autoscaling clusers | | Required |
| node_locations | The list of zones in which the cluster's nodes are located. Nodes must be in the region of their regional cluster or in the same region as their cluster's zone for zonal clusters. Defaults to cluster level node locations if nothing is specified | " " | Optional |
| node_metadata | Options to expose the node metadata to the workload running on the node | | Optional |
Expand Down
9 changes: 9 additions & 0 deletions modules/beta-public-cluster-update-variant/cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,15 @@ resource "google_container_node_pool" "pools" {
}
}

dynamic "network_config" {
for_each = lookup(each.value, "network_config", false) ? [each.value] : []
content {
create_pod_range = lookup(network_config.value, "create_pod_range", false)
pod_ipv4_cidr_block = lookup(network_config.value, "pod_ipv4_cidr_block", null)
pod_range = lookup(network_config.value, "pod_range", null)
}
}

management {
auto_repair = lookup(each.value, "auto_repair", true)
auto_upgrade = lookup(each.value, "auto_upgrade", local.default_auto_upgrade)
Expand Down
4 changes: 4 additions & 0 deletions modules/beta-public-cluster/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,10 @@ The node_pools variable takes the following parameters:
| max_unavailable | The number of nodes that can be simultaneously unavailable during an upgrade. Increasing max_unavailable raises the number of nodes that can be upgraded in parallel. Can be set to 0 or greater. | 0 | Optional |
| min_count | Minimum number of nodes in the NodePool. Must be >=0 and <= max_count. Should be used when autoscaling is true | 1 | Optional |
| name | The name of the node pool | | Required |
| network_config | Configuration for Adding Pod IP address ranges to the node pool. | | Optional |
| create_pod_range | Whether to create a new range for pod IPs in this node pool. Defaults are provided for pod_range and pod_ipv4_cidr_block if they are not specified. | false | Optional |
| pod_ipv4_cidr_block | The IP address range for pod IPs in this node pool. Only applicable if create_pod_range is true. | | Optional |
| pod_range | The ID of the secondary range for pod IPs. If create_pod_range is true, this ID is used for the new range. If create_pod_range is false, uses an existing secondary range with this ID. | | Optional |
| node_count | The number of nodes in the nodepool when autoscaling is false. Otherwise defaults to 1. Only valid for non-autoscaling clusers | | Required |
| node_locations | The list of zones in which the cluster's nodes are located. Nodes must be in the region of their regional cluster or in the same region as their cluster's zone for zonal clusters. Defaults to cluster level node locations if nothing is specified | " " | Optional |
| node_metadata | Options to expose the node metadata to the workload running on the node | | Optional |
Expand Down
9 changes: 9 additions & 0 deletions modules/beta-public-cluster/cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,15 @@ resource "google_container_node_pool" "pools" {
}
}

dynamic "network_config" {
for_each = lookup(each.value, "network_config", false) ? [each.value] : []
content {
create_pod_range = lookup(network_config.value, "create_pod_range", false)
pod_ipv4_cidr_block = lookup(network_config.value, "pod_ipv4_cidr_block", null)
pod_range = lookup(network_config.value, "pod_range", null)
}
}

management {
auto_repair = lookup(each.value, "auto_repair", true)
auto_upgrade = lookup(each.value, "auto_upgrade", local.default_auto_upgrade)
Expand Down
4 changes: 4 additions & 0 deletions modules/private-cluster-update-variant/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,10 @@ The node_pools variable takes the following parameters:
| max_count | Maximum number of nodes in the NodePool. Must be >= min_count | 100 | Optional |
| min_count | Minimum number of nodes in the NodePool. Must be >=0 and <= max_count. Should be used when autoscaling is true | 1 | Optional |
| name | The name of the node pool | | Required |
| network_config | Configuration for Adding Pod IP address ranges to the node pool. | | Optional |
| create_pod_range | Whether to create a new range for pod IPs in this node pool. Defaults are provided for pod_range and pod_ipv4_cidr_block if they are not specified. | false | Optional |
| pod_ipv4_cidr_block | The IP address range for pod IPs in this node pool. Only applicable if create_pod_range is true. | | Optional |
| pod_range | The ID of the secondary range for pod IPs. If create_pod_range is true, this ID is used for the new range. If create_pod_range is false, uses an existing secondary range with this ID. | | Optional |
| node_count | The number of nodes in the nodepool when autoscaling is false. Otherwise defaults to 1. Only valid for non-autoscaling clusers | | Required |
| node_locations | The list of zones in which the cluster's nodes are located. Nodes must be in the region of their regional cluster or in the same region as their cluster's zone for zonal clusters. Defaults to cluster level node locations if nothing is specified | " " | Optional |
| node_metadata | Options to expose the node metadata to the workload running on the node | | Optional |
Expand Down
1 change: 1 addition & 0 deletions modules/private-cluster-update-variant/cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ resource "google_container_node_pool" "pools" {
}
}


management {
auto_repair = lookup(each.value, "auto_repair", true)
auto_upgrade = lookup(each.value, "auto_upgrade", local.default_auto_upgrade)
Expand Down
4 changes: 4 additions & 0 deletions modules/private-cluster/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,10 @@ The node_pools variable takes the following parameters:
| max_count | Maximum number of nodes in the NodePool. Must be >= min_count | 100 | Optional |
| min_count | Minimum number of nodes in the NodePool. Must be >=0 and <= max_count. Should be used when autoscaling is true | 1 | Optional |
| name | The name of the node pool | | Required |
| network_config | Configuration for Adding Pod IP address ranges to the node pool. | | Optional |
| create_pod_range | Whether to create a new range for pod IPs in this node pool. Defaults are provided for pod_range and pod_ipv4_cidr_block if they are not specified. | false | Optional |
| pod_ipv4_cidr_block | The IP address range for pod IPs in this node pool. Only applicable if create_pod_range is true. | | Optional |
| pod_range | The ID of the secondary range for pod IPs. If create_pod_range is true, this ID is used for the new range. If create_pod_range is false, uses an existing secondary range with this ID. | | Optional |
| node_count | The number of nodes in the nodepool when autoscaling is false. Otherwise defaults to 1. Only valid for non-autoscaling clusers | | Required |
| node_locations | The list of zones in which the cluster's nodes are located. Nodes must be in the region of their regional cluster or in the same region as their cluster's zone for zonal clusters. Defaults to cluster level node locations if nothing is specified | " " | Optional |
| node_metadata | Options to expose the node metadata to the workload running on the node | | Optional |
Expand Down
1 change: 1 addition & 0 deletions modules/private-cluster/cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ resource "google_container_node_pool" "pools" {
}
}


management {
auto_repair = lookup(each.value, "auto_repair", true)
auto_upgrade = lookup(each.value, "auto_upgrade", local.default_auto_upgrade)
Expand Down