Skip to content

Commit 2ad9d6a

Browse files
wyardleyBBBmau
authored andcommitted
container: fix missing updates for google_container_cluster.node_config subfields (GoogleCloudPlatform#12014)
1 parent c0cbdee commit 2ad9d6a

File tree

4 files changed

+334
-203
lines changed

4 files changed

+334
-203
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -2161,7 +2161,7 @@ func nodePoolNodeConfigUpdate(d *schema.ResourceData, config *transport_tpg.Conf
21612161
req.Tags = ntags
21622162
}
21632163

2164-
// sets tags to the empty list when user removes a previously defined list of tags entriely
2164+
// sets tags to the empty list when user removes a previously defined list of tags entriely
21652165
// aka the node pool goes from having tags to no longer having any
21662166
if req.Tags == nil {
21672167
tags := []string{}

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

+6-143
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,6 @@ var (
104104
"private_cluster_config.0.master_global_access_config",
105105
}
106106

107-
forceNewClusterNodeConfigFields = []string{
108-
"labels",
109-
"workload_metadata_config",
110-
"resource_manager_tags",
111-
}
112-
113107
suppressDiffForAutopilot = schema.SchemaDiffSuppressFunc(func(k, oldValue, newValue string, d *schema.ResourceData) bool {
114108
if v, _ := d.Get("enable_autopilot").(bool); v {
115109
return true
@@ -126,19 +120,6 @@ var (
126120
})
127121
)
128122

129-
// This uses the node pool nodeConfig schema but sets
130-
// node-pool-only updatable fields to ForceNew
131-
func clusterSchemaNodeConfig() *schema.Schema {
132-
nodeConfigSch := schemaNodeConfig()
133-
schemaMap := nodeConfigSch.Elem.(*schema.Resource).Schema
134-
for _, k := range forceNewClusterNodeConfigFields {
135-
if sch, ok := schemaMap[k]; ok {
136-
tpgresource.ChangeFieldSchemaToForceNew(sch)
137-
}
138-
}
139-
return nodeConfigSch
140-
}
141-
142123
// Defines default nodel pool settings for the entire cluster. These settings are
143124
// overridden if specified on the specific NodePool object.
144125
func clusterSchemaNodePoolDefaults() *schema.Schema {
@@ -1477,7 +1458,7 @@ func ResourceContainerCluster() *schema.Resource {
14771458
},
14781459
},
14791460

1480-
"node_config": clusterSchemaNodeConfig(),
1461+
"node_config": schemaNodeConfig(),
14811462

14821463
"node_pool": {
14831464
Type: schema.TypeList,
@@ -3812,133 +3793,15 @@ func resourceContainerClusterUpdate(d *schema.ResourceData, meta interface{}) er
38123793
}
38133794

38143795
if d.HasChange("node_config") {
3815-
if d.HasChange("node_config.0.image_type") {
3816-
it := d.Get("node_config.0.image_type").(string)
3817-
req := &container.UpdateClusterRequest{
3818-
Update: &container.ClusterUpdate{
3819-
DesiredImageType: it,
3820-
},
3821-
}
3822-
3823-
updateF := func() error {
3824-
name := containerClusterFullName(project, location, clusterName)
3825-
clusterUpdateCall := config.NewContainerClient(userAgent).Projects.Locations.Clusters.Update(name, req)
3826-
if config.UserProjectOverride {
3827-
clusterUpdateCall.Header().Add("X-Goog-User-Project", project)
3828-
}
3829-
op, err := clusterUpdateCall.Do()
3830-
if err != nil {
3831-
return err
3832-
}
3833-
3834-
// Wait until it's updated
3835-
return ContainerOperationWait(config, op, project, location, "updating GKE image type", userAgent, d.Timeout(schema.TimeoutUpdate))
3836-
}
38373796

3838-
// Call update serially.
3839-
if err := transport_tpg.LockedCall(lockKey, updateF); err != nil {
3840-
return err
3841-
}
3842-
3843-
log.Printf("[INFO] GKE cluster %s: image type has been updated to %s", d.Id(), it)
3844-
}
3845-
3846-
if d.HasChange("node_config.0.kubelet_config") {
3847-
3848-
defaultPool := "default-pool"
3849-
3850-
timeout := d.Timeout(schema.TimeoutCreate)
3851-
3852-
nodePoolInfo, err := extractNodePoolInformationFromCluster(d, config, clusterName)
3853-
if err != nil {
3854-
return err
3855-
}
3856-
3857-
// Acquire write-lock on nodepool.
3858-
npLockKey := nodePoolInfo.nodePoolLockKey(defaultPool)
3859-
3860-
// Still should be further consolidated / DRYed up
3861-
// See b/361634104
3862-
it := d.Get("node_config.0.kubelet_config")
3863-
3864-
// While we're getting the value from fields in
3865-
// node_config.kubelet_config, the actual setting that needs to be
3866-
// updated is on the default nodepool.
3867-
req := &container.UpdateNodePoolRequest{
3868-
Name: defaultPool,
3869-
KubeletConfig: expandKubeletConfig(it),
3870-
}
3797+
defaultPool := "default-pool"
38713798

3872-
updateF := func() error {
3873-
clusterNodePoolsUpdateCall := config.NewContainerClient(userAgent).Projects.Locations.Clusters.NodePools.Update(nodePoolInfo.fullyQualifiedName(defaultPool), req)
3874-
if config.UserProjectOverride {
3875-
clusterNodePoolsUpdateCall.Header().Add("X-Goog-User-Project", nodePoolInfo.project)
3876-
}
3877-
op, err := clusterNodePoolsUpdateCall.Do()
3878-
if err != nil {
3879-
return err
3880-
}
3881-
3882-
// Wait until it's updated
3883-
return ContainerOperationWait(config, op, nodePoolInfo.project, nodePoolInfo.location,
3884-
"updating GKE node pool kubelet_config", userAgent, timeout)
3885-
}
3886-
3887-
if err := retryWhileIncompatibleOperation(timeout, npLockKey, updateF); err != nil {
3888-
return err
3889-
}
3890-
3891-
log.Printf("[INFO] GKE cluster %s: kubelet_config updated", d.Id())
3892-
}
3893-
3894-
if d.HasChange("node_config.0.gcfs_config") {
3895-
3896-
defaultPool := "default-pool"
3897-
3898-
timeout := d.Timeout(schema.TimeoutCreate)
3899-
3900-
nodePoolInfo, err := extractNodePoolInformationFromCluster(d, config, clusterName)
3901-
if err != nil {
3902-
return err
3903-
}
3904-
3905-
// Acquire write-lock on nodepool.
3906-
npLockKey := nodePoolInfo.nodePoolLockKey(defaultPool)
3907-
3908-
gcfsEnabled := d.Get("node_config.0.gcfs_config.0.enabled").(bool)
3909-
3910-
// While we're getting the value from the drepcated field in
3911-
// node_config.kubelet_config, the actual setting that needs to be updated
3912-
// is on the default nodepool.
3913-
req := &container.UpdateNodePoolRequest{
3914-
Name: defaultPool,
3915-
GcfsConfig: &container.GcfsConfig{
3916-
Enabled: gcfsEnabled,
3917-
},
3918-
}
3919-
3920-
updateF := func() error {
3921-
clusterNodePoolsUpdateCall := config.NewContainerClient(userAgent).Projects.Locations.Clusters.NodePools.Update(nodePoolInfo.fullyQualifiedName(defaultPool), req)
3922-
if config.UserProjectOverride {
3923-
clusterNodePoolsUpdateCall.Header().Add("X-Goog-User-Project", nodePoolInfo.project)
3924-
}
3925-
op, err := clusterNodePoolsUpdateCall.Do()
3926-
if err != nil {
3927-
return err
3928-
}
3929-
3930-
// Wait until it's updated
3931-
return ContainerOperationWait(config, op, nodePoolInfo.project, nodePoolInfo.location,
3932-
"updating GKE node pool gcfs_config", userAgent, timeout)
3933-
}
3934-
3935-
if err := retryWhileIncompatibleOperation(timeout, npLockKey, updateF); err != nil {
3936-
return err
3937-
}
3938-
3939-
log.Printf("[INFO] GKE cluster %s: %s setting for gcfs_config updated to %t", d.Id(), defaultPool, gcfsEnabled)
3799+
nodePoolInfo, err := extractNodePoolInformationFromCluster(d, config, clusterName)
3800+
if err != nil {
3801+
return err
39403802
}
39413803

3804+
nodePoolNodeConfigUpdate(d, config, nodePoolInfo, "", defaultPool, d.Timeout(schema.TimeoutUpdate))
39423805
}
39433806

39443807
if d.HasChange("notification_config") {

mmv1/third_party/terraform/services/container/resource_container_cluster_migratev1.go.tmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -1198,7 +1198,7 @@ func resourceContainerClusterResourceV1() *schema.Resource {
11981198
},
11991199
},
12001200

1201-
"node_config": clusterSchemaNodeConfig(),
1201+
"node_config": schemaNodeConfig(),
12021202

12031203
"node_pool": {
12041204
Type: schema.TypeList,

0 commit comments

Comments
 (0)