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. (#12569)

[upstream:81de2e099caee29e40283e5eff4770d8ca90979c]

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician committed Dec 16, 2024
1 parent ef4afcc commit d349076
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 29 deletions.
3 changes: 3 additions & 0 deletions .changelog/12569.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
container: changed `google_container_cluster` to apply maintenance policy updates after upgrades during cluster update
```
59 changes: 30 additions & 29 deletions google/services/container/resource_container_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -3415,35 +3415,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 @@ -3711,6 +3682,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 d349076

Please sign in to comment.