Skip to content

Commit

Permalink
feat: add support for Linux node config (#782)
Browse files Browse the repository at this point in the history
* Add linux node config

* Add variable node_pools_linux_node_configs

* Generate modules

* Fix dynamic block

* Generate modules

* Deep merge for sysctls maps

* Generate modules

* Add sysctls to node_pool example and test

* Flatten sysctls map

* Generate modules

* Fix typo in test

* Fix trailing whitespace

* Fix parens

* Update autogen/main/cluster.tf.tmpl

Co-authored-by: Tencho Tenev <tencho@improbable.io>

* Generate modules

Co-authored-by: Tencho Tenev <tencho@improbable.io>
Co-authored-by: Bharath KKB <bharathkrishnakb@gmail.com>
  • Loading branch information
3 people committed Jan 14, 2021
1 parent aa551d5 commit 98826e6
Show file tree
Hide file tree
Showing 21 changed files with 242 additions and 1 deletion.
16 changes: 15 additions & 1 deletion autogen/main/cluster.tf.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ resource "google_container_cluster" "primary" {
}
}
}

vertical_pod_autoscaling {
enabled = var.enable_vertical_pod_autoscaling
}
Expand Down Expand Up @@ -565,6 +565,20 @@ resource "google_container_node_pool" "pools" {
cpu_manager_policy = lookup(each.value, "cpu_manager_policy")
}
}

dynamic "linux_node_config" {
for_each = merge(
local.node_pools_linux_node_configs_sysctls["all"],
local.node_pools_linux_node_configs_sysctls[each.value["name"]]
) != {} ? [1] : []

content {
sysctls = merge(
local.node_pools_linux_node_configs_sysctls["all"],
local.node_pools_linux_node_configs_sysctls[each.value["name"]]
)
}
}
{% endif %}

shielded_instance_config {
Expand Down
13 changes: 13 additions & 0 deletions autogen/main/variables.tf.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,19 @@ variable "node_pools_metadata" {
default-node-pool = {}
}
}
{% if beta_cluster %}

variable "node_pools_linux_node_configs_sysctls" {
type = map(map(string))
description = "Map of maps containing linux node config sysctls by node-pool name"

# Default is being set in variables_defaults.tf
default = {
all = {}
default-node-pool = {}
}
}
{% endif %}

variable "resource_usage_export_dataset_id" {
type = string
Expand Down
12 changes: 12 additions & 0 deletions autogen/main/variables_defaults.tf
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,16 @@ locals {
),
var.node_pools_oauth_scopes
)
{% if beta_cluster %}

node_pools_linux_node_configs_sysctls = merge(
{ all = {} },
{ default-node-pool = {} },
zipmap(
[for node_pool in var.node_pools : node_pool["name"]],
[for node_pool in var.node_pools : {}]
),
var.node_pools_linux_node_configs_sysctls
)
{% endif %}
}
12 changes: 12 additions & 0 deletions examples/node_pool/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,16 @@ module "gke" {
"pool-01-example",
]
}

node_pools_linux_node_configs_sysctls = {
all = {
"net.core.netdev_max_backlog" = "10000"
}
pool-01 = {
"net.core.rmem_max" = "10000"
}
pool-03 = {
"net.core.netdev_max_backlog" = "20000"
}
}
}
1 change: 1 addition & 0 deletions modules/beta-private-cluster-update-variant/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ Then perform the following commands on the root folder:
| node\_metadata | Specifies how node metadata is exposed to the workload running on the node | `string` | `"GKE_METADATA_SERVER"` | no |
| node\_pools | List of maps containing node pools | `list(map(string))` | <pre>[<br> {<br> "name": "default-node-pool"<br> }<br>]</pre> | no |
| node\_pools\_labels | Map of maps containing node labels by node-pool name | `map(map(string))` | <pre>{<br> "all": {},<br> "default-node-pool": {}<br>}</pre> | no |
| node\_pools\_linux\_node\_configs\_sysctls | Map of maps containing linux node config sysctls by node-pool name | `map(map(string))` | <pre>{<br> "all": {},<br> "default-node-pool": {}<br>}</pre> | no |
| node\_pools\_metadata | Map of maps containing node metadata by node-pool name | `map(map(string))` | <pre>{<br> "all": {},<br> "default-node-pool": {}<br>}</pre> | no |
| node\_pools\_oauth\_scopes | Map of lists containing node oauth scopes by node-pool name | `map(list(string))` | <pre>{<br> "all": [<br> "https://www.googleapis.com/auth/cloud-platform"<br> ],<br> "default-node-pool": []<br>}</pre> | no |
| node\_pools\_tags | Map of lists containing node network tags by node-pool name | `map(list(string))` | <pre>{<br> "all": [],<br> "default-node-pool": []<br>}</pre> | no |
Expand Down
14 changes: 14 additions & 0 deletions modules/beta-private-cluster-update-variant/cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,20 @@ resource "google_container_node_pool" "pools" {
}
}

