Skip to content

Commit

Permalink
Apply maintenance policy updates after upgrades so validation on main…
Browse files Browse the repository at this point in the history
…tenance policy uses the new versions. (GoogleCloudPlatform#12569)
  • Loading branch information
cslink authored Dec 16, 2024
1 parent 8dd1c9d commit 81de2e0
Showing 1 changed file with 30 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3654,35 +3654,6 @@ func resourceContainerClusterUpdate(d *schema.ResourceData, meta interface{}) er
log.Printf("[INFO] GKE cluster %s Default SNAT status has been updated", d.Id())
}

if d.HasChange("maintenance_policy") {
req := &container.SetMaintenancePolicyRequest{
MaintenancePolicy: expandMaintenancePolicy(d, meta),
}

updateF := func() error {
name := containerClusterFullName(project, location, clusterName)
clusterSetMaintenancePolicyCall := config.NewContainerClient(userAgent).Projects.Locations.Clusters.SetMaintenancePolicy(name, req)
if config.UserProjectOverride {
clusterSetMaintenancePolicyCall.Header().Add("X-Goog-User-Project", project)
}
op, err := clusterSetMaintenancePolicyCall.Do()

if err != nil {
return err
}

// Wait until it's updated
return ContainerOperationWait(config, op, project, location, "updating GKE cluster maintenance policy", userAgent, d.Timeout(schema.TimeoutUpdate))
}

// Call update serially.
if err := transport_tpg.LockedCall(lockKey, updateF); err != nil {
return err
}

log.Printf("[INFO] GKE cluster %s maintenance policy has been updated", d.Id())
}

if d.HasChange("node_locations") {
azSetOldI, azSetNewI := d.GetChange("node_locations")
azSetNew := azSetNewI.(*schema.Set)
Expand Down Expand Up @@ -3950,6 +3921,36 @@ func resourceContainerClusterUpdate(d *schema.ResourceData, meta interface{}) er
}
}

// Set maintenance policy after upgrade so validation will use the new versions.
if d.HasChange("maintenance_policy") {
req := &container.SetMaintenancePolicyRequest{
MaintenancePolicy: expandMaintenancePolicy(d, meta),
}

updateF := func() error {
name := containerClusterFullName(project, location, clusterName)
clusterSetMaintenancePolicyCall := config.NewContainerClient(userAgent).Projects.Locations.Clusters.SetMaintenancePolicy(name, req)
if config.UserProjectOverride {
clusterSetMaintenancePolicyCall.Header().Add("X-Goog-User-Project", project)
}
op, err := clusterSetMaintenancePolicyCall.Do()

if err != nil {
return err
}

// Wait until it's updated
return ContainerOperationWait(config, op, project, location, "updating GKE cluster maintenance policy", userAgent, d.Timeout(schema.TimeoutUpdate))
}

// Call update serially.
if err := transport_tpg.LockedCall(lockKey, updateF); err != nil {
return err
}

log.Printf("[INFO] GKE cluster %s maintenance policy has been updated", d.Id())
}

if d.HasChange("node_config") {

defaultPool := "default-pool"
Expand Down

0 comments on commit 81de2e0

Please sign in to comment.