Skip to content

Commit ab9c86f

Browse files
No pdcsi disable on create (#9557) (#16794)
[upstream:f8feaf07fdeff43bd80832c47ec15f645d7228a4] Signed-off-by: Modular Magician <[email protected]>
1 parent 206fb3b commit ab9c86f

File tree

3 files changed

+44
-9
lines changed

3 files changed

+44
-9
lines changed

.changelog/9557.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
container: fixed a bug where disable PDCSI addon `gce_persistent_disk_csi_driver_config ` during creation will result in permadiff in `google_container_cluster` resource
3+
```

google/services/container/resource_container_cluster.go

+40-8
Original file line numberDiff line numberDiff line change
@@ -2161,11 +2161,28 @@ func resourceContainerClusterCreate(d *schema.ResourceData, meta interface{}) er
21612161
cluster.SecurityPostureConfig = expandSecurityPostureConfig(v)
21622162
}
21632163

2164+
needUpdateAfterCreate := false
2165+
21642166
// For now PSC based cluster don't support `enable_private_endpoint` on `create`, but only on `update` API call.
21652167
// If cluster is PSC based and enable_private_endpoint is set to true we will ignore it on `create` call and update cluster right after creation.
21662168
enablePrivateEndpointPSCCluster := isEnablePrivateEndpointPSCCluster(cluster)
21672169
if enablePrivateEndpointPSCCluster {
21682170
cluster.PrivateClusterConfig.EnablePrivateEndpoint = false
2171+
needUpdateAfterCreate = true
2172+
}
2173+
2174+
enablePDCSI := isEnablePDCSI(cluster)
2175+
if !enablePDCSI {
2176+
// GcePersistentDiskCsiDriver cannot be disabled at cluster create, only on cluster update. Ignore on create then update after creation.
2177+
// If pdcsi is disabled, the config should be defined. But we will be paranoid and double-check.
2178+
needUpdateAfterCreate = true
2179+
if cluster.AddonsConfig == nil {
2180+
cluster.AddonsConfig = &container.AddonsConfig{}
2181+
}
2182+
if cluster.AddonsConfig.GcePersistentDiskCsiDriverConfig == nil {
2183+
cluster.AddonsConfig.GcePersistentDiskCsiDriverConfig = &container.GcePersistentDiskCsiDriverConfig{}
2184+
}
2185+
cluster.AddonsConfig.GcePersistentDiskCsiDriverConfig.Enabled = true
21692186
}
21702187

21712188
req := &container.CreateClusterRequest{
@@ -2252,14 +2269,22 @@ func resourceContainerClusterCreate(d *schema.ResourceData, meta interface{}) er
22522269
}
22532270
}
22542271

2255-
if enablePrivateEndpointPSCCluster {
2272+
if needUpdateAfterCreate {
22562273
name := containerClusterFullName(project, location, clusterName)
2257-
req := &container.UpdateClusterRequest{
2258-
Update: &container.ClusterUpdate{
2259-
DesiredEnablePrivateEndpoint: true,
2260-
ForceSendFields: []string{"DesiredEnablePrivateEndpoint"},
2261-
},
2274+
update := &container.ClusterUpdate{}
2275+
if enablePrivateEndpointPSCCluster {
2276+
update.DesiredEnablePrivateEndpoint = true
2277+
update.ForceSendFields = append(update.ForceSendFields, "DesiredEnablePrivateEndpoint")
2278+
}
2279+
if !enablePDCSI {
2280+
update.DesiredAddonsConfig = &container.AddonsConfig{
2281+
GcePersistentDiskCsiDriverConfig: &container.GcePersistentDiskCsiDriverConfig{
2282+
Enabled: false,
2283+
},
2284+
}
2285+
update.ForceSendFields = append(update.ForceSendFields, "DesiredAddonsConfig.GcePersistentDiskCsiDriverConfig.Enabled")
22622286
}
2287+
req := &container.UpdateClusterRequest{Update: update}
22632288

22642289
err = transport_tpg.Retry(transport_tpg.RetryOptions{
22652290
RetryFunc: func() error {
@@ -2272,12 +2297,12 @@ func resourceContainerClusterCreate(d *schema.ResourceData, meta interface{}) er
22722297
},
22732298
})
22742299
if err != nil {
2275-
return errwrap.Wrapf("Error updating enable private endpoint: {{err}}", err)
2300+
return errwrap.Wrapf(fmt.Sprintf("Error updating cluster for %v: {{err}}", update.ForceSendFields), err)
22762301
}
22772302

22782303
err = ContainerOperationWait(config, op, project, location, "updating enable private endpoint", userAgent, d.Timeout(schema.TimeoutCreate))
22792304
if err != nil {
2280-
return errwrap.Wrapf("Error while waiting to enable private endpoint: {{err}}", err)
2305+
return errwrap.Wrapf(fmt.Sprintf("Error while waiting on cluster update for %v: {{err}}", update.ForceSendFields), err)
22812306
}
22822307
}
22832308

@@ -4511,6 +4536,13 @@ func isEnablePrivateEndpointPSCCluster(cluster *container.Cluster) bool {
45114536
return false
45124537
}
45134538

4539+
func isEnablePDCSI(cluster *container.Cluster) bool {
4540+
if cluster.AddonsConfig == nil || cluster.AddonsConfig.GcePersistentDiskCsiDriverConfig == nil {
4541+
return true // PDCSI is enabled by default.
4542+
}
4543+
return cluster.AddonsConfig.GcePersistentDiskCsiDriverConfig.Enabled
4544+
}
4545+
45144546
func expandPrivateClusterConfig(configured interface{}) *container.PrivateClusterConfig {
45154547
l := configured.([]interface{})
45164548
if len(l) == 0 {

google/services/container/resource_container_cluster_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ func TestAccContainerCluster_misc(t *testing.T) {
128128
}
129129

130130
func TestAccContainerCluster_withAddons(t *testing.T) {
131-
t.Skipf("Skipping test %s due to https://github.com/hashicorp/terraform-provider-google/issues/16114", t.Name())
132131
t.Parallel()
133132

134133
clusterName := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10))
@@ -4184,6 +4183,7 @@ resource "google_container_cluster" "primary" {
41844183
gcs_fuse_csi_driver_config {
41854184
enabled = true
41864185
}
4186+
}
41874187
deletion_protection = false
41884188
network = "%s"
41894189
subnetwork = "%s"

0 commit comments

Comments
 (0)