Skip to content

Commit 98826e6

Browse files
m10evTencho Tenevbharathkkb
authored
feat: add support for Linux node config (terraform-google-modules#782)
* 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 <[email protected]> * Generate modules Co-authored-by: Tencho Tenev <[email protected]> Co-authored-by: Bharath KKB <[email protected]>
1 parent aa551d5 commit 98826e6

File tree

21 files changed

+242
-1
lines changed

21 files changed

+242
-1
lines changed

autogen/main/cluster.tf.tmpl

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ resource "google_container_cluster" "primary" {
9898
}
9999
}
100100
}
101-
101+
102102
vertical_pod_autoscaling {
103103
enabled = var.enable_vertical_pod_autoscaling
104104
}
@@ -565,6 +565,20 @@ resource "google_container_node_pool" "pools" {
565565
cpu_manager_policy = lookup(each.value, "cpu_manager_policy")
566566
}
567567
}
568+
569+
dynamic "linux_node_config" {
570+
for_each = merge(
571+
local.node_pools_linux_node_configs_sysctls["all"],
572+
local.node_pools_linux_node_configs_sysctls[each.value["name"]]
573+
) != {} ? [1] : []
574+
575+
content {
576+
sysctls = merge(
577+
local.node_pools_linux_node_configs_sysctls["all"],
578+
local.node_pools_linux_node_configs_sysctls[each.value["name"]]
579+
)
580+
}
581+
}
568582
{% endif %}
569583

570584
shielded_instance_config {

autogen/main/variables.tf.tmpl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,19 @@ variable "node_pools_metadata" {
194194
default-node-pool = {}
195195
}
196196
}
197+
{% if beta_cluster %}
198+
199+
variable "node_pools_linux_node_configs_sysctls" {
200+
type = map(map(string))
201+
description = "Map of maps containing linux node config sysctls by node-pool name"
202+
203+
# Default is being set in variables_defaults.tf
204+
default = {
205+
all = {}
206+
default-node-pool = {}
207+
}
208+
}
209+
{% endif %}
197210

198211
variable "resource_usage_export_dataset_id" {
199212
type = string

autogen/main/variables_defaults.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,16 @@ locals {
6969
),
7070
var.node_pools_oauth_scopes
7171
)
72+
{% if beta_cluster %}
73+
74+
node_pools_linux_node_configs_sysctls = merge(
75+
{ all = {} },
76+
{ default-node-pool = {} },
77+
zipmap(
78+
[for node_pool in var.node_pools : node_pool["name"]],
79+
[for node_pool in var.node_pools : {}]
80+
),
81+
var.node_pools_linux_node_configs_sysctls
82+
)
83+
{% endif %}
7284
}

examples/node_pool/main.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,16 @@ module "gke" {
121121
"pool-01-example",
122122
]
123123
}
124+
125+
node_pools_linux_node_configs_sysctls = {
126+
all = {
127+
"net.core.netdev_max_backlog" = "10000"
128+
}
129+
pool-01 = {
130+
"net.core.rmem_max" = "10000"
131+
}
132+
pool-03 = {
133+
"net.core.netdev_max_backlog" = "20000"
134+
}
135+
}
124136
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ Then perform the following commands on the root folder:
220220
| node\_metadata | Specifies how node metadata is exposed to the workload running on the node | `string` | `"GKE_METADATA_SERVER"` | no |
221221
| node\_pools | List of maps containing node pools | `list(map(string))` | <pre>[<br> {<br> "name": "default-node-pool"<br> }<br>]</pre> | no |
222222
| 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 |
223+
| 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 |
223224
| 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 |
224225
| 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 |
225226
| 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 |

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,20 @@ resource "google_container_node_pool" "pools" {
522522
}
523523
}
524524

525+
dynamic "linux_node_config" {
526+
for_each = merge(
527+
local.node_pools_linux_node_configs_sysctls["all"],
528+
local.node_pools_linux_node_configs_sysctls[each.value["name"]]
529+
) != {} ? [1] : []
530+
531+
content {
532+
sysctls = merge(
533+
local.node_pools_linux_node_configs_sysctls["all"],
534+
local.node_pools_linux_node_configs_sysctls[each.value["name"]]
535+
)
536+
}
537+
}
538+
525539
shielded_instance_config {
526540
enable_secure_boot = lookup(each.value, "enable_secure_boot", false)
527541
enable_integrity_monitoring = lookup(each.value, "enable_integrity_monitoring", true)

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,17 @@ variable "node_pools_metadata" {
193193
}
194194
}
195195

