Skip to content

Commit 20ac9f9

Browse files
authored
container: fix updates for node_config.gcfs_config and make optional (#11717)
1 parent 26f76d1 commit 20ac9f9

5 files changed

+166
-16
lines changed

mmv1/third_party/terraform/services/container/node_config.go.erb

+7-6
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,13 @@ func schemaLoggingVariant() *schema.Schema {
101101
}
102102

103103
func schemaGcfsConfig() *schema.Schema {
104-
return &schema.Schema{
105-
Type: schema.TypeList,
106-
Optional: true,
107-
MaxItems: 1,
104+
return &schema.Schema{
105+
Type: schema.TypeList,
106+
Optional: true,
107+
Computed: true,
108+
MaxItems: 1,
108109
Description: `GCFS configuration for this node.`,
109-
Elem: &schema.Resource{
110+
Elem: &schema.Resource{
110111
Schema: map[string]*schema.Schema{
111112
"enabled": {
112113
Type: schema.TypeBool,
@@ -115,7 +116,7 @@ func schemaGcfsConfig() *schema.Schema {
115116
},
116117
},
117118
},
118-
}
119+
}
119120
}
120121

121122
func schemaNodeConfig() *schema.Schema {

mmv1/third_party/terraform/services/container/resource_container_cluster.go.erb

+49
Original file line numberDiff line numberDiff line change
@@ -3883,6 +3883,55 @@ func resourceContainerClusterUpdate(d *schema.ResourceData, meta interface{}) er
38833883
log.Printf("[INFO] GKE cluster %s: default-pool setting for insecure_kubelet_readonly_port_enabled updated to %s", d.Id(), it)
38843884
}
38853885
}
3886+
3887+
if d.HasChange("node_config.0.gcfs_config") {
3888+
3889+
defaultPool := "default-pool"
3890+
3891+
timeout := d.Timeout(schema.TimeoutCreate)
3892+
3893+
nodePoolInfo, err := extractNodePoolInformationFromCluster(d, config, clusterName)
3894+
if err != nil {
3895+
return err
3896+
}
3897+
3898+
// Acquire write-lock on nodepool.
3899+
npLockKey := nodePoolInfo.nodePoolLockKey(defaultPool)
3900+
3901+
gcfsEnabled := d.Get("node_config.0.gcfs_config.0.enabled").(bool)
3902+
3903+
// While we're getting the value from the drepcated field in
3904+
// node_config.kubelet_config, the actual setting that needs to be updated
3905+
// is on the default nodepool.
3906+
req := &container.UpdateNodePoolRequest{
3907+
Name: defaultPool,
3908+
GcfsConfig: &container.GcfsConfig{
3909+
Enabled: gcfsEnabled,
3910+
},
3911+
}
3912+
3913+
updateF := func() error {
3914+
clusterNodePoolsUpdateCall := config.NewContainerClient(userAgent).Projects.Locations.Clusters.NodePools.Update(nodePoolInfo.fullyQualifiedName(defaultPool), req)
3915+
if config.UserProjectOverride {
3916+
clusterNodePoolsUpdateCall.Header().Add("X-Goog-User-Project", nodePoolInfo.project)
3917+
}
3918+
op, err := clusterNodePoolsUpdateCall.Do()
3919+
if err != nil {
3920+
return err
3921+
}
3922+
3923+
// Wait until it's updated
3924+
return ContainerOperationWait(config, op, nodePoolInfo.project, nodePoolInfo.location,
3925+
"updating GKE node pool gcfs_config", userAgent, timeout)
3926+
}
3927+
3928+
if err := retryWhileIncompatibleOperation(timeout, npLockKey, updateF); err != nil {
3929+
return err
3930+
}
3931+
3932+
log.Printf("[INFO] GKE cluster %s: %s setting for gcfs_config updated to %t", d.Id(), defaultPool, gcfsEnabled)
3933+
}
3934+
38863935
}
38873936

38883937
if d.HasChange("notification_config") {

mmv1/third_party/terraform/services/container/resource_container_cluster_test.go.erb

+63
Original file line numberDiff line numberDiff line change
@@ -1536,6 +1536,49 @@ func TestAccContainerCluster_withNodeConfig(t *testing.T) {
15361536
})
15371537
}
15381538

