Skip to content

Commit

Permalink
container_node_pool : add gvnic support (GoogleCloudPlatform#5789)
Browse files Browse the repository at this point in the history
  • Loading branch information
ScottSuarez authored and lcaggio committed Mar 16, 2022
1 parent 88b79e5 commit d890dbf
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -978,6 +978,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)
}

<% unless version == 'ga' -%>
func TestAccContainerNodePool_compactPlacement(t *testing.T) {
t.Parallel()
Expand Down Expand Up @@ -2192,3 +2241,5 @@ resource "google_container_node_pool" "np" {
}
`, cluster, np)
}


36 changes: 36 additions & 0 deletions mmv1/third_party/terraform/utils/node_config.go.erb
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,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 @@ -457,6 +475,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 @@ -653,6 +678,7 @@ func flattenNodeConfig(c *container.NodeConfig) []map[string]interface{} {
"ephemeral_storage_config": flattenEphemeralStorageConfig(c.EphemeralStorageConfig),
<% end -%>
"gcfs_config": flattenGcfsConfig(c.GcfsConfig),
"gvnic": flattenGvnic(c.Gvnic),
"service_account": c.ServiceAccount,
"metadata": c.Metadata,
"image_type": c.ImageType,
Expand Down Expand Up @@ -729,6 +755,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
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
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

0 comments on commit d890dbf

Please sign in to comment.