Skip to content

Explicitly set update_policy on GCE instance group managers #17411

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
merged 4 commits into from
Jun 12, 2025
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions pkg/model/gcemodel/autoscalinggroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ func (b *AutoscalingGroupModelBuilder) Build(c *fi.CloudupModelBuilderContext) e
Lifecycle: b.Lifecycle,
Zone: s(zone),
TargetSize: fi.PtrTo(int64(targetSize)),
UpdatePolicy: &gcetasks.UpdatePolicy{MinimalAction: "REPLACE", Type: "OPPORTUNISTIC"},
BaseInstanceName: s(ig.ObjectMeta.Name),
InstanceTemplate: instanceTemplate,
ListManagedInstancesResults: "PAGINATED",
Expand Down
24 changes: 24 additions & 0 deletions tests/integration/update_cluster/ha_gce/kubernetes.tf
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,10 @@ resource "google_compute_instance_group_manager" "a-master-us-test1-a-ha-gce-exa
list_managed_instances_results = "PAGINATED"
name = "a-master-us-test1-a-ha-gce-example-com"
target_size = 1
update_policy {
minimal_action = "REPLACE"
type = "OPPORTUNISTIC"
}
version {
instance_template = google_compute_instance_template.master-us-test1-a-ha-gce-example-com.self_link
}
Expand All @@ -508,6 +512,10 @@ resource "google_compute_instance_group_manager" "a-nodes-ha-gce-example-com" {
list_managed_instances_results = "PAGINATED"
name = "a-nodes-ha-gce-example-com"
target_size = 1
update_policy {
minimal_action = "REPLACE"
type = "OPPORTUNISTIC"
}
version {
instance_template = google_compute_instance_template.nodes-ha-gce-example-com.self_link
}
Expand All @@ -519,6 +527,10 @@ resource "google_compute_instance_group_manager" "b-master-us-test1-b-ha-gce-exa
list_managed_instances_results = "PAGINATED"
name = "b-master-us-test1-b-ha-gce-example-com"
target_size = 1
update_policy {
minimal_action = "REPLACE"
type = "OPPORTUNISTIC"
}
version {
instance_template = google_compute_instance_template.master-us-test1-b-ha-gce-example-com.self_link
}
Expand All @@ -530,6 +542,10 @@ resource "google_compute_instance_group_manager" "b-nodes-ha-gce-example-com" {
list_managed_instances_results = "PAGINATED"
name = "b-nodes-ha-gce-example-com"
target_size = 1
update_policy {
minimal_action = "REPLACE"
type = "OPPORTUNISTIC"
}
version {
instance_template = google_compute_instance_template.nodes-ha-gce-example-com.self_link
}
Expand All @@ -541,6 +557,10 @@ resource "google_compute_instance_group_manager" "c-master-us-test1-c-ha-gce-exa
list_managed_instances_results = "PAGINATED"
name = "c-master-us-test1-c-ha-gce-example-com"
target_size = 1
update_policy {
minimal_action = "REPLACE"
type = "OPPORTUNISTIC"
}
version {
instance_template = google_compute_instance_template.master-us-test1-c-ha-gce-example-com.self_link
}
Expand All @@ -552,6 +572,10 @@ resource "google_compute_instance_group_manager" "c-nodes-ha-gce-example-com" {
list_managed_instances_results = "PAGINATED"
name = "c-nodes-ha-gce-example-com"
target_size = 0
update_policy {
minimal_action = "REPLACE"
type = "OPPORTUNISTIC"
}
version {
instance_template = google_compute_instance_template.nodes-ha-gce-example-com.self_link
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,10 @@ resource "google_compute_instance_group_manager" "a-master-us-test1-a-minimal-ex
list_managed_instances_results = "PAGINATED"
name = "a-master-us-test1-a-minimal-example-com"
target_size = 1
update_policy {
minimal_action = "REPLACE"
type = "OPPORTUNISTIC"
}
version {
instance_template = google_compute_instance_template.master-us-test1-a-minimal-example-com.self_link
}
Expand All @@ -436,6 +440,10 @@ resource "google_compute_instance_group_manager" "a-nodes-minimal-example-com" {
list_managed_instances_results = "PAGINATED"
name = "a-nodes-minimal-example-com"
target_size = 1
update_policy {
minimal_action = "REPLACE"
type = "OPPORTUNISTIC"
}
version {
instance_template = google_compute_instance_template.nodes-minimal-example-com.self_link
}
Expand Down
8 changes: 8 additions & 0 deletions tests/integration/update_cluster/minimal_gce/kubernetes.tf
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,10 @@ resource "google_compute_instance_group_manager" "a-master-us-test1-a-minimal-gc
list_managed_instances_results = "PAGINATED"
name = "a-master-us-test1-a-minimal-gce-example-com"
target_size = 1
update_policy {
minimal_action = "REPLACE"
type = "OPPORTUNISTIC"
}
version {
instance_template = google_compute_instance_template.master-us-test1-a-minimal-gce-example-com.self_link
}
Expand All @@ -412,6 +416,10 @@ resource "google_compute_instance_group_manager" "a-nodes-minimal-gce-example-co
list_managed_instances_results = "PAGINATED"
name = "a-nodes-minimal-gce-example-com"
target_size = 2
update_policy {
minimal_action = "REPLACE"
type = "OPPORTUNISTIC"
}
version {
instance_template = google_compute_instance_template.nodes-minimal-gce-example-com.self_link
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,10 @@ resource "google_compute_instance_group_manager" "a-master-us-test1-a-minimal-gc
list_managed_instances_results = "PAGINATED"
name = "a-master-us-test1-a-minimal-gce-example-com"
target_size = 1
update_policy {
minimal_action = "REPLACE"
type = "OPPORTUNISTIC"
}
version {
instance_template = google_compute_instance_template.master-us-test1-a-minimal-gce-example-com.self_link
}
Expand All @@ -476,6 +480,10 @@ resource "google_compute_instance_group_manager" "a-nodes-minimal-gce-example-co
list_managed_instances_results = "PAGINATED"
name = "a-nodes-minimal-gce-example-com"
target_size = 2
update_policy {
minimal_action = "REPLACE"
type = "OPPORTUNISTIC"
}
version {
instance_template = google_compute_instance_template.nodes-minimal-gce-example-com.self_link
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,10 @@ resource "google_compute_instance_group_manager" "a-master-us-test1-a-minimal-gc
list_managed_instances_results = "PAGINATED"
name = "a-master-us-test1-a-minimal-gce-ilb-example-com"
target_size = 1
update_policy {
minimal_action = "REPLACE"
type = "OPPORTUNISTIC"
}
version {
instance_template = google_compute_instance_template.master-us-test1-a-minimal-gce-ilb-example-com.self_link
}
Expand All @@ -445,6 +449,10 @@ resource "google_compute_instance_group_manager" "a-nodes-minimal-gce-ilb-exampl
list_managed_instances_results = "PAGINATED"
name = "a-nodes-minimal-gce-ilb-example-com"
target_size = 2
update_policy {
minimal_action = "REPLACE"
type = "OPPORTUNISTIC"
}
version {
instance_template = google_compute_instance_template.nodes-minimal-gce-ilb-example-com.self_link
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,10 @@ resource "google_compute_instance_group_manager" "a-master-us-test1-a-minimal-gc
list_managed_instances_results = "PAGINATED"
name = "a-master-us-test1-a-minimal-gce-with-a-very-very-very-ve-j0fh8f"
target_size = 1
update_policy {
minimal_action = "REPLACE"
type = "OPPORTUNISTIC"
}
version {
instance_template = google_compute_instance_template.master-us-test1-a-minimal-gce-with-a-very-very-very-very-very-long-name-example-com.self_link
}
Expand All @@ -445,6 +449,10 @@ resource "google_compute_instance_group_manager" "a-nodes-minimal-gce-with-a-ver
list_managed_instances_results = "PAGINATED"
name = "a-nodes-minimal-gce-with-a-very-very-very-very-very-long-qk78uj"
target_size = 2
update_policy {
minimal_action = "REPLACE"
type = "OPPORTUNISTIC"
}
version {
instance_template = google_compute_instance_template.nodes-minimal-gce-with-a-very-very-very-very-very-long-name-example-com.self_link
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,10 @@ resource "google_compute_instance_group_manager" "a-master-us-test1-a-minimal-gc
list_managed_instances_results = "PAGINATED"
name = "a-master-us-test1-a-minimal-gce-with-a-very-very-very-ve-j0fh8f"
target_size = 1
update_policy {
minimal_action = "REPLACE"
type = "OPPORTUNISTIC"
}
version {
instance_template = google_compute_instance_template.master-us-test1-a-minimal-gce-with-a-very-very-very-very-very-long-name-example-com.self_link
}
Expand All @@ -412,6 +416,10 @@ resource "google_compute_instance_group_manager" "a-nodes-minimal-gce-with-a-ver
list_managed_instances_results = "PAGINATED"
name = "a-nodes-minimal-gce-with-a-very-very-very-very-very-long-qk78uj"
target_size = 2
update_policy {
minimal_action = "REPLACE"
type = "OPPORTUNISTIC"
}
version {
instance_template = google_compute_instance_template.nodes-minimal-gce-with-a-very-very-very-very-very-long-name-example-com.self_link
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,10 @@ resource "google_compute_instance_group_manager" "a-master-us-test1-a-minimal-gc
name = "a-master-us-test1-a-minimal-gce-plb-example-com"
target_pools = [google_compute_target_pool.api-minimal-gce-plb-example-com.self_link]
target_size = 1
update_policy {
minimal_action = "REPLACE"
type = "OPPORTUNISTIC"
}
version {
instance_template = google_compute_instance_template.master-us-test1-a-minimal-gce-plb-example-com.self_link
}
Expand All @@ -469,6 +473,10 @@ resource "google_compute_instance_group_manager" "a-nodes-minimal-gce-plb-exampl
list_managed_instances_results = "PAGINATED"
name = "a-nodes-minimal-gce-plb-example-com"
target_size = 2
update_policy {
minimal_action = "REPLACE"
type = "OPPORTUNISTIC"
}
version {
instance_template = google_compute_instance_template.nodes-minimal-gce-plb-example-com.self_link
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,10 @@ resource "google_compute_instance_group_manager" "a-master-us-test1-a-minimal-gc
list_managed_instances_results = "PAGINATED"
name = "a-master-us-test1-a-minimal-gce-private-example-com"
target_size = 1
update_policy {
minimal_action = "REPLACE"
type = "OPPORTUNISTIC"
}
version {
instance_template = google_compute_instance_template.master-us-test1-a-minimal-gce-private-example-com.self_link
}
Expand All @@ -412,6 +416,10 @@ resource "google_compute_instance_group_manager" "a-nodes-minimal-gce-private-ex
list_managed_instances_results = "PAGINATED"
name = "a-nodes-minimal-gce-private-example-com"
target_size = 2
update_policy {
minimal_action = "REPLACE"
type = "OPPORTUNISTIC"
}
version {
instance_template = google_compute_instance_template.nodes-minimal-gce-private-example-com.self_link
}
Expand Down
24 changes: 24 additions & 0 deletions upup/pkg/fi/cloudup/gcetasks/instancegroupmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type InstanceGroupManager struct {
InstanceTemplate *InstanceTemplate
ListManagedInstancesResults string
TargetSize *int64
UpdatePolicy *UpdatePolicy

TargetPools []*TargetPool
}
Expand Down Expand Up @@ -66,6 +67,10 @@ func (e *InstanceGroupManager) Find(c *fi.CloudupContext) (*InstanceGroupManager
actual.InstanceTemplate = &InstanceTemplate{ID: fi.PtrTo(lastComponent(r.InstanceTemplate))}
actual.ListManagedInstancesResults = r.ListManagedInstancesResults

if policy := r.UpdatePolicy; policy != nil {
actual.UpdatePolicy = &UpdatePolicy{MinimalAction: r.UpdatePolicy.MinimalAction, Type: r.UpdatePolicy.Type}
}

for _, targetPool := range r.TargetPools {
actual.TargetPools = append(actual.TargetPools, &TargetPool{
Name: fi.PtrTo(lastComponent(targetPool)),
Expand Down Expand Up @@ -104,6 +109,13 @@ func (_ *InstanceGroupManager) RenderGCE(t *gce.GCEAPITarget, a, e, changes *Ins
ListManagedInstancesResults: e.ListManagedInstancesResults,
}

if policy := e.UpdatePolicy; policy != nil {
i.UpdatePolicy = &compute.InstanceGroupManagerUpdatePolicy{
MinimalAction: e.UpdatePolicy.MinimalAction,
Type: e.UpdatePolicy.Type,
}
}

for _, targetPool := range e.TargetPools {
i.TargetPools = append(i.TargetPools, targetPool.URL(t.Cloud))
}
Expand Down Expand Up @@ -181,9 +193,15 @@ type terraformInstanceGroupManager struct {
ListManagedInstancesResults string `cty:"list_managed_instances_results"`
Version *terraformVersion `cty:"version"`
TargetSize *int64 `cty:"target_size"`
UpdatePolicy *terraformUpdatePolicy `cty:"update_policy"`
TargetPools []*terraformWriter.Literal `cty:"target_pools"`
}

type terraformUpdatePolicy struct {
MinimalAction string `cty:"minimal_action"`
Type string `cty:"type"`
}

type terraformVersion struct {
InstanceTemplate *terraformWriter.Literal `cty:"instance_template"`
}
Expand All @@ -196,6 +214,12 @@ func (_ *InstanceGroupManager) RenderTerraform(t *terraform.TerraformTarget, a,
TargetSize: e.TargetSize,
ListManagedInstancesResults: e.ListManagedInstancesResults,
}
if policy := e.UpdatePolicy; policy != nil {
tf.UpdatePolicy = &terraformUpdatePolicy{
MinimalAction: e.UpdatePolicy.MinimalAction,
Type: e.UpdatePolicy.Type,
}
}
tf.Version = &terraformVersion{
InstanceTemplate: e.InstanceTemplate.TerraformLink(),
}
Expand Down
31 changes: 31 additions & 0 deletions upup/pkg/fi/cloudup/gcetasks/updatepolicy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
Copyright 2025 The Kubernetes Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package gcetasks

import "k8s.io/kops/upup/pkg/fi"

// UpdatePolicy represents a GCE instance group manager UpdatePolicy
type UpdatePolicy struct {
MinimalAction string
Type string
}

var _ fi.CloudupHasDependencies = &UpdatePolicy{}

func (_ *UpdatePolicy) GetDependencies(tasks map[string]fi.CloudupTask) []fi.CloudupTask {
return nil
}