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

container_node_pool : add gvnic support #11240

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/5789.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
container: add support for gvnic to `google_container_node_pool`
```
36 changes: 36 additions & 0 deletions google/node_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,24 @@ func schemaNodeConfig() *schema.Schema {
},
},

"gvnic": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Description: `Enable or disable gvnic in the node pool.`,
ForceNew: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"enabled": {
Type: schema.TypeBool,
Required: true,
ForceNew: true,
Description: `Whether or not gvnic is enabled`,
},
},
},
},

"machine_type": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -336,6 +354,13 @@ func expandNodeConfig(v interface{}) *container.NodeConfig {
}
}

if v, ok := nodeConfig["gvnic"]; ok && len(v.([]interface{})) > 0 {
conf := v.([]interface{})[0].(map[string]interface{})
nc.Gvnic = &container.VirtualNIC{
Enabled: conf["enabled"].(bool),
}
}

if scopes, ok := nodeConfig["oauth_scopes"]; ok {
scopesSet := scopes.(*schema.Set)
scopes := make([]string, scopesSet.Len())
Expand Down Expand Up @@ -459,6 +484,7 @@ func flattenNodeConfig(c *container.NodeConfig) []map[string]interface{} {
"guest_accelerator": flattenContainerGuestAccelerators(c.Accelerators),
"local_ssd_count": c.LocalSsdCount,
"gcfs_config": flattenGcfsConfig(c.GcfsConfig),
"gvnic": flattenGvnic(c.Gvnic),
"service_account": c.ServiceAccount,
"metadata": c.Metadata,
"image_type": c.ImageType,
Expand Down Expand Up @@ -513,6 +539,16 @@ func flattenGcfsConfig(c *container.GcfsConfig) []map[string]interface{} {
return result
}

func flattenGvnic(c *container.VirtualNIC) []map[string]interface{} {
result := []map[string]interface{}{}
if c != nil {
result = append(result, map[string]interface{}{
"enabled": c.Enabled,
})
}
return result
}

func flattenTaints(c []*container.NodeTaint) []map[string]interface{} {
result := []map[string]interface{}{}
for _, taint := range c {
Expand Down
49 changes: 49 additions & 0 deletions google/resource_container_node_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,55 @@ resource "google_container_node_pool" "np" {
`, cluster, np)
}

func TestAccContainerNodePool_gvnic(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) },
Providers: testAccProviders,
CheckDestroy: testAccCheckContainerNodePoolDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccContainerNodePool_gvnic(cluster, np),
},
{
ResourceName: "google_container_node_pool.np",
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func testAccContainerNodePool_gvnic(cluster, np string) string {
return fmt.Sprintf(`
resource "google_container_cluster" "cluster" {
name = "%s"
location = "us-central1-a"
initial_node_count = 1
min_master_version = "1.19"
}

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

node_config {
machine_type = "n1-standard-8"
image_type = "COS_CONTAINERD"
gvnic {
enabled = true
}
}
}
`, cluster, np)
}

func testAccCheckContainerNodePoolDestroyProducer(t *testing.T) func(s *terraform.State) error {
return func(s *terraform.State) error {
config := googleProviderConfig(t)
Expand Down
20 changes: 19 additions & 1 deletion website/docs/r/container_cluster.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ subnetwork in which the cluster's instances are launched.
It can only be disabled if the nodes already do not have network policies enabled.
Defaults to disabled; set `disabled = false` to enable.

* `gcp_filestore_csi_driver_config` - (Optional) The status of the Filestore CSI driver addon,
* `gcp_filestore_csi_driver_config` - (Optional) The status of the Filestore CSI driver addon,
which allows the usage of filestore instance as volumes.
It is disabled by default; set `enabled = true` to enable.

Expand Down Expand Up @@ -649,6 +649,20 @@ gcfs_config {
}
```


* `gvnic` - (Optional) Google Virtual NIC (gVNIC) is a virtual network interface.
Installing the gVNIC driver allows for more efficient traffic transmission across the Google network infrastructure.
gVNIC is an alternative to the virtIO-based ethernet driver. GKE nodes must use a Container-Optimized OS node image.
GKE node version 1.15.11-gke.15 or later
Structure is [documented below](#nested_gvnic).


```hcl
gvnic {
enabled = true
}
```

* `guest_accelerator` - (Optional) List of the type and count of accelerator cards attached to the instance.
Structure [documented below](#nested_guest_accelerator).
To support removal of guest_accelerators in Terraform 0.12 this field is an
Expand Down Expand Up @@ -762,6 +776,10 @@ linux_node_config {

* `enabled` (Required) - Whether or not the Google Container Filesystem (GCFS) is enabled

<a name="nested_gvnic"></a>The `gvnic` block supports:

* `enabled` (Required) - Whether or not the Google Virtual NIC (gVNIC) is enabled

<a name="nested_guest_accelerator"></a>The `guest_accelerator` block supports:

* `type` (Required) - The accelerator type resource to expose to this instance. E.g. `nvidia-tesla-k80`.
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/container_node_pool.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ cluster.
with the specified prefix. Conflicts with `name`.

* `node_config` - (Optional) Parameters used in creating the node pool. See
[google_container_cluster](container_cluster.html) for schema.
[google_container_cluster](container_cluster.html#nested_node_config) for schema.

* `network_config` - (Optional) The network configuration of the pool. See
[google_container_cluster](container_cluster.html) for schema.
Expand Down