196+
variable "node_pools_linux_node_configs_sysctls" {
197+
type = map(map(string))
198+
description = "Map of maps containing linux node config sysctls by node-pool name"
199+
200+
# Default is being set in variables_defaults.tf
201+
default = {
202+
all = {}
203+
default-node-pool = {}
204+
}
205+
}
206+
196207
variable "resource_usage_export_dataset_id" {
197208
type = string
198209
description = "The ID of a BigQuery Dataset for using BigQuery as the destination of resource usage export."

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,14 @@ locals {
6969
),
7070
var.node_pools_oauth_scopes
7171
)
72+
73+
node_pools_linux_node_configs_sysctls = merge(
74+
{ all = {} },
75+
{ default-node-pool = {} },
76+
zipmap(
77+
[for node_pool in var.node_pools : node_pool["name"]],
78+
[for node_pool in var.node_pools : {}]
79+
),
80+
var.node_pools_linux_node_configs_sysctls
81+
)
7282
}

modules/beta-private-cluster/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ Then perform the following commands on the root folder:
198198
| node\_metadata | Specifies how node metadata is exposed to the workload running on the node | `string` | `"GKE_METADATA_SERVER"` | no |
199199
| node\_pools | List of maps containing node pools | `list(map(string))` | <pre>[<br> {<br> "name": "default-node-pool"<br> }<br>]</pre> | no |
200200
| 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 |
201+
| 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 |
201202
| 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 |
202203
| 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 |
203204
| 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 |

modules/beta-private-cluster/cluster.tf

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,20 @@ resource "google_container_node_pool" "pools" {
438438
}
439439
}
440440

441+
dynamic "linux_node_config" {
442+
for_each = merge(
443+
local.node_pools_linux_node_configs_sysctls["all"],
444+
local.node_pools_linux_node_configs_sysctls[each.value["name"]]
445+
) != {} ? [1] : []
446+
447+
content {
448+
sysctls = merge(
449+
local.node_pools_linux_node_configs_sysctls["all"],
450+
local.node_pools_linux_node_configs_sysctls[each.value["name"]]
451+
)
452+
}
453+
}
454+
441455
shielded_instance_config {
442456
enable_secure_boot = lookup(each.value, "enable_secure_boot", false)
443457
enable_integrity_monitoring = lookup(each.value, "enable_integrity_monitoring", true)

modules/beta-private-cluster/variables.tf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,17 @@ variable "node_pools_metadata" {
193193
}
194194
}
195195

196+
variable "node_pools_linux_node_configs_sysctls" {
197+
type = map(map(string))
198+
description = "Map of maps containing linux node config sysctls by node-pool name"
199+
200+
# Default is being set in variables_defaults.tf
201+
default = {
202+
all = {}
203+
default-node-pool = {}
204+
}
205+
}
206+
196207
variable "resource_usage_export_dataset_id" {
197208
type = string
198209
description = "The ID of a BigQuery Dataset for using BigQuery as the destination of resource usage export."

modules/beta-private-cluster/variables_defaults.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,14 @@ locals {
6969
),
7070
var.node_pools_oauth_scopes
7171
)
72+
73+
node_pools_linux_node_configs_sysctls = merge(
74+
{ all = {} },
75+
{ default-node-pool = {} },
76+
zipmap(
77+
[for node_pool in var.node_pools : node_pool["name"]],
78+
[for node_pool in var.node_pools : {}]
79+
),
80+
var.node_pools_linux_node_configs_sysctls
81+
)
7282
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ Then perform the following commands on the root folder:
209209
| node\_metadata | Specifies how node metadata is exposed to the workload running on the node | `string` | `"GKE_METADATA_SERVER"` | no |
210210
| node\_pools | List of maps containing node pools | `list(map(string))` | <pre>[<br> {<br> "name": "default-node-pool"<br> }<br>]</pre> | no |
211211
| 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 |
212+
| 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 |
212213
| 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 |
213214
| 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 |
214215
| 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 |

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,20 @@ resource "google_container_node_pool" "pools" {
503503
}
504504
}
505505

506+
dynamic "linux_node_config" {
507+
for_each = merge(
508+
local.node_pools_linux_node_configs_sysctls["all"],
509+
local.node_pools_linux_node_configs_sysctls[each.value["name"]]
510+
) != {} ? [1] : []
511+
512+
content {
513+
sysctls = merge(
514+
local.node_pools_linux_node_configs_sysctls["all"],
515+
local.node_pools_linux_node_configs_sysctls[each.value["name"]]
516+
)
517+
}
518+
}
519+
506520
shielded_instance_config {
507521
enable_secure_boot = lookup(each.value, "enable_secure_boot", false)
508522
enable_integrity_monitoring = lookup(each.value, "enable_integrity_monitoring", true)

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,17 @@ variable "node_pools_metadata" {
193193
}
194194
}
195195