dynamic "linux_node_config" {
for_each = merge(
local.node_pools_linux_node_configs_sysctls["all"],
local.node_pools_linux_node_configs_sysctls[each.value["name"]]
) != {} ? [1] : []

content {
sysctls = merge(
local.node_pools_linux_node_configs_sysctls["all"],
local.node_pools_linux_node_configs_sysctls[each.value["name"]]
)
}
}

shielded_instance_config {
enable_secure_boot = lookup(each.value, "enable_secure_boot", false)
enable_integrity_monitoring = lookup(each.value, "enable_integrity_monitoring", true)
Expand Down
11 changes: 11 additions & 0 deletions modules/beta-private-cluster-update-variant/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,17 @@ variable "node_pools_metadata" {
}
}

variable "node_pools_linux_node_configs_sysctls" {
type = map(map(string))
description = "Map of maps containing linux node config sysctls by node-pool name"

# Default is being set in variables_defaults.tf
default = {
all = {}
default-node-pool = {}
}
}

variable "resource_usage_export_dataset_id" {
type = string
description = "The ID of a BigQuery Dataset for using BigQuery as the destination of resource usage export."
Expand Down
10 changes: 10 additions & 0 deletions modules/beta-private-cluster-update-variant/variables_defaults.tf
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,14 @@ locals {
),
var.node_pools_oauth_scopes
)

node_pools_linux_node_configs_sysctls = merge(
{ all = {} },
{ default-node-pool = {} },
zipmap(
[for node_pool in var.node_pools : node_pool["name"]],
[for node_pool in var.node_pools : {}]
),
var.node_pools_linux_node_configs_sysctls
)
}
1 change: 1 addition & 0 deletions modules/beta-private-cluster/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ Then perform the following commands on the root folder:
| node\_metadata | Specifies how node metadata is exposed to the workload running on the node | `string` | `"GKE_METADATA_SERVER"` | no |
| node\_pools | List of maps containing node pools | `list(map(string))` | <pre>[<br> {<br> "name": "default-node-pool"<br> }<br>]</pre> | no |
| node\_pools\_labels | Map of maps containing node labels by node-pool name | `map(map(string))` | <pre>{<br> "all": {},<br> "default-node-pool": {}<br>}</pre> | no |
| node\_pools\_linux\_node\_configs\_sysctls | Map of maps containing linux node config sysctls by node-pool name | `map(map(string))` | <pre>{<br> "all": {},<br> "default-node-pool": {}<br>}</pre> | no |
| node\_pools\_metadata | Map of maps containing node metadata by node-pool name | `map(map(string))` | <pre>{<br> "all": {},<br> "default-node-pool": {}<br>}</pre> | no |
| node\_pools\_oauth\_scopes | Map of lists containing node oauth scopes by node-pool name | `map(list(string))` | <pre>{<br> "all": [<br> "https://www.googleapis.com/auth/cloud-platform"<br> ],<br> "default-node-pool": []<br>}</pre> | no |
| node\_pools\_tags | Map of lists containing node network tags by node-pool name | `map(list(string))` | <pre>{<br> "all": [],<br> "default-node-pool": []<br>}</pre> | no |
Expand Down
14 changes: 14 additions & 0 deletions modules/beta-private-cluster/cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,20 @@ resource "google_container_node_pool" "pools" {
}
}

dynamic "linux_node_config" {
for_each = merge(
local.node_pools_linux_node_configs_sysctls["all"],
local.node_pools_linux_node_configs_sysctls[each.value["name"]]
) != {} ? [1] : []

content {
sysctls = merge(
local.node_pools_linux_node_configs_sysctls["all"],
local.node_pools_linux_node_configs_sysctls[each.value["name"]]
)
}
}

shielded_instance_config {
enable_secure_boot = lookup(each.value, "enable_secure_boot", false)
enable_integrity_monitoring = lookup(each.value, "enable_integrity_monitoring", true)
Expand Down
11 changes: 11 additions & 0 deletions modules/beta-private-cluster/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,17 @@ variable "node_pools_metadata" {
}
}

