Skip to content

Commit 9179236

Browse files
container: allow updating gvnic in place for node_pool (#13660) (#22421)
[upstream:5e3b8726fa9f24f0f9d6bd6f36a7cdeef240aa75] Signed-off-by: Modular Magician <[email protected]>
1 parent cb0b50e commit 9179236

File tree

3 files changed

+62
-12
lines changed

3 files changed

+62
-12
lines changed

.changelog/13660.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: allow updating `gvnic` in place for `google_container_node_pool`
3+
```

google/services/container/node_config.go

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,13 +321,11 @@ func schemaNodeConfig() *schema.Schema {
321321
Optional: true,
322322
MaxItems: 1,
323323
Description: `Enable or disable gvnic in the node pool.`,
324-
ForceNew: true,
325324
Elem: &schema.Resource{
326325
Schema: map[string]*schema.Schema{
327326
"enabled": {
328327
Type: schema.TypeBool,
329328
Required: true,
330-
ForceNew: true,
331329
Description: `Whether or not gvnic is enabled`,
332330
},
333331
},
@@ -2484,6 +2482,39 @@ func nodePoolNodeConfigUpdate(d *schema.ResourceData, config *transport_tpg.Conf
24842482
log.Printf("[INFO] Updated gcfs_config for node pool %s", name)
24852483
}
24862484

2485+
if d.HasChange(prefix + "node_config.0.gvnic") {
2486+
gvnicEnabled := bool(d.Get(prefix + "node_config.0.gvnic.0.enabled").(bool))
2487+
req := &container.UpdateNodePoolRequest{
2488+
NodePoolId: name,
2489+
Gvnic: &container.VirtualNIC{
2490+
Enabled: gvnicEnabled,
2491+
},
2492+
}
2493+
updateF := func() error {
2494+
clusterNodePoolsUpdateCall := config.NewContainerClient(userAgent).Projects.Locations.Clusters.NodePools.Update(nodePoolInfo.fullyQualifiedName(name), req)
2495+
if config.UserProjectOverride {
2496+
clusterNodePoolsUpdateCall.Header().Add("X-Goog-User-Project", nodePoolInfo.project)
2497+
}
2498+
op, err := clusterNodePoolsUpdateCall.Do()
2499+
if err != nil {
2500+
return err
2501+
}
2502+
2503+
// Wait until it's updated
2504+
return ContainerOperationWait(config, op,
2505+
nodePoolInfo.project,
2506+
nodePoolInfo.location,
2507+
"updating GKE node pool gvnic", userAgent,
2508+
timeout)
2509+
}
2510+
2511+
if err := retryWhileIncompatibleOperation(timeout, npLockKey, updateF); err != nil {
2512+
return err
2513+
}
2514+
2515+
log.Printf("[INFO] Updated gvnic for node pool %s", name)
2516+
}
2517+
24872518
if d.HasChange(prefix + "node_config.0.kubelet_config") {
24882519
req := &container.UpdateNodePoolRequest{
24892520
NodePoolId: name,

google/services/container/resource_container_node_pool_test.go

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1749,7 +1749,23 @@ func TestAccContainerNodePool_gvnic(t *testing.T) {
17491749
CheckDestroy: testAccCheckContainerNodePoolDestroyProducer(t),
17501750
Steps: []resource.TestStep{
17511751
{
1752-
Config: testAccContainerNodePool_gvnic(cluster, np, networkName, subnetworkName),
1752+
Config: testAccContainerNodePool_gvnic(cluster, np, networkName, subnetworkName, true),
1753+
},
1754+
{
1755+
ResourceName: "google_container_node_pool.np",
1756+
ImportState: true,
1757+
ImportStateVerify: true,
1758+
},
1759+
{
1760+
Config: testAccContainerNodePool_gvnic(cluster, np, networkName, subnetworkName, false),
1761+
},
1762+
{
1763+
ResourceName: "google_container_node_pool.np",
1764+
ImportState: true,
1765+
ImportStateVerify: true,
1766+
},
1767+
{
1768+
Config: testAccContainerNodePool_gvnic(cluster, np, networkName, subnetworkName, true),
17531769
},
17541770
{
17551771
ResourceName: "google_container_node_pool.np",
@@ -1760,15 +1776,15 @@ func TestAccContainerNodePool_gvnic(t *testing.T) {
17601776
})
17611777
}
17621778

1763-
func testAccContainerNodePool_gvnic(cluster, np, networkName, subnetworkName string) string {
1779+
func testAccContainerNodePool_gvnic(cluster, np, networkName, subnetworkName string, enabled bool) string {
17641780
return fmt.Sprintf(`
17651781
resource "google_container_cluster" "cluster" {
1766-
name = "%s"
1767-
location = "us-central1-a"
1768-
initial_node_count = 1
1782+
name = "%s"
1783+
location = "us-central1-a"
1784+
initial_node_count = 1
17691785
deletion_protection = false
1770-
network = "%s"
1771-
subnetwork = "%s"
1786+
network = "%s"
1787+
subnetwork = "%s"
17721788
}
17731789
17741790
resource "google_container_node_pool" "np" {
@@ -1779,13 +1795,13 @@ resource "google_container_node_pool" "np" {
17791795
17801796
node_config {
17811797
machine_type = "n1-standard-8"
1782-
image_type = "COS_CONTAINERD"
1798+
image_type = "COS_CONTAINERD"
17831799
gvnic {
1784-
enabled = true
1800+
enabled = "%t"
17851801
}
17861802
}
17871803
}
1788-
`, cluster, networkName, subnetworkName, np)
1804+
`, cluster, networkName, subnetworkName, np, enabled)
17891805
}
17901806

17911807
func TestAccContainerNodePool_fastSocket(t *testing.T) {

0 commit comments

Comments
 (0)