Skip to content

Apply maintenance policy updates after upgrades so validation on maintenance policy uses the new versions. #8922

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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-beta/services/container/resource_container_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -3612,35 +3612,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 @@ -3908,6 +3879,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
Loading