Skip to content

Commit

Permalink
Adds support for Graceful Updater in Compute Managed Instance Groups. (
Browse files Browse the repository at this point in the history
…#5975)

* Support new features of IGM.updatePolicy (#4956)

* Add new IGM.UpdatePolicy features - minimal_action=REFRESH and most_disruptive_allowed_action

* Fix documentation of most_disruptive_allowed_action

* Make most_disruptive_allowed_action an Optional field.

* Fix RMIG UpdatePolicy flattening.

* Fix most_disruptive_allowed_action documentation - new field is Optional.

* Fix most_disruptive_allowed_action documentation - and improve testing.

* Fix whitespaces in test.

Co-authored-by: Grzegorz Sancewicz <[email protected]>

* Always send minimal_action and most_disruptive_allowed_action with IGM.UpdatePolicy.

* Make minimal_action optional and send null values instead of empty strings

* Remove unnecesary appending to ForceSendFields array

* Fix documentation for minimal_action - field is no longer required.

* Revert making minimal_action optional.

Co-authored-by: Kamil Hajduczenia <[email protected]>
  • Loading branch information
gsancewicz and khajduczenia authored May 4, 2022
1 parent 9fbf070 commit 7a58cb7
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,15 @@ func resourceComputeInstanceGroupManager() *schema.Resource {
"minimal_action": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{"RESTART", "REPLACE"}, false),
Description: `Minimal action to be taken on an instance. You can specify either RESTART to restart existing instances or REPLACE to delete and create new instances from the target template. If you specify a RESTART, the Updater will attempt to perform that action only. However, if the Updater determines that the minimal action you specify is not enough to perform the update, it might perform a more disruptive action.`,
ValidateFunc: validation.StringInSlice([]string{"REFRESH", "RESTART", "REPLACE"}, false),
Description: `Minimal action to be taken on an instance. You can specify either REFRESH to update without stopping instances, RESTART to restart existing instances or REPLACE to delete and create new instances from the target template. If you specify a REFRESH, the Updater will attempt to perform that action only. However, if the Updater determines that the minimal action you specify is not enough to perform the update, it might perform a more disruptive action.`,
},

"most_disruptive_allowed_action": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{"NONE", "REFRESH", "RESTART", "REPLACE"}, false),
Description: `Most disruptive action that is allowed to be taken on an instance. You can specify either NONE to forbid any actions, REFRESH to allow actions that do not need instance restart, RESTART to allow actions that can be applied without instance replacing or REPLACE to allow all possible actions. If the Updater determines that the minimal update action needed is more disruptive than most disruptive allowed action you specify it will not perform the update at all.`,
},

"type": {
Expand Down Expand Up @@ -919,6 +926,12 @@ func expandUpdatePolicy(configured []interface{}) *compute.InstanceGroupManagerU
data := raw.(map[string]interface{})

updatePolicy.MinimalAction = data["minimal_action"].(string)
mostDisruptiveAllowedAction := data["most_disruptive_allowed_action"].(string)
if mostDisruptiveAllowedAction != "" {
updatePolicy.MostDisruptiveAllowedAction = mostDisruptiveAllowedAction
} else {
updatePolicy.NullFields = append(updatePolicy.NullFields, "MostDisruptiveAllowedAction")
}
updatePolicy.Type = data["type"].(string)
updatePolicy.ReplacementMethod = data["replacement_method"].(string)
<% unless version == "ga" -%>
Expand Down Expand Up @@ -1010,6 +1023,7 @@ func flattenUpdatePolicy(updatePolicy *compute.InstanceGroupManagerUpdatePolicy)
up["min_ready_sec"] = updatePolicy.MinReadySec
<% end -%>
up["minimal_action"] = updatePolicy.MinimalAction
up["most_disruptive_allowed_action"] = updatePolicy.MostDisruptiveAllowedAction
up["type"] = updatePolicy.Type
up["replacement_method"] = updatePolicy.ReplacementMethod
results = append(results, up)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,15 @@ func resourceComputeRegionInstanceGroupManager() *schema.Resource {
"minimal_action": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{"RESTART", "REPLACE"}, false),
Description: `Minimal action to be taken on an instance. You can specify either RESTART to restart existing instances or REPLACE to delete and create new instances from the target template. If you specify a RESTART, the Updater will attempt to perform that action only. However, if the Updater determines that the minimal action you specify is not enough to perform the update, it might perform a more disruptive action.`,
ValidateFunc: validation.StringInSlice([]string{"REFRESH", "RESTART", "REPLACE"}, false),
Description: `Minimal action to be taken on an instance. You can specify either REFRESH to update without stopping instances, RESTART to restart existing instances or REPLACE to delete and create new instances from the target template. If you specify a REFRESH, the Updater will attempt to perform that action only. However, if the Updater determines that the minimal action you specify is not enough to perform the update, it might perform a more disruptive action.`,
},