196+
variable "node_pools_linux_node_configs_sysctls" {
197+
type = map(map(string))
198+
description = "Map of maps containing linux node config sysctls by node-pool name"
199+
200+
# Default is being set in variables_defaults.tf
201+
default = {
202+
all = {}
203+
default-node-pool = {}
204+
}
205+
}
206+
196207
variable "resource_usage_export_dataset_id" {
197208
type = string
198209
description = "The ID of a BigQuery Dataset for using BigQuery as the destination of resource usage export."

modules/beta-public-cluster-update-variant/variables_defaults.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,14 @@ locals {
6969
),
7070
var.node_pools_oauth_scopes
7171
)
72+
73+
node_pools_linux_node_configs_sysctls = merge(
74+
{ all = {} },
75+
{ default-node-pool = {} },
76+
zipmap(
77+
[for node_pool in var.node_pools : node_pool["name"]],
78+
[for node_pool in var.node_pools : {}]
79+
),
80+
var.node_pools_linux_node_configs_sysctls
81+
)
7282
}

modules/beta-public-cluster/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ Then perform the following commands on the root folder:
187187
| node\_metadata | Specifies how node metadata is exposed to the workload running on the node | `string` | `"GKE_METADATA_SERVER"` | no |
188188
| node\_pools | List of maps containing node pools | `list(map(string))` | <pre>[<br> {<br> "name": "default-node-pool"<br> }<br>]</pre> | no |
189189
| 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 |
190+
| 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 |
190191
| 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 |
191192
| 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 |
192193
| 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 |

modules/beta-public-cluster/cluster.tf

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,20 @@ resource "google_container_node_pool" "pools" {
419419
}
420420
}
421421

422+
dynamic "linux_node_config" {
423+
for_each = merge(
424+
local.node_pools_linux_node_configs_sysctls["all"],
425+
local.node_pools_linux_node_configs_sysctls[each.value["name"]]
426+
) != {} ? [1] : []
427+
428+
content {
429+
sysctls = merge(
430+
local.node_pools_linux_node_configs_sysctls["all"],
431+
local.node_pools_linux_node_configs_sysctls[each.value["name"]]
432+
)
433+
}
434+
}
435+
422436
shielded_instance_config {
423437
enable_secure_boot = lookup(each.value, "enable_secure_boot", false)
424438
enable_integrity_monitoring = lookup(each.value, "enable_integrity_monitoring", true)

modules/beta-public-cluster/variables.tf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,17 @@ variable "node_pools_metadata" {
193193
}
194194
}
195195

196+
variable "node_pools_linux_node_configs_sysctls" {
197+
type = map(map(string))
198+
description = "Map of maps containing linux node config sysctls by node-pool name"
199+
200+
# Default is being set in variables_defaults.tf
201+
default = {
202+
all = {}
203+
default-node-pool = {}
204+
}
205+
}
206+
196207
variable "resource_usage_export_dataset_id" {
197208
type = string
198209
description = "The ID of a BigQuery Dataset for using BigQuery as the destination of resource usage export."

modules/beta-public-cluster/variables_defaults.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,14 @@ locals {
6969
),
7070
var.node_pools_oauth_scopes
7171
)
72+
73+
node_pools_linux_node_configs_sysctls = merge(
74+
{ all = {} },
75+
{ default-node-pool = {} },
76+
zipmap(
77+
[for node_pool in var.node_pools : node_pool["name"]],
78+
[for node_pool in var.node_pools : {}]
79+
),
80+
var.node_pools_linux_node_configs_sysctls
81+
)
7282
}

test/integration/node_pool/controls/gcloud.rb

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,22 @@
174174
)
175175
)
176176
end
177+
178+
it "has the expected linux node config sysctls" do
179+
expect(data['nodePools']).to include(
180+
including(
181+
"name" => "pool-01",
182+
"config" => including(
183+
"linuxNodeConfig" => including(
184+
"sysctls" => including(
185+
"net.core.netdev_max_backlog" => "10000",
186+
"net.core.rmem_max" => "10000"
187+
)
188+
)
189+
)
190+
)
191+
)
192+
end
177193
end
178194

179195
describe "pool-02" do
@@ -303,6 +319,21 @@
303319
)
304320
)
305321
end
322+
323+
it "has the expected linux node config sysctls" do
324+
expect(data['nodePools']).to include(
325+
including(
326+
"name" => "pool-02",
327+
"config" => including(
328+
"linuxNodeConfig" => including(
329+
"sysctls" => including(
330+
"net.core.netdev_max_backlog" => "10000"
331+
)
332+
)
333+
)
334+
)
335+
)
336+
end
306337
end
307338

308339
describe "pool-03" do
@@ -396,6 +427,21 @@
396427
)
397428
)
398429
end
430+
431+
it "has the expected linux node config sysctls" do
432+
expect(data['nodePools']).to include(
433+
including(
434+
"name" => "pool-03",
435+
"config" => including(
436+
"linuxNodeConfig" => including(
437+
"sysctls" => including(
438+
"net.core.netdev_max_backlog" => "20000"
439+
)
440+
)
441+
)
442+
)
443+
)
444+
end
399445
end
400446
end
401447
end

0 commit comments

Comments
 (0)