Skip to content

Commit 80252f3

Browse files
authored
feat: Add support for CPU quota configs for node pools (#1032)
1 parent 04f7502 commit 80252f3

File tree

12 files changed

+76
-25
lines changed

12 files changed

+76
-25
lines changed

Diff for: autogen/main/README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,9 @@ The node_pools variable takes the following parameters:
176176
| autoscaling | Configuration required by cluster autoscaler to adjust the size of the node pool to the current cluster usage | true | Optional |
177177
| auto_upgrade | Whether the nodes will be automatically upgraded | true (if cluster is regional) | Optional |
178178
{% if beta_cluster %}
179-
| cpu_manager_policy | The CPU manager policy on the node. One of "none" or "static". | "none" | Optional |
179+
| cpu_manager_policy | The CPU manager policy on the node. One of "none" or "static". | "static" | Optional |
180+
| cpu_cfs_quota | Enforces the Pod's CPU limit. Setting this value to false means that the CPU limits for Pods are ignored | null | Optional |
181+
| cpu_cfs_quota_period | The CPU CFS quota period value, which specifies the period of how often a cgroup's access to CPU resources should be reallocated | null | Optional |
180182
{% endif %}
181183
| disk_size_gb | Size of the disk attached to each node, specified in GB. The smallest allowed disk size is 10GB | 100 | Optional |
182184
| disk_type | Type of the disk attached to each node (e.g. 'pd-standard' or 'pd-ssd') | pd-standard | Optional |

Diff for: autogen/main/cluster.tf.tmpl

+7-2
Original file line numberDiff line numberDiff line change
@@ -588,10 +588,15 @@ resource "google_container_node_pool" "pools" {
588588
boot_disk_kms_key = lookup(each.value, "boot_disk_kms_key", "")
589589

590590
dynamic "kubelet_config" {
591-
for_each = contains(keys(each.value), "cpu_manager_policy") ? [1] : []
591+
for_each = length(setintersection(
592+
keys(each.value),
593+
["cpu_manager_policy", "cpu_cfs_quota", "cpu_cfs_quota_period"]
594+
)) != 0 ? [1] : []
592595

593596
content {
594-
cpu_manager_policy = lookup(each.value, "cpu_manager_policy")
597+
cpu_manager_policy = lookup(each.value, "cpu_manager_policy", "static")
598+
cpu_cfs_quota = lookup(each.value, "cpu_cfs_quota", null)
599+
cpu_cfs_quota_period = lookup(each.value, "cpu_cfs_quota_period", null)
595600
}
596601
}
597602

Diff for: examples/node_pool/main.tf

+12-10
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,18 @@ module "gke" {
6969
service_account = var.compute_engine_service_account
7070
},
7171
{
72-
name = "pool-03"
73-
machine_type = "n1-standard-2"
74-
node_locations = "${var.region}-b,${var.region}-c"
75-
autoscaling = false
76-
node_count = 2
77-
disk_type = "pd-standard"
78-
auto_upgrade = true
79-
service_account = var.compute_engine_service_account
80-
pod_range = "test"
81-
sandbox_enabled = true
72+
name = "pool-03"
73+
machine_type = "n1-standard-2"
74+
node_locations = "${var.region}-b,${var.region}-c"
75+
autoscaling = false
76+
node_count = 2
77+
disk_type = "pd-standard"
78+
auto_upgrade = true
79+
service_account = var.compute_engine_service_account
80+
pod_range = "test"
81+
sandbox_enabled = true
82+
cpu_manager_policy = "static"
83+
cpu_cfs_quota = true
8284
},
8385
]
8486

Diff for: modules/beta-private-cluster-update-variant/README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,9 @@ The node_pools variable takes the following parameters:
298298
| auto_repair | Whether the nodes will be automatically repaired | true | Optional |
299299
| autoscaling | Configuration required by cluster autoscaler to adjust the size of the node pool to the current cluster usage | true | Optional |
300300
| auto_upgrade | Whether the nodes will be automatically upgraded | true (if cluster is regional) | Optional |
301-
| cpu_manager_policy | The CPU manager policy on the node. One of "none" or "static". | "none" | Optional |
301+
| cpu_manager_policy | The CPU manager policy on the node. One of "none" or "static". | "static" | Optional |
302+
| cpu_cfs_quota | Enforces the Pod's CPU limit. Setting this value to false means that the CPU limits for Pods are ignored | null | Optional |
303+
| cpu_cfs_quota_period | The CPU CFS quota period value, which specifies the period of how often a cgroup's access to CPU resources should be reallocated | null | Optional |
302304
| disk_size_gb | Size of the disk attached to each node, specified in GB. The smallest allowed disk size is 10GB | 100 | Optional |
303305
| disk_type | Type of the disk attached to each node (e.g. 'pd-standard' or 'pd-ssd') | pd-standard | Optional |
304306
| effect | Effect for the taint | | Required |

Diff for: modules/beta-private-cluster-update-variant/cluster.tf

+7-2
Original file line numberDiff line numberDiff line change
@@ -534,10 +534,15 @@ resource "google_container_node_pool" "pools" {
534534
boot_disk_kms_key = lookup(each.value, "boot_disk_kms_key", "")
535535

536536
dynamic "kubelet_config" {
537-
for_each = contains(keys(each.value), "cpu_manager_policy") ? [1] : []
537+
for_each = length(setintersection(
538+
keys(each.value),
539+
["cpu_manager_policy", "cpu_cfs_quota", "cpu_cfs_quota_period"]
540+
)) != 0 ? [1] : []
538541

539542
content {
540-
cpu_manager_policy = lookup(each.value, "cpu_manager_policy")
543+
cpu_manager_policy = lookup(each.value, "cpu_manager_policy", "static")
544+
cpu_cfs_quota = lookup(each.value, "cpu_cfs_quota", null)
545+
cpu_cfs_quota_period = lookup(each.value, "cpu_cfs_quota_period", null)
541546
}
542547
}
543548

Diff for: modules/beta-private-cluster/README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,9 @@ The node_pools variable takes the following parameters:
276276
| auto_repair | Whether the nodes will be automatically repaired | true | Optional |
277277
| autoscaling | Configuration required by cluster autoscaler to adjust the size of the node pool to the current cluster usage | true | Optional |
278278
| auto_upgrade | Whether the nodes will be automatically upgraded | true (if cluster is regional) | Optional |
279-
| cpu_manager_policy | The CPU manager policy on the node. One of "none" or "static". | "none" | Optional |
279+
| cpu_manager_policy | The CPU manager policy on the node. One of "none" or "static". | "static" | Optional |
280+
| cpu_cfs_quota | Enforces the Pod's CPU limit. Setting this value to false means that the CPU limits for Pods are ignored | null | Optional |
281+
| cpu_cfs_quota_period | The CPU CFS quota period value, which specifies the period of how often a cgroup's access to CPU resources should be reallocated | null | Optional |
280282
| disk_size_gb | Size of the disk attached to each node, specified in GB. The smallest allowed disk size is 10GB | 100 | Optional |
281283
| disk_type | Type of the disk attached to each node (e.g. 'pd-standard' or 'pd-ssd') | pd-standard | Optional |
282284
| effect | Effect for the taint | | Required |

Diff for: modules/beta-private-cluster/cluster.tf

+7-2
Original file line numberDiff line numberDiff line change
@@ -450,10 +450,15 @@ resource "google_container_node_pool" "pools" {
450450
boot_disk_kms_key = lookup(each.value, "boot_disk_kms_key", "")
451451

452452
dynamic "kubelet_config" {
453-
for_each = contains(keys(each.value), "cpu_manager_policy") ? [1] : []
453+
for_each = length(setintersection(
454+
keys(each.value),
455+
["cpu_manager_policy", "cpu_cfs_quota", "cpu_cfs_quota_period"]
456+
)) != 0 ? [1] : []
454457

455458
content {
456-
cpu_manager_policy = lookup(each.value, "cpu_manager_policy")
459+
cpu_manager_policy = lookup(each.value, "cpu_manager_policy", "static")
460+
cpu_cfs_quota = lookup(each.value, "cpu_cfs_quota", null)
461+
cpu_cfs_quota_period = lookup(each.value, "cpu_cfs_quota_period", null)
457462
}
458463
}
459464

Diff for: modules/beta-public-cluster-update-variant/README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,9 @@ The node_pools variable takes the following parameters:
285285
| auto_repair | Whether the nodes will be automatically repaired | true | Optional |
286286
| autoscaling | Configuration required by cluster autoscaler to adjust the size of the node pool to the current cluster usage | true | Optional |
287287
| auto_upgrade | Whether the nodes will be automatically upgraded | true (if cluster is regional) | Optional |
288-
| cpu_manager_policy | The CPU manager policy on the node. One of "none" or "static". | "none" | Optional |
288+
| cpu_manager_policy | The CPU manager policy on the node. One of "none" or "static". | "static" | Optional |
289+
| cpu_cfs_quota | Enforces the Pod's CPU limit. Setting this value to false means that the CPU limits for Pods are ignored | null | Optional |
290+
| cpu_cfs_quota_period | The CPU CFS quota period value, which specifies the period of how often a cgroup's access to CPU resources should be reallocated | null | Optional |
289291
| disk_size_gb | Size of the disk attached to each node, specified in GB. The smallest allowed disk size is 10GB | 100 | Optional |
290292
| disk_type | Type of the disk attached to each node (e.g. 'pd-standard' or 'pd-ssd') | pd-standard | Optional |
291293
| effect | Effect for the taint | | Required |

Diff for: modules/beta-public-cluster-update-variant/cluster.tf

+7-2
Original file line numberDiff line numberDiff line change
@@ -515,10 +515,15 @@ resource "google_container_node_pool" "pools" {
515515
boot_disk_kms_key = lookup(each.value, "boot_disk_kms_key", "")
516516

517517
dynamic "kubelet_config" {
518-
for_each = contains(keys(each.value), "cpu_manager_policy") ? [1] : []
518+
for_each = length(setintersection(
519+
keys(each.value),
520+
["cpu_manager_policy", "cpu_cfs_quota", "cpu_cfs_quota_period"]
521+
)) != 0 ? [1] : []
519522

520523
content {
521-
cpu_manager_policy = lookup(each.value, "cpu_manager_policy")
524+
cpu_manager_policy = lookup(each.value, "cpu_manager_policy", "static")
525+
cpu_cfs_quota = lookup(each.value, "cpu_cfs_quota", null)
526+
cpu_cfs_quota_period = lookup(each.value, "cpu_cfs_quota_period", null)
522527
}
523528
}
524529

Diff for: modules/beta-public-cluster/README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,9 @@ The node_pools variable takes the following parameters:
263263
| auto_repair | Whether the nodes will be automatically repaired | true | Optional |
264264
| autoscaling | Configuration required by cluster autoscaler to adjust the size of the node pool to the current cluster usage | true | Optional |
265265
| auto_upgrade | Whether the nodes will be automatically upgraded | true (if cluster is regional) | Optional |
266-
| cpu_manager_policy | The CPU manager policy on the node. One of "none" or "static". | "none" | Optional |
266+
| cpu_manager_policy | The CPU manager policy on the node. One of "none" or "static". | "static" | Optional |
267+
| cpu_cfs_quota | Enforces the Pod's CPU limit. Setting this value to false means that the CPU limits for Pods are ignored | null | Optional |
268+
| cpu_cfs_quota_period | The CPU CFS quota period value, which specifies the period of how often a cgroup's access to CPU resources should be reallocated | null | Optional |
267269
| disk_size_gb | Size of the disk attached to each node, specified in GB. The smallest allowed disk size is 10GB | 100 | Optional |
268270
| disk_type | Type of the disk attached to each node (e.g. 'pd-standard' or 'pd-ssd') | pd-standard | Optional |
269271
| effect | Effect for the taint | | Required |

Diff for: modules/beta-public-cluster/cluster.tf

+7-2
Original file line numberDiff line numberDiff line change
@@ -431,10 +431,15 @@ resource "google_container_node_pool" "pools" {
431431
boot_disk_kms_key = lookup(each.value, "boot_disk_kms_key", "")
432432

433433
dynamic "kubelet_config" {
434-
for_each = contains(keys(each.value), "cpu_manager_policy") ? [1] : []
434+
for_each = length(setintersection(
435+
keys(each.value),
436+
["cpu_manager_policy", "cpu_cfs_quota", "cpu_cfs_quota_period"]
437+
)) != 0 ? [1] : []
435438

436439
content {
437-
cpu_manager_policy = lookup(each.value, "cpu_manager_policy")
440+
cpu_manager_policy = lookup(each.value, "cpu_manager_policy", "static")
441+
cpu_cfs_quota = lookup(each.value, "cpu_cfs_quota", null)
442+
cpu_cfs_quota_period = lookup(each.value, "cpu_cfs_quota_period", null)
438443
}
439444
}
440445

Diff for: test/integration/node_pool/controls/gcloud.rb

+14
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,20 @@
453453
)
454454
end
455455

456+
it "has the expected kubelet config" do
457+
expect(data['nodePools']).to include(
458+
including(
459+
"name" => "pool-03",
460+
"config" => including(
461+
"kubeletConfig" => including(
462+
"cpuManagerPolicy" => "static",
463+
"cpuCfsQuota" => true
464+
)
465+
)
466+
)
467+
)
468+
end
469+
456470
it "has the expected linux node config sysctls" do
457471
expect(data['nodePools']).to include(
458472
including(

0 commit comments

Comments
 (0)