From e7b08850aa667d9d091c1c9108865854f81596d2 Mon Sep 17 00:00:00 2001 From: drfaust92 Date: Sat, 24 Aug 2024 18:34:02 -0400 Subject: [PATCH 1/8] container - add hugepages config --- .../services/container/node_config.go.erb | 66 ++++++++++++++++- .../resource_container_node_pool_test.go.erb | 72 +++++++++++++++++++ .../docs/r/container_cluster.html.markdown | 8 +++ 3 files changed, 144 insertions(+), 2 deletions(-) diff --git a/mmv1/third_party/terraform/services/container/node_config.go.erb b/mmv1/third_party/terraform/services/container/node_config.go.erb index f03dbaa03537..a1ded9350b7e 100644 --- a/mmv1/third_party/terraform/services/container/node_config.go.erb +++ b/mmv1/third_party/terraform/services/container/node_config.go.erb @@ -646,6 +646,26 @@ func schemaNodeConfig() *schema.Schema { Description: `cgroupMode specifies the cgroup mode to be used on the node.`, DiffSuppressFunc: tpgresource.EmptyOrDefaultStringSuppress("CGROUP_MODE_UNSPECIFIED"), }, + "hugepages_config": { + Type: schema.TypeList, + Optional: true, + MaxItems: 1, + Description: `Amounts for 2M and 1G hugepages.`, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "hugepage_size_2m": { + Type: schema.TypeInt, + Optional: true, + Description: `Amount of 2M hugepages.`, + }, + "hugepage_size_1g": { + Type: schema.TypeInt, + Optional: true, + Description: `Amount of 1G hugepages.`, + }, + }, + }, + }, }, }, }, @@ -1245,6 +1265,10 @@ func expandLinuxNodeConfig(v interface{}) *container.LinuxNodeConfig { linuxNodeConfig.CgroupMode = cgroupMode } + if v, ok := cfg["hugepages_config"]; ok { + linuxNodeConfig.Hugepages = expandHugepagesConfig(v) + } + return linuxNodeConfig } @@ -1269,6 +1293,32 @@ func expandCgroupMode(cfg map[string]interface{}) string { return cgroupMode.(string) } +func expandHugepagesConfig(v interface{}) *container.HugepagesConfig { + if v == nil { + return nil + } + ls := v.([]interface{}) + if len(ls) == 0 { + return nil + } + if ls[0] == nil { + return &container.HugepagesConfig{} + } + cfg := ls[0].(map[string]interface{}) + + hugepagesConfig := &container.HugepagesConfig{} + + if v, ok := cfg["hugepage_size_2m"]; ok { + hugepagesConfig.HugepageSize2m = int64(v.(int)) + } + + if v, ok := cfg["hugepage_size_1g"]; ok { + hugepagesConfig.HugepageSize1g = int64(v.(int)) + } + + return hugepagesConfig +} + func expandContainerdConfig(v interface{}) *container.ContainerdConfig { if v == nil { return nil @@ -1799,8 +1849,20 @@ func flattenLinuxNodeConfig(c *container.LinuxNodeConfig) []map[string]interface result := []map[string]interface{}{} if c != nil { result = append(result, map[string]interface{}{ - "sysctls": c.Sysctls, - "cgroup_mode": c.CgroupMode, + "sysctls": c.Sysctls, + "cgroup_mode": c.CgroupMode, + "hugepages_config": flattenHugepagesConfig(c.Hugepages), + }) + } + return result +} + +func flattenHugepagesConfig(c *container.HugepagesConfig) []map[string]interface{} { + result := []map[string]interface{}{} + if c != nil { + result = append(result, map[string]interface{}{ + "hugepage_size_2m": c.HugepageSize2m, + "hugepage_size_1g": c.HugepageSize1g, }) } return result diff --git a/mmv1/third_party/terraform/services/container/resource_container_node_pool_test.go.erb b/mmv1/third_party/terraform/services/container/resource_container_node_pool_test.go.erb index 5adcfc374cc3..c2da30e3befc 100644 --- a/mmv1/third_party/terraform/services/container/resource_container_node_pool_test.go.erb +++ b/mmv1/third_party/terraform/services/container/resource_container_node_pool_test.go.erb @@ -671,6 +671,40 @@ func TestAccContainerNodePool_withCgroupMode(t *testing.T) { }) } +func TestAccContainerNodePool_withHugepageConfig(t *testing.T) { + t.Parallel() + + cluster := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10)) + np := fmt.Sprintf("tf-test-np-%s", acctest.RandString(t, 10)) + networkName := acctest.BootstrapSharedTestNetwork(t, "gke-cluster") + subnetworkName := acctest.BootstrapSubnet(t, "gke-cluster", networkName) + + acctest.VcrTest(t, resource.TestCase{ + PreCheck: func() { acctest.AccTestPreCheck(t) }, + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), + CheckDestroy: testAccCheckContainerClusterDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccContainerNodePool_withHugepageConfig(cluster, np, networkName, subnetworkName, 1), + }, + { + ResourceName: "google_container_node_pool.np", + ImportState: true, + ImportStateVerify: true, + }, + // Perform an update. + { + Config: testAccContainerNodePool_withHugepageConfig(cluster, np, networkName, subnetworkName, 1), + }, + { + ResourceName: "google_container_node_pool.np", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + func TestAccContainerNodePool_withNetworkConfig(t *testing.T) { t.Parallel() @@ -3387,6 +3421,44 @@ resource "google_container_node_pool" "with_tier1_net" { `, network, cluster, np, np, np, np, netTier) } + +func testAccContainerNodePool_withHugepageConfig(cluster, np, networkName, subnetworkName string, hugepage int) string { + return fmt.Sprintf(` +data "google_container_engine_versions" "central1a" { + location = "us-central1-a" +} + +resource "google_container_cluster" "cluster" { + name = "%s" + location = "us-central1-a" + initial_node_count = 1 + min_master_version = data.google_container_engine_versions.central1a.latest_master_version + deletion_protection = false + network = "%s" + subnetwork = "%s" +} + +resource "google_container_node_pool" "np" { + name = "%s" + location = "us-central1-a" + cluster = google_container_cluster.cluster.name + initial_node_count = 1 + node_config { + image_type = "COS_CONTAINERD" + linux_node_config { + hugepages_config { + hugepage_size_2m = %d + } + } + oauth_scopes = [ + "https://www.googleapis.com/auth/logging.write", + "https://www.googleapis.com/auth/monitoring", + ] + } +} +`, cluster, networkName, subnetworkName, np, hugepage) +} + func testAccContainerNodePool_withMultiNicNetworkConfig(cluster, np, network string) string { return fmt.Sprintf(` resource "google_compute_network" "container_network" { diff --git a/mmv1/third_party/terraform/website/docs/r/container_cluster.html.markdown b/mmv1/third_party/terraform/website/docs/r/container_cluster.html.markdown index df2af254ebee..c4fc1f7c3a78 100644 --- a/mmv1/third_party/terraform/website/docs/r/container_cluster.html.markdown +++ b/mmv1/third_party/terraform/website/docs/r/container_cluster.html.markdown @@ -1328,6 +1328,14 @@ linux_node_config { * `CGROUP_MODE_V1`: CGROUP_MODE_V1 specifies to use cgroupv1 for the cgroup configuration on the node image. * `CGROUP_MODE_V2`: CGROUP_MODE_V2 specifies to use cgroupv2 for the cgroup configuration on the node image. +* `hugepages_config` - (Optional) Amounts for 2M and 1G hugepages. Structure is [documented below](#nested_hugepages_config). + +The `hugepages_config` block supports: + +* `hugepage_size_2m` - (Optional) Amount of 2M hugepages. + +* `hugepage_size_1g` - (Optional) Amount of 1G hugepages. + The `containerd_config` block supports: * `private_registry_access_config` (Optional) - Configuration for private container registries. There are two fields in this config: From b69674d1646fcaefdee3588fe14f954ce6c09099 Mon Sep 17 00:00:00 2001 From: Ilia Lazebnik Date: Sat, 7 Sep 2024 00:55:38 +0300 Subject: [PATCH 2/8] Update mmv1/third_party/terraform/services/container/resource_container_node_pool_test.go.erb Co-authored-by: Will Yardley --- .../services/container/resource_container_node_pool_test.go.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mmv1/third_party/terraform/services/container/resource_container_node_pool_test.go.erb b/mmv1/third_party/terraform/services/container/resource_container_node_pool_test.go.erb index c2da30e3befc..59d65de8719d 100644 --- a/mmv1/third_party/terraform/services/container/resource_container_node_pool_test.go.erb +++ b/mmv1/third_party/terraform/services/container/resource_container_node_pool_test.go.erb @@ -694,7 +694,7 @@ func TestAccContainerNodePool_withHugepageConfig(t *testing.T) { }, // Perform an update. { - Config: testAccContainerNodePool_withHugepageConfig(cluster, np, networkName, subnetworkName, 1), + Config: testAccContainerNodePool_withHugepageConfig(cluster, np, networkName, subnetworkName, 2), }, { ResourceName: "google_container_node_pool.np", From eb68708ce62d385b8fc20397a95a5a8cc9f2bbec Mon Sep 17 00:00:00 2001 From: drfaust92 Date: Fri, 6 Sep 2024 19:30:59 -0400 Subject: [PATCH 3/8] container - add hugepages config Signed-off-by: drfaust92 --- .../services/container/resource_container_node_pool_test.go.erb | 1 + 1 file changed, 1 insertion(+) diff --git a/mmv1/third_party/terraform/services/container/resource_container_node_pool_test.go.erb b/mmv1/third_party/terraform/services/container/resource_container_node_pool_test.go.erb index 59d65de8719d..f443b8cd9121 100644 --- a/mmv1/third_party/terraform/services/container/resource_container_node_pool_test.go.erb +++ b/mmv1/third_party/terraform/services/container/resource_container_node_pool_test.go.erb @@ -3448,6 +3448,7 @@ resource "google_container_node_pool" "np" { linux_node_config { hugepages_config { hugepage_size_2m = %d + hugepage_size_1g = %d } } oauth_scopes = [ From cfcdd0b7da506446f701ad86b387ef2fa7722f11 Mon Sep 17 00:00:00 2001 From: drfaust92 Date: Fri, 6 Sep 2024 19:39:05 -0400 Subject: [PATCH 4/8] container - add hugepages config Signed-off-by: drfaust92 --- .../services/container/resource_container_node_pool_test.go.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mmv1/third_party/terraform/services/container/resource_container_node_pool_test.go.erb b/mmv1/third_party/terraform/services/container/resource_container_node_pool_test.go.erb index f443b8cd9121..94e3b33b0aa2 100644 --- a/mmv1/third_party/terraform/services/container/resource_container_node_pool_test.go.erb +++ b/mmv1/third_party/terraform/services/container/resource_container_node_pool_test.go.erb @@ -3448,7 +3448,7 @@ resource "google_container_node_pool" "np" { linux_node_config { hugepages_config { hugepage_size_2m = %d - hugepage_size_1g = %d + hugepage_size_1g = %d } } oauth_scopes = [ From 0754ad746f2f3b319c54a1f8dbcda26b94945cee Mon Sep 17 00:00:00 2001 From: drfaust92 Date: Fri, 6 Sep 2024 19:39:51 -0400 Subject: [PATCH 5/8] container - add hugepages config Signed-off-by: drfaust92 --- .../container/resource_container_node_pool_test.go.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mmv1/third_party/terraform/services/container/resource_container_node_pool_test.go.erb b/mmv1/third_party/terraform/services/container/resource_container_node_pool_test.go.erb index 94e3b33b0aa2..15fa1e9df70b 100644 --- a/mmv1/third_party/terraform/services/container/resource_container_node_pool_test.go.erb +++ b/mmv1/third_party/terraform/services/container/resource_container_node_pool_test.go.erb @@ -3434,8 +3434,8 @@ resource "google_container_cluster" "cluster" { initial_node_count = 1 min_master_version = data.google_container_engine_versions.central1a.latest_master_version deletion_protection = false - network = "%s" - subnetwork = "%s" + network = "%s" + subnetwork = "%s" } resource "google_container_node_pool" "np" { From 6fb8b1496c75559be0686d761eca8d2d3a25d9a6 Mon Sep 17 00:00:00 2001 From: drfaust92 Date: Tue, 17 Sep 2024 09:46:06 -0400 Subject: [PATCH 6/8] fix test Signed-off-by: drfaust92 --- .../services/container/resource_container_node_pool_test.go.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mmv1/third_party/terraform/services/container/resource_container_node_pool_test.go.erb b/mmv1/third_party/terraform/services/container/resource_container_node_pool_test.go.erb index 15fa1e9df70b..2b75237c45d4 100644 --- a/mmv1/third_party/terraform/services/container/resource_container_node_pool_test.go.erb +++ b/mmv1/third_party/terraform/services/container/resource_container_node_pool_test.go.erb @@ -3457,7 +3457,7 @@ resource "google_container_node_pool" "np" { ] } } -`, cluster, networkName, subnetworkName, np, hugepage) +`, cluster, networkName, subnetworkName, np, hugepage, hugepage) } func testAccContainerNodePool_withMultiNicNetworkConfig(cluster, np, network string) string { From 1ab3c6a8c1da46d6e634ac1339e3756752710523 Mon Sep 17 00:00:00 2001 From: drfaust92 Date: Tue, 17 Sep 2024 10:39:57 -0400 Subject: [PATCH 7/8] fix test Signed-off-by: drfaust92 --- .ruby-version | 2 +- .../container/resource_container_node_pool_test.go.erb | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.ruby-version b/.ruby-version index fd2a01863fdd..944880fa15e8 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -3.1.0 +3.2.0 diff --git a/mmv1/third_party/terraform/services/container/resource_container_node_pool_test.go.erb b/mmv1/third_party/terraform/services/container/resource_container_node_pool_test.go.erb index 2b75237c45d4..05018f304885 100644 --- a/mmv1/third_party/terraform/services/container/resource_container_node_pool_test.go.erb +++ b/mmv1/third_party/terraform/services/container/resource_container_node_pool_test.go.erb @@ -3444,7 +3444,8 @@ resource "google_container_node_pool" "np" { cluster = google_container_cluster.cluster.name initial_node_count = 1 node_config { - image_type = "COS_CONTAINERD" + image_type = "COS_CONTAINERD" + machine_type = "c2d-standard-2" # This is required for hugepage_size_1g https://cloud.google.com/kubernetes-engine/docs/how-to/node-system-config#huge-page-options linux_node_config { hugepages_config { hugepage_size_2m = %d From 0ec21575740f59206318fd78048c8ee6a338e8ac Mon Sep 17 00:00:00 2001 From: drfaust92 Date: Tue, 17 Sep 2024 10:42:11 -0400 Subject: [PATCH 8/8] fix test Signed-off-by: drfaust92 --- .ruby-version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.ruby-version b/.ruby-version index 944880fa15e8..fd2a01863fdd 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -3.2.0 +3.1.0