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 GKE support for threads_per_core option #14106

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/6808.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
container: added support for `advanced_machine_features.threads_per_core`
```
36 changes: 36 additions & 0 deletions google/node_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,24 @@ func schemaNodeConfig() *schema.Schema {
ForceNew: true,
Description: `Setting this field will assign instances of this pool to run on the specified node group. This is useful for running workloads on sole tenant nodes.`,
},

"advanced_machine_features": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Description: `Specifies options for controlling advanced machine features.`,
ForceNew: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"threads_per_core": {
Type: schema.TypeInt,
Required: true,
ForceNew: true,
Description: `The number of threads per physical core. To disable simultaneous multithreading (SMT) set this to 1. If unset, the maximum number of threads supported per core by the underlying processor is assumed.`,
},
},
},
},
},
},
}
Expand Down Expand Up @@ -679,6 +697,13 @@ func expandNodeConfig(v interface{}) *container.NodeConfig {
nc.NodeGroup = v.(string)
}

if v, ok := nodeConfig["advanced_machine_features"]; ok && len(v.([]interface{})) > 0 {
advanced_machine_features := v.([]interface{})[0].(map[string]interface{})
nc.AdvancedMachineFeatures = &container.AdvancedMachineFeatures{
ThreadsPerCore: int64(advanced_machine_features["threads_per_core"].(int)),
}
}

return nc
}

Expand Down Expand Up @@ -797,6 +822,7 @@ func flattenNodeConfig(c *container.NodeConfig) []map[string]interface{} {
"kubelet_config": flattenKubeletConfig(c.KubeletConfig),
"linux_node_config": flattenLinuxNodeConfig(c.LinuxNodeConfig),
"node_group": c.NodeGroup,
"advanced_machine_features": flattenAdvancedMachineFeaturesConfig(c.AdvancedMachineFeatures),
})

if len(c.OauthScopes) > 0 {
Expand All @@ -806,6 +832,16 @@ func flattenNodeConfig(c *container.NodeConfig) []map[string]interface{} {
return config
}

func flattenAdvancedMachineFeaturesConfig(c *container.AdvancedMachineFeatures) []map[string]interface{} {
result := []map[string]interface{}{}
if c != nil {
result = append(result, map[string]interface{}{
"threads_per_core": c.ThreadsPerCore,
})
}
return result
}

func flattenContainerGuestAccelerators(c []*container.AcceleratorConfig) []map[string]interface{} {
result := []map[string]interface{}{}
for _, accel := range c {
Expand Down
56 changes: 55 additions & 1 deletion google/resource_container_node_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ func TestAccContainerNodePool_regionalAutoscaling(t *testing.T) {
})
}

//This test exists to validate a node pool with total size *and* and update to it.
// This test exists to validate a node pool with total size *and* and update to it.
func TestAccContainerNodePool_totalSize(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -1307,6 +1307,60 @@ resource "google_container_node_pool" "np" {
`, cluster, np, placementType)
}

func TestAccContainerNodePool_threadsPerCore(t *testing.T) {
t.Parallel()

cluster := fmt.Sprintf("tf-test-cluster-%s", RandString(t, 10))
np := fmt.Sprintf("tf-test-nodepool-%s", RandString(t, 10))

VcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV5ProviderFactories: ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckContainerNodePoolDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccContainerNodePool_threadsPerCore(cluster, np, 1),
},
{
ResourceName: "google_container_cluster.cluster",
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func testAccContainerNodePool_threadsPerCore(cluster, np string, threadsPerCore int) string {
return fmt.Sprintf(`
resource "google_container_cluster" "cluster" {
name = "%s"
location = "us-central1-a"
initial_node_count = 1

node_config {
machine_type = "c2-standard-4"
advanced_machine_features {
threads_per_core = "%v"
}
}
}

resource "google_container_node_pool" "np" {
name = "%s"
location = "us-central1-a"
cluster = google_container_cluster.cluster.name
initial_node_count = 2

node_config {
machine_type = "c2-standard-4"
advanced_machine_features {
threads_per_core = "%v"
}
}
}
`, cluster, threadsPerCore, np, threadsPerCore)
}

func testAccCheckContainerNodePoolDestroyProducer(t *testing.T) func(s *terraform.State) error {
return func(s *terraform.State) error {
config := GoogleProviderConfig(t)
Expand Down
7 changes: 7 additions & 0 deletions website/docs/r/container_cluster.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -880,6 +880,13 @@ linux_node_config {

* `node_group` - (Optional) Setting this field will assign instances of this pool to run on the specified node group. This is useful for running workloads on [sole tenant nodes](https://cloud.google.com/compute/docs/nodes/sole-tenant-nodes).

* `advanced_machine_features` - (Optional) Specifies options for controlling
advanced machine features. Structure is documented below.

<a name="nested_advanced_machine_features"></a>The `advanced_machine_features` block supports:

* `threads_per_core` - (Required) The number of threads per physical core. To disable simultaneous multithreading (SMT) set this to 1. If unset, the maximum number of threads supported per core by the underlying processor is assumed.

<a name="nested_ephemeral_storage_config"></a>The `ephemeral_storage_config` block supports:

* `local_ssd_count` (Required) - Number of local SSDs to use to back ephemeral storage. Uses NVMe interfaces. Each local SSD is 375 GB in size. If zero, it means to disable using local SSDs as ephemeral storage.
Expand Down