Skip to content

Commit dd55378

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

File tree

3 files changed

+44
-9
lines changed

3 files changed

+44
-9
lines changed

.changelog/9557.txt

Lines changed: 3 additions & 0 deletions
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-beta/services/container/resource_container_cluster.go

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2340,11 +2340,28 @@ func resourceContainerClusterCreate(d *schema.ResourceData, meta interface{}) er
23402340
cluster.SecurityPostureConfig = expandSecurityPostureConfig(v)
23412341
}
23422342

2343+
needUpdateAfterCreate := false
2344+
23432345
// For now PSC based cluster don't support `enable_private_endpoint` on `create`, but only on `update` API call.
23442346
// 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.
23452347
enablePrivateEndpointPSCCluster := isEnablePrivateEndpointPSCCluster(cluster)
23462348
if enablePrivateEndpointPSCCluster {
23472349
cluster.PrivateClusterConfig.EnablePrivateEndpoint = false
2350+
needUpdateAfterCreate = true
2351+
}
2352+
2353+
enablePDCSI := isEnablePDCSI(cluster)
2354+
if !enablePDCSI {
2355+
// GcePersistentDiskCsiDriver cannot be disabled at cluster create, only on cluster update. Ignore on create then update after creation.
2356+
// If pdcsi is disabled, the config should be defined. But we will be paranoid and double-check.
2357+
needUpdateAfterCreate = true
2358+
if cluster.AddonsConfig == nil {
2359+
cluster.AddonsConfig = &container.AddonsConfig{}
2360+
}
2361+
if cluster.AddonsConfig.GcePersistentDiskCsiDriverConfig == nil {
2362+
cluster.AddonsConfig.GcePersistentDiskCsiDriverConfig = &container.GcePersistentDiskCsiDriverConfig{}
2363+
}
2364+
cluster.AddonsConfig.GcePersistentDiskCsiDriverConfig.Enabled = true
23482365
}
23492366

23502367
req := &container.CreateClusterRequest{
@@ -2431,14 +2448,22 @@ func resourceContainerClusterCreate(d *schema.ResourceData, meta interface{}) er
24312448
}
24322449
}
24332450

2434-
if enablePrivateEndpointPSCCluster {
2451+
if needUpdateAfterCreate {
24352452
name := containerClusterFullName(project, location, clusterName)
2436-
req := &container.UpdateClusterRequest{
2437-
Update: &container.ClusterUpdate{
2438-
DesiredEnablePrivateEndpoint: true,
2439-
ForceSendFields: []string{"DesiredEnablePrivateEndpoint"},
2440-
},
2453+
update := &container.ClusterUpdate{}
2454+
if enablePrivateEndpointPSCCluster {
2455+
update.DesiredEnablePrivateEndpoint = true
2456+
update.ForceSendFields = append(update.ForceSendFields, "DesiredEnablePrivateEndpoint")
2457+
}
2458+
if !enablePDCSI {
2459+
update.DesiredAddonsConfig = &container.AddonsConfig{
2460+
GcePersistentDiskCsiDriverConfig: &container.GcePersistentDiskCsiDriverConfig{
2461+
Enabled: false,
2462+
},
2463+
}
2464+
update.ForceSendFields = append(update.ForceSendFields, "DesiredAddonsConfig.GcePersistentDiskCsiDriverConfig.Enabled")
24412465
}
2466+
req := &container.UpdateClusterRequest{Update: update}
24422467

24432468
err = transport_tpg.Retry(transport_tpg.RetryOptions{
24442469
RetryFunc: func() error {
@@ -2451,12 +2476,12 @@ func resourceContainerClusterCreate(d *schema.ResourceData, meta interface{}) er
24512476
},
24522477
})
24532478
if err != nil {
2454-
return errwrap.Wrapf("Error updating enable private endpoint: {{err}}", err)
2479+
return errwrap.Wrapf(fmt.Sprintf("Error updating cluster for %v: {{err}}", update.ForceSendFields), err)
24552480
}
24562481

24572482
err = ContainerOperationWait(config, op, project, location, "updating enable private endpoint", userAgent, d.Timeout(schema.TimeoutCreate))
24582483
if err != nil {
2459-
return errwrap.Wrapf("Error while waiting to enable private endpoint: {{err}}", err)
2484+
return errwrap.Wrapf(fmt.Sprintf("Error while waiting on cluster update for %v: {{err}}", update.ForceSendFields), err)
24602485
}
24612486
}
24622487

@@ -4885,6 +4910,13 @@ func isEnablePrivateEndpointPSCCluster(cluster *container.Cluster) bool {
48854910
return false
48864911
}
48874912

4913+
func isEnablePDCSI(cluster *container.Cluster) bool {
4914+
if cluster.AddonsConfig == nil || cluster.AddonsConfig.GcePersistentDiskCsiDriverConfig == nil {
4915+
return true // PDCSI is enabled by default.
4916+
}
4917+
return cluster.AddonsConfig.GcePersistentDiskCsiDriverConfig.Enabled
4918+
}
4919+
48884920
func expandPrivateClusterConfig(configured interface{}) *container.PrivateClusterConfig {
48894921
l := configured.([]interface{})
48904922
if len(l) == 0 {

google-beta/services/container/resource_container_cluster_test.go

Lines changed: 1 addition & 1 deletion
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))
@@ -4771,6 +4770,7 @@ resource "google_container_cluster" "primary" {
47714770
kalm_config {
47724771
enabled = true
47734772
}
4773+
}
47744774
deletion_protection = false
47754775
network = "%s"
47764776
subnetwork = "%s"

0 commit comments

Comments
 (0)