1539+
func TestAccContainerCluster_withNodeConfigGcfsConfig(t *testing.T) {
1540+
t.Parallel()
1541+
clusterName := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10))
1542+
networkName := acctest.BootstrapSharedTestNetwork(t, "gke-cluster")
1543+
subnetworkName := acctest.BootstrapSubnet(t, "gke-cluster", networkName)
1544+
1545+
acctest.VcrTest(t, resource.TestCase{
1546+
PreCheck: func() { acctest.AccTestPreCheck(t) },
1547+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
1548+
CheckDestroy: testAccCheckContainerClusterDestroyProducer(t),
1549+
Steps: []resource.TestStep{
1550+
{
1551+
Config: testAccContainerCluster_withNodeConfigGcfsConfig(clusterName, networkName, subnetworkName, false),
1552+
ConfigPlanChecks: resource.ConfigPlanChecks{
1553+
PreApply: []plancheck.PlanCheck{
1554+
acctest.ExpectNoDelete(),
1555+
},
1556+
},
1557+
},
1558+
{
1559+
ResourceName: "google_container_cluster.with_node_config_gcfs_config",
1560+
ImportState: true,
1561+
ImportStateVerify: true,
1562+
ImportStateVerifyIgnore: []string{"deletion_protection"},
1563+
},
1564+
{
1565+
Config: testAccContainerCluster_withNodeConfigGcfsConfig(clusterName, networkName, subnetworkName, true),
1566+
ConfigPlanChecks: resource.ConfigPlanChecks{
1567+
PreApply: []plancheck.PlanCheck{
1568+
acctest.ExpectNoDelete(),
1569+
},
1570+
},
1571+
},
1572+
{
1573+
ResourceName: "google_container_cluster.with_node_config_gcfs_config",
1574+
ImportState: true,
1575+
ImportStateVerify: true,
1576+
ImportStateVerifyIgnore: []string{"deletion_protection"},
1577+
},
1578+
},
1579+
})
1580+
}
1581+
15391582
// Note: Updates for these are currently known to be broken (b/361634104), and
15401583
// so are not tested here.
15411584
// They can probably be made similar to, or consolidated with,
@@ -6693,6 +6736,26 @@ resource "google_container_cluster" "with_node_config" {
66936736
`, clusterName, networkName, subnetworkName)
66946737
}
66956738

6739+
func testAccContainerCluster_withNodeConfigGcfsConfig(clusterName, networkName, subnetworkName string, enabled bool) string {
6740+
return fmt.Sprintf(`
6741+
resource "google_container_cluster" "with_node_config_gcfs_config" {
6742+
name = "%s"
6743+
location = "us-central1-f"
6744+
initial_node_count = 1
6745+
6746+
node_config {
6747+
gcfs_config {
6748+
enabled = %t
6749+
}
6750+
}
6751+
6752+
deletion_protection = false
6753+
network = "%s"
6754+
subnetwork = "%s"
6755+
}
6756+
`, clusterName, enabled, networkName, subnetworkName)
6757+
}
6758+
66966759
func testAccContainerCluster_withNodeConfigKubeletConfigSettings(clusterName, networkName, subnetworkName string) string {
66976760
return fmt.Sprintf(`
66986761
resource "google_container_cluster" "with_node_config_kubelet_config_settings" {

mmv1/third_party/terraform/services/container/resource_container_node_pool.go.erb

+33
Original file line numberDiff line numberDiff line change
@@ -1787,6 +1787,39 @@ func nodePoolUpdate(d *schema.ResourceData, meta interface{}, nodePoolInfo *Node
17871787
log.Printf("[INFO] Updated workload_metadata_config for node pool %s", name)
17881788
}
17891789

1790+
if d.HasChange(prefix + "node_config.0.gcfs_config") {
1791+
gcfsEnabled := bool(d.Get(prefix + "node_config.0.gcfs_config.0.enabled").(bool))
1792+
req := &container.UpdateNodePoolRequest{
1793+
NodePoolId: name,
1794+
GcfsConfig: &container.GcfsConfig{
1795+
Enabled: gcfsEnabled,
1796+
},
1797+
}
1798+
updateF := func() error {
1799+
clusterNodePoolsUpdateCall := config.NewContainerClient(userAgent).Projects.Locations.Clusters.NodePools.Update(nodePoolInfo.fullyQualifiedName(name),req)
1800+
if config.UserProjectOverride {
1801+
clusterNodePoolsUpdateCall.Header().Add("X-Goog-User-Project", nodePoolInfo.project)
1802+
}
1803+
op, err := clusterNodePoolsUpdateCall.Do()
1804+
if err != nil {
1805+
return err
1806+
}
1807+
1808+
// Wait until it's updated
1809+
return ContainerOperationWait(config, op,
1810+
nodePoolInfo.project,
1811+
nodePoolInfo.location,
1812+
"updating GKE node pool gcfs_config", userAgent,
1813+
timeout)
1814+
}
1815+
1816+
if err := retryWhileIncompatibleOperation(timeout, npLockKey, updateF); err != nil {
1817+
return err
1818+
}
1819+
1820+
log.Printf("[INFO] Updated gcfs_config for node pool %s", name)
1821+
}
1822+
17901823
if d.HasChange(prefix + "node_config.0.kubelet_config") {
17911824
req := &container.UpdateNodePoolRequest{
17921825
NodePoolId: name,

mmv1/third_party/terraform/services/container/resource_container_node_pool_test.go.erb

+14-10
Original file line numberDiff line numberDiff line change
@@ -1675,9 +1675,9 @@ resource "google_container_node_pool" "np" {
16751675
node_config {
16761676
machine_type = "n1-standard-8"
16771677
image_type = "COS_CONTAINERD"
1678-
gcfs_config {
1679-
enabled = true
1680-
}
1678+
gcfs_config {
1679+
enabled = true
1680+
}
16811681
secondary_boot_disks {
16821682
disk_image = ""
16831683
mode = "CONTAINER_IMAGE_CACHE"
@@ -1694,9 +1694,9 @@ resource "google_container_node_pool" "np-no-mode" {
16941694
node_config {
16951695
machine_type = "n1-standard-8"
16961696
image_type = "COS_CONTAINERD"
1697-
gcfs_config {
1698-
enabled = true
1699-
}
1697+
gcfs_config {
1698+
enabled = true
1699+
}
17001700
secondary_boot_disks {
17011701
disk_image = ""
17021702
}
@@ -1720,10 +1720,14 @@ func TestAccContainerNodePool_gcfsConfig(t *testing.T) {
17201720
Steps: []resource.TestStep{
17211721
{
17221722
Config: testAccContainerNodePool_gcfsConfig(cluster, np, networkName, subnetworkName, true),
1723-
Check: resource.ComposeTestCheckFunc(
1724-
resource.TestCheckResourceAttr("google_container_node_pool.np",
1725-
"node_config.0.gcfs_config.0.enabled", "true"),
1726-
),
1723+
},
1724+
{
1725+
ResourceName: "google_container_node_pool.np",
1726+
ImportState: true,
1727+
ImportStateVerify: true,
1728+
},
1729+
{
1730+
Config: testAccContainerNodePool_gcfsConfig(cluster, np, networkName, subnetworkName, false),
17271731
},
17281732
{
17291733
ResourceName: "google_container_node_pool.np",

0 commit comments

Comments
 (0)