"most_disruptive_allowed_action": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{"NONE", "REFRESH", "RESTART", "REPLACE"}, false),
Description: `Most disruptive action that is allowed to be taken on an instance. You can specify either NONE to forbid any actions, REFRESH to allow actions that do not need instance restart, RESTART to allow actions that can be applied without instance replacing or REPLACE to allow all possible actions. If the Updater determines that the minimal update action needed is more disruptive than most disruptive allowed action you specify it will not perform the update at all.`,
},

"type": {
Expand Down Expand Up @@ -775,6 +782,12 @@ func expandRegionUpdatePolicy(configured []interface{}) *compute.InstanceGroupMa
data := raw.(map[string]interface{})

updatePolicy.MinimalAction = data["minimal_action"].(string)
mostDisruptiveAllowedAction := data["most_disruptive_allowed_action"].(string)
if mostDisruptiveAllowedAction != "" {
updatePolicy.MostDisruptiveAllowedAction = mostDisruptiveAllowedAction
} else {
updatePolicy.NullFields = append(updatePolicy.NullFields, "MostDisruptiveAllowedAction")
}
updatePolicy.Type = data["type"].(string)
updatePolicy.InstanceRedistributionType = data["instance_redistribution_type"].(string)
updatePolicy.ReplacementMethod = data["replacement_method"].(string)
Expand Down Expand Up @@ -838,6 +851,7 @@ func flattenRegionUpdatePolicy(updatePolicy *compute.InstanceGroupManagerUpdateP
up["min_ready_sec"] = updatePolicy.MinReadySec
<% end -%>
up["minimal_action"] = updatePolicy.MinimalAction
up["most_disruptive_allowed_action"] = updatePolicy.MostDisruptiveAllowedAction
up["type"] = updatePolicy.Type
up["instance_redistribution_type"] = updatePolicy.InstanceRedistributionType
up["replacement_method"] = updatePolicy.ReplacementMethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -933,10 +933,11 @@ resource "google_compute_instance_group_manager" "igm-rolling-update-policy" {
zone = "us-central1-c"
target_size = 3
update_policy {
type = "PROACTIVE"
minimal_action = "REPLACE"
max_surge_fixed = 2
max_unavailable_fixed = 2
type = "PROACTIVE"
minimal_action = "REPLACE"
most_disruptive_allowed_action = "REPLACE"
max_surge_fixed = 2
max_unavailable_fixed = 2
}
named_port {
name = "customhttp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1295,15 +1295,16 @@ resource "google_compute_region_instance_group_manager" "igm-rolling-update-poli
distribution_policy_zones = ["us-central1-a", "us-central1-f"]
target_size = 3
update_policy {
type = "PROACTIVE"
instance_redistribution_type = "NONE"
minimal_action = "REPLACE"
max_surge_fixed = 0
max_unavailable_fixed = 2
type = "PROACTIVE"
instance_redistribution_type = "NONE"
minimal_action = "REPLACE"
most_disruptive_allowed_action = "REPLACE"
max_surge_fixed = 0
max_unavailable_fixed = 2
<% unless version == "ga" -%>
min_ready_sec = 10
min_ready_sec = 10
<% end -%>
replacement_method = "RECREATE"
replacement_method = "RECREATE"
}
named_port {
name = "customhttp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,16 +149,19 @@ group. You can specify only one value. Structure is [documented below](#nested_a

```hcl
update_policy {
type = "PROACTIVE"
minimal_action = "REPLACE"
max_surge_percent = 20
max_unavailable_fixed = 2
min_ready_sec = 50
replacement_method = "RECREATE"
type = "PROACTIVE"
minimal_action = "REPLACE"
most_disruptive_allowed_action = "REPLACE"
max_surge_percent = 20
max_unavailable_fixed = 2
min_ready_sec = 50
replacement_method = "RECREATE"
}
```

* `minimal_action` - (Required) - Minimal action to be taken on an instance. You can specify either `RESTART` to restart existing instances or `REPLACE` to delete and create new instances from the target template. If you specify a `RESTART`, the Updater will attempt to perform that action only. However, if the Updater determines that the minimal action you specify is not enough to perform the update, it might perform a more disruptive action.
* `minimal_action` - (Required) - Minimal action to be taken on an instance. You can specify either `REFRESH` to update without stopping instances, `RESTART` to restart existing instances or `REPLACE` to delete and create new instances from the target template. If you specify a `REFRESH`, the Updater will attempt to perform that action only. However, if the Updater determines that the minimal action you specify is not enough to perform the update, it might perform a more disruptive action.

* `most_disruptive_allowed_action` - (Optional) - Most disruptive action that is allowed to be taken on an instance. You can specify either NONE to forbid any actions, REFRESH to allow actions that do not need instance restart, RESTART to allow actions that can be applied without instance replacing or REPLACE to allow all possible actions. If the Updater determines that the minimal update action needed is more disruptive than most disruptive allowed action you specify it will not perform the update at all.

* `type` - (Required) - The type of update process. You can specify either `PROACTIVE` so that the instance group manager proactively executes actions in order to bring instances to their target versions or `OPPORTUNISTIC` so that no action is proactively executed but the update will be performed as part of other actions (for example, resizes or recreateInstances calls).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,17 +158,20 @@ group. You can specify one or more values. For more information, see the [offici

```hcl
update_policy {
type = "PROACTIVE"
instance_redistribution_type = "PROACTIVE"
minimal_action = "REPLACE"
max_surge_percent = 20
max_unavailable_fixed = 2
min_ready_sec = 50
replacement_method = "RECREATE"
type = "PROACTIVE"
instance_redistribution_type = "PROACTIVE"
minimal_action = "REPLACE"
most_disruptive_allowed_action = "REPLACE"
max_surge_percent = 20
max_unavailable_fixed = 2
min_ready_sec = 50
replacement_method = "RECREATE"
}
```

* `minimal_action` - (Required) - Minimal action to be taken on an instance. You can specify either `RESTART` to restart existing instances or `REPLACE` to delete and create new instances from the target template. If you specify a `RESTART`, the Updater will attempt to perform that action only. However, if the Updater determines that the minimal action you specify is not enough to perform the update, it might perform a more disruptive action.
* `minimal_action` - (Required) - Minimal action to be taken on an instance. You can specify either `REFRESH` to update without stopping instances, `RESTART` to restart existing instances or `REPLACE` to delete and create new instances from the target template. If you specify a `REFRESH`, the Updater will attempt to perform that action only. However, if the Updater determines that the minimal action you specify is not enough to perform the update, it might perform a more disruptive action.

* `most_disruptive_allowed_action` - (Optional) - Most disruptive action that is allowed to be taken on an instance. You can specify either NONE to forbid any actions, REFRESH to allow actions that do not need instance restart, RESTART to allow actions that can be applied without instance replacing or REPLACE to allow all possible actions. If the Updater determines that the minimal update action needed is more disruptive than most disruptive allowed action you specify it will not perform the update at all.

* `type` - (Required) - The type of update process. You can specify either `PROACTIVE` so that the instance group manager proactively executes actions in order to bring instances to their target versions or `OPPORTUNISTIC` so that no action is proactively executed but the update will be performed as part of other actions (for example, resizes or recreateInstances calls).

Expand Down

0 comments on commit 7a58cb7

Please sign in to comment.