variable "node_pools_linux_node_configs_sysctls" {
type = map(map(string))
description = "Map of maps containing linux node config sysctls by node-pool name"

# Default is being set in variables_defaults.tf
default = {
all = {}
default-node-pool = {}
}
}

variable "resource_usage_export_dataset_id" {
type = string
description = "The ID of a BigQuery Dataset for using BigQuery as the destination of resource usage export."
Expand Down
10 changes: 10 additions & 0 deletions modules/beta-private-cluster/variables_defaults.tf
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,14 @@ locals {
),
var.node_pools_oauth_scopes
)

node_pools_linux_node_configs_sysctls = merge(
{ all = {} },
{ default-node-pool = {} },
zipmap(
[for node_pool in var.node_pools : node_pool["name"]],
[for node_pool in var.node_pools : {}]
),
var.node_pools_linux_node_configs_sysctls
)
}
1 change: 1 addition & 0 deletions modules/beta-public-cluster-update-variant/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ Then perform the following commands on the root folder:
| node\_metadata | Specifies how node metadata is exposed to the workload running on the node | `string` | `"GKE_METADATA_SERVER"` | no |
| node\_pools | List of maps containing node pools | `list(map(string))` | <pre>[<br> {<br> "name": "default-node-pool"<br> }<br>]</pre> | no |
| node\_pools\_labels | Map of maps containing node labels by node-pool name | `map(map(string))` | <pre>{<br> "all": {},<br> "default-node-pool": {}<br>}</pre> | no |
| node\_pools\_linux\_node\_configs\_sysctls | Map of maps containing linux node config sysctls by node-pool name | `map(map(string))` | <pre>{<br> "all": {},<br> "default-node-pool": {}<br>}</pre> | no |
| node\_pools\_metadata | Map of maps containing node metadata by node-pool name | `map(map(string))` | <pre>{<br> "all": {},<br> "default-node-pool": {}<br>}</pre> | no |
| node\_pools\_oauth\_scopes | Map of lists containing node oauth scopes by node-pool name | `map(list(string))` | <pre>{<br> "all": [<br> "https://www.googleapis.com/auth/cloud-platform"<br> ],<br> "default-node-pool": []<br>}</pre> | no |
| node\_pools\_tags | Map of lists containing node network tags by node-pool name | `map(list(string))` | <pre>{<br> "all": [],<br> "default-node-pool": []<br>}</pre> | no |
Expand Down
14 changes: 14 additions & 0 deletions modules/beta-public-cluster-update-variant/cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,20 @@ resource "google_container_node_pool" "pools" {
}
}

dynamic "linux_node_config" {
for_each = merge(
local.node_pools_linux_node_configs_sysctls["all"],
local.node_pools_linux_node_configs_sysctls[each.value["name"]]
) != {} ? [1] : []

content {
sysctls = merge(
local.node_pools_linux_node_configs_sysctls["all"],
local.node_pools_linux_node_configs_sysctls[each.value["name"]]
)
}
}

shielded_instance_config {
enable_secure_boot = lookup(each.value, "enable_secure_boot", false)
enable_integrity_monitoring = lookup(each.value, "enable_integrity_monitoring", true)
Expand Down
11 changes: 11 additions & 0 deletions modules/beta-public-cluster-update-variant/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,17 @@ variable "node_pools_metadata" {
}
}

variable "node_pools_linux_node_configs_sysctls" {
type = map(map(string))
description = "Map of maps containing linux node config sysctls by node-pool name"

# Default is being set in variables_defaults.tf
default = {
all = {}
default-node-pool = {}
}
}

variable "resource_usage_export_dataset_id" {
type = string
description = "The ID of a BigQuery Dataset for using BigQuery as the destination of resource usage export."
Expand Down
10 changes: 10 additions & 0 deletions modules/beta-public-cluster-update-variant/variables_defaults.tf
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,14 @@ locals {
),
var.node_pools_oauth_scopes
)

