Skip to content

Commit 84e620b

Browse files
container_node_pool : add gvnic support (#5789) (#4111)
Signed-off-by: Modular Magician <[email protected]>
1 parent a662c33 commit 84e620b

File tree

5 files changed

+108
-2
lines changed

5 files changed

+108
-2
lines changed

.changelog/5789.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
container: add support for gvnic to `google_container_node_pool`
3+
```

google-beta/node_config.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,24 @@ func schemaNodeConfig() *schema.Schema {
145145
},
146146
},
147147

148+
"gvnic": {
149+
Type: schema.TypeList,
150+
Optional: true,
151+
MaxItems: 1,
152+
Description: `Enable or disable gvnic in the node pool.`,
153+
ForceNew: true,
154+
Elem: &schema.Resource{
155+
Schema: map[string]*schema.Schema{
156+
"enabled": {
157+
Type: schema.TypeBool,
158+
Required: true,
159+
ForceNew: true,
160+
Description: `Whether or not gvnic is enabled`,
161+
},
162+
},
163+
},
164+
},
165+
148166
"machine_type": {
149167
Type: schema.TypeString,
150168
Optional: true,
@@ -436,6 +454,13 @@ func expandNodeConfig(v interface{}) *container.NodeConfig {
436454
}
437455
}
438456

457+
if v, ok := nodeConfig["gvnic"]; ok && len(v.([]interface{})) > 0 {
458+
conf := v.([]interface{})[0].(map[string]interface{})
459+
nc.Gvnic = &container.VirtualNIC{
460+
Enabled: conf["enabled"].(bool),
461+
}
462+
}
463+
439464
if scopes, ok := nodeConfig["oauth_scopes"]; ok {
440465
scopesSet := scopes.(*schema.Set)
441466
scopes := make([]string, scopesSet.Len())
@@ -620,6 +645,7 @@ func flattenNodeConfig(c *container.NodeConfig) []map[string]interface{} {
620645
"local_ssd_count": c.LocalSsdCount,
621646
"ephemeral_storage_config": flattenEphemeralStorageConfig(c.EphemeralStorageConfig),
622647
"gcfs_config": flattenGcfsConfig(c.GcfsConfig),
648+
"gvnic": flattenGvnic(c.Gvnic),
623649
"service_account": c.ServiceAccount,
624650
"metadata": c.Metadata,
625651
"image_type": c.ImageType,
@@ -688,6 +714,16 @@ func flattenGcfsConfig(c *container.GcfsConfig) []map[string]interface{} {
688714
return result
689715
}
690716

717+
func flattenGvnic(c *container.VirtualNIC) []map[string]interface{} {
718+
result := []map[string]interface{}{}
719+
if c != nil {
720+
result = append(result, map[string]interface{}{
721+
"enabled": c.Enabled,
722+
})
723+
}
724+
return result
725+
}
726+
691727
func flattenTaints(c []*container.NodeTaint) []map[string]interface{} {
692728
result := []map[string]interface{}{}
693729
for _, taint := range c {

google-beta/resource_container_node_pool_test.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -963,6 +963,55 @@ resource "google_container_node_pool" "np" {
963963
`, cluster, np)
964964
}
965965

966+
func TestAccContainerNodePool_gvnic(t *testing.T) {
967+
t.Parallel()
968+
969+
cluster := fmt.Sprintf("tf-test-cluster-%s", randString(t, 10))
970+
np := fmt.Sprintf("tf-test-nodepool-%s", randString(t, 10))
971+
972+
vcrTest(t, resource.TestCase{
973+
PreCheck: func() { testAccPreCheck(t) },
974+
Providers: testAccProviders,
975+
CheckDestroy: testAccCheckContainerNodePoolDestroyProducer(t),
976+
Steps: []resource.TestStep{
977+
{
978+
Config: testAccContainerNodePool_gvnic(cluster, np),
979+
},
980+
{
981+
ResourceName: "google_container_node_pool.np",
982+
ImportState: true,
983+
ImportStateVerify: true,
984+
},
985+
},
986+
})
987+
}
988+
989+
func testAccContainerNodePool_gvnic(cluster, np string) string {
990+
return fmt.Sprintf(`
991+
resource "google_container_cluster" "cluster" {
992+
name = "%s"
993+
location = "us-central1-a"
994+
initial_node_count = 1
995+
min_master_version = "1.19"
996+
}
997+
998+
resource "google_container_node_pool" "np" {
999+
name = "%s"
1000+
location = "us-central1-a"
1001+
cluster = google_container_cluster.cluster.name
1002+
initial_node_count = 1
1003+
1004+
node_config {
1005+
machine_type = "n1-standard-8"
1006+
image_type = "COS_CONTAINERD"
1007+
gvnic {
1008+
enabled = true
1009+
}
1010+
}
1011+
}
1012+
`, cluster, np)
1013+
}
1014+
9661015
func TestAccContainerNodePool_compactPlacement(t *testing.T) {
9671016
t.Parallel()
9681017

website/docs/r/container_cluster.html.markdown

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ subnetwork in which the cluster's instances are launched.
367367
It can only be disabled if the nodes already do not have network policies enabled.
368368
Defaults to disabled; set `disabled = false` to enable.
369369

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

@@ -649,6 +649,20 @@ gcfs_config {
649649
}
650650
```
651651

652+
653+
* `gvnic` - (Optional) Google Virtual NIC (gVNIC) is a virtual network interface.
654+
Installing the gVNIC driver allows for more efficient traffic transmission across the Google network infrastructure.
655+
gVNIC is an alternative to the virtIO-based ethernet driver. GKE nodes must use a Container-Optimized OS node image.
656+
GKE node version 1.15.11-gke.15 or later
657+
Structure is [documented below](#nested_gvnic).
658+
659+
660+
```hcl
661+
gvnic {
662+
enabled = true
663+
}
664+
```
665+
652666
* `guest_accelerator` - (Optional) List of the type and count of accelerator cards attached to the instance.
653667
Structure [documented below](#nested_guest_accelerator).
654668
To support removal of guest_accelerators in Terraform 0.12 this field is an
@@ -762,6 +776,10 @@ linux_node_config {
762776

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

779+
<a name="nested_gvnic"></a>The `gvnic` block supports:
780+
781+
* `enabled` (Required) - Whether or not the Google Virtual NIC (gVNIC) is enabled
782+
765783
<a name="nested_guest_accelerator"></a>The `guest_accelerator` block supports:
766784

767785
* `type` (Required) - The accelerator type resource to expose to this instance. E.g. `nvidia-tesla-k80`.

website/docs/r/container_node_pool.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ cluster.
148148
with the specified prefix. Conflicts with `name`.
149149

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

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

0 commit comments

Comments
 (0)