node_pools_linux_node_configs_sysctls = merge(
{ all = {} },
{ default-node-pool = {} },
zipmap(
[for node_pool in var.node_pools : node_pool["name"]],
[for node_pool in var.node_pools : {}]
),
var.node_pools_linux_node_configs_sysctls
)
}
1 change: 1 addition & 0 deletions modules/beta-public-cluster/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ Then perform the following commands on the root folder:
| node\_metadata | Specifies how node metadata is exposed to the workload running on the node | `string` | `"GKE_METADATA_SERVER"` | no |
| node\_pools | List of maps containing node pools | `list(map(string))` | <pre>[<br> {<br> "name": "default-node-pool"<br> }<br>]</pre> | no |
| node\_pools\_labels | Map of maps containing node labels by node-pool name | `map(map(string))` | <pre>{<br> "all": {},<br> "default-node-pool": {}<br>}</pre> | no |
| node\_pools\_linux\_node\_configs\_sysctls | Map of maps containing linux node config sysctls by node-pool name | `map(map(string))` | <pre>{<br> "all": {},<br> "default-node-pool": {}<br>}</pre> | no |
| node\_pools\_metadata | Map of maps containing node metadata by node-pool name | `map(map(string))` | <pre>{<br> "all": {},<br> "default-node-pool": {}<br>}</pre> | no |
| node\_pools\_oauth\_scopes | Map of lists containing node oauth scopes by node-pool name | `map(list(string))` | <pre>{<br> "all": [<br> "https://www.googleapis.com/auth/cloud-platform"<br> ],<br> "default-node-pool": []<br>}</pre> | no |
| node\_pools\_tags | Map of lists containing node network tags by node-pool name | `map(list(string))` | <pre>{<br> "all": [],<br> "default-node-pool": []<br>}</pre> | no |
Expand Down
14 changes: 14 additions & 0 deletions modules/beta-public-cluster/cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,20 @@ resource "google_container_node_pool" "pools" {
}
}

dynamic "linux_node_config" {
for_each = merge(
local.node_pools_linux_node_configs_sysctls["all"],
local.node_pools_linux_node_configs_sysctls[each.value["name"]]
) != {} ? [1] : []

content {
sysctls = merge(
local.node_pools_linux_node_configs_sysctls["all"],
local.node_pools_linux_node_configs_sysctls[each.value["name"]]
)
}
}

shielded_instance_config {
enable_secure_boot = lookup(each.value, "enable_secure_boot", false)
enable_integrity_monitoring = lookup(each.value, "enable_integrity_monitoring", true)
Expand Down
11 changes: 11 additions & 0 deletions modules/beta-public-cluster/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,17 @@ variable "node_pools_metadata" {
}
}

variable "node_pools_linux_node_configs_sysctls" {
type = map(map(string))
description = "Map of maps containing linux node config sysctls by node-pool name"

# Default is being set in variables_defaults.tf
default = {
all = {}
default-node-pool = {}
}
}

variable "resource_usage_export_dataset_id" {
type = string
description = "The ID of a BigQuery Dataset for using BigQuery as the destination of resource usage export."
Expand Down
10 changes: 10 additions & 0 deletions modules/beta-public-cluster/variables_defaults.tf
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,14 @@ locals {
),
var.node_pools_oauth_scopes
)

node_pools_linux_node_configs_sysctls = merge(
{ all = {} },
{ default-node-pool = {} },
zipmap(
[for node_pool in var.node_pools : node_pool["name"]],
[for node_pool in var.node_pools : {}]
),
var.node_pools_linux_node_configs_sysctls
)
}
46 changes: 46 additions & 0 deletions test/integration/node_pool/controls/gcloud.rb
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,22 @@
)
)
end

it "has the expected linux node config sysctls" do
expect(data['nodePools']).to include(
including(
"name" => "pool-01",
"config" => including(
"linuxNodeConfig" => including(
"sysctls" => including(
"net.core.netdev_max_backlog" => "10000",
"net.core.rmem_max" => "10000"
)
)
)
)
)
end
end

describe "pool-02" do
Expand Down Expand Up @@ -303,6 +319,21 @@
)
)
end

it "has the expected linux node config sysctls" do
expect(data['nodePools']).to include(
including(
"name" => "pool-02",
"config" => including(
"linuxNodeConfig" => including(
"sysctls" => including(
"net.core.netdev_max_backlog" => "10000"
)
)
)
)
)
end
end

describe "pool-03" do
Expand Down Expand Up @@ -396,6 +427,21 @@
)
)
end

it "has the expected linux node config sysctls" do
expect(data['nodePools']).to include(
including(
"name" => "pool-03",
"config" => including(
"linuxNodeConfig" => including(
"sysctls" => including(
"net.core.netdev_max_backlog" => "20000"
)
)
)
)
)
end
end
end
end
Expand Down

0 comments on commit 98826e6

Please sign in to comment.