Skip to content

Commit 0c109dc

Browse files
Add support for accelerated upgrade feature flags (#14265) (#10258)
[upstream:0109a298a4099cdf5c1b849ee808885e5e00d259] Signed-off-by: Modular Magician <[email protected]>
1 parent 7afac7d commit 0c109dc

File tree

6 files changed

+142
-6
lines changed

6 files changed

+142
-6
lines changed

.changelog/14265.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
container: added `gke_auto_upgrade_config` field to `google_container_cluster` resource
3+
```

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ require (
3434
golang.org/x/exp v0.0.0-20240409090435-93d18d7e34b8
3535
golang.org/x/net v0.41.0
3636
golang.org/x/oauth2 v0.30.0
37-
google.golang.org/api v0.237.0
37+
google.golang.org/api v0.238.0
3838
google.golang.org/genproto/googleapis/rpc v0.0.0-20250603155806-513f23925822
3939
google.golang.org/grpc v1.73.0
4040
google.golang.org/protobuf v1.36.6

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,8 +381,8 @@ golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8T
381381
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
382382
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
383383
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
384-
google.golang.org/api v0.237.0 h1:MP7XVsGZesOsx3Q8WVa4sUdbrsTvDSOERd3Vh4xj/wc=
385-
google.golang.org/api v0.237.0/go.mod h1:cOVEm2TpdAGHL2z+UwyS+kmlGr3bVWQQ6sYEqkKje50=
384+
google.golang.org/api v0.238.0 h1:+EldkglWIg/pWjkq97sd+XxH7PxakNYoe/rkSTbnvOs=
385+
google.golang.org/api v0.238.0/go.mod h1:cOVEm2TpdAGHL2z+UwyS+kmlGr3bVWQQ6sYEqkKje50=
386386
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
387387
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
388388
google.golang.org/appengine v1.6.8 h1:IhEN5q69dyKagZPYMSdIjS2HqprW324FRQZJcGqPAsM=

google-beta/services/container/resource_container_cluster.go

Lines changed: 83 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2099,6 +2099,24 @@ func ResourceContainerCluster() *schema.Resource {
20992099
},
21002100
},
21012101

2102+
"gke_auto_upgrade_config": {
2103+
Type: schema.TypeList,
2104+
Optional: true,
2105+
Computed: true,
2106+
Description: `Configuration options for the auto-upgrade patch type feature, which provide more control over the speed of automatic upgrades of your GKE clusters.`,
2107+
MaxItems: 1,
2108+
Elem: &schema.Resource{
2109+
Schema: map[string]*schema.Schema{
2110+
"patch_mode": {
2111+
Type: schema.TypeString,
2112+
Required: true,
2113+
Description: `The selected auto-upgrade patch type. Accepted values are:
2114+
* ACCELERATED: Upgrades to the latest available patch version in a given minor and release channel.`,
2115+
},
2116+
},
2117+
},
2118+
},
2119+
21022120
"tpu_ipv4_cidr_block": {
21032121
Computed: true,
21042122
Type: schema.TypeString,
@@ -2598,9 +2616,10 @@ func resourceContainerClusterCreate(d *schema.ResourceData, meta interface{}) er
25982616
WorkloadPolicyConfig: workloadPolicyConfig,
25992617
ForceSendFields: []string{"Enabled"},
26002618
},
2601-
ReleaseChannel: expandReleaseChannel(d.Get("release_channel")),
2602-
ClusterTelemetry: expandClusterTelemetry(d.Get("cluster_telemetry")),
2603-
EnableTpu: d.Get("enable_tpu").(bool),
2619+
ReleaseChannel: expandReleaseChannel(d.Get("release_channel")),
2620+
GkeAutoUpgradeConfig: expandGkeAutoUpgradeConfig(d.Get("gke_auto_upgrade_config")),
2621+
ClusterTelemetry: expandClusterTelemetry(d.Get("cluster_telemetry")),
2622+
EnableTpu: d.Get("enable_tpu").(bool),
26042623
NetworkConfig: &container.NetworkConfig{
26052624
EnableIntraNodeVisibility: d.Get("enable_intranode_visibility").(bool),
26062625
DefaultSnatStatus: expandDefaultSnatStatus(d.Get("default_snat_status")),
@@ -3151,6 +3170,9 @@ func resourceContainerClusterRead(d *schema.ResourceData, meta interface{}) erro
31513170
if err := d.Set("release_channel", flattenReleaseChannel(cluster.ReleaseChannel)); err != nil {
31523171
return err
31533172
}
3173+
if err := d.Set("gke_auto_upgrade_config", flattenGkeAutoUpgradeConfig(cluster.GkeAutoUpgradeConfig)); err != nil {
3174+
return err
3175+
}
31543176
if err := d.Set("notification_config", flattenNotificationConfig(cluster.NotificationConfig)); err != nil {
31553177
return err
31563178
}
@@ -3580,6 +3602,38 @@ func resourceContainerClusterUpdate(d *schema.ResourceData, meta interface{}) er
35803602
log.Printf("[INFO] GKE cluster %s Release Channel has been updated to %#v", d.Id(), req.Update.DesiredReleaseChannel)
35813603
}
35823604

3605+
if d.HasChange("gke_auto_upgrade_config") {
3606+
req := &container.UpdateClusterRequest{
3607+
Update: &container.ClusterUpdate{
3608+
GkeAutoUpgradeConfig: expandGkeAutoUpgradeConfig(d.Get("gke_auto_upgrade_config")),
3609+
},
3610+
}
3611+
updateF := func() error {
3612+
log.Println("[DEBUG] updating gke_auto_upgrade_config")
3613+
name := containerClusterFullName(project, location, clusterName)
3614+
clusterUpdateCall := config.NewContainerClient(userAgent).Projects.Locations.Clusters.Update(name, req)
3615+
if config.UserProjectOverride {
3616+
clusterUpdateCall.Header().Add("X-Goog-User-Project", project)
3617+
}
3618+
op, err := clusterUpdateCall.Do()
3619+
if err != nil {
3620+
return err
3621+
}
3622+
3623+
// Wait until it's updated
3624+
err = ContainerOperationWait(config, op, project, location, "updating GKE Auto Upgrade Config", userAgent, d.Timeout(schema.TimeoutUpdate))
3625+
log.Println("[DEBUG] done updating gke_auto_upgrade_config")
3626+
return err
3627+
}
3628+
3629+
// Call update serially.
3630+
if err := transport_tpg.LockedCall(lockKey, updateF); err != nil {
3631+
return err
3632+
}
3633+
3634+
log.Printf("[INFO] GKE cluster %s GKE Auto Upgrade Config has been updated to %#v", d.Id(), req.Update.GkeAutoUpgradeConfig)
3635+
}
3636+
35833637
if d.HasChange("enable_intranode_visibility") {
35843638
enabled := d.Get("enable_intranode_visibility").(bool)
35853639
req := &container.UpdateClusterRequest{
@@ -5888,6 +5942,17 @@ func expandReleaseChannel(configured interface{}) *container.ReleaseChannel {
58885942
}
58895943
}
58905944

5945+
func expandGkeAutoUpgradeConfig(configured interface{}) *container.GkeAutoUpgradeConfig {
5946+
l := configured.([]interface{})
5947+
if len(l) == 0 || l[0] == nil {
5948+
return nil
5949+
}
5950+
config := l[0].(map[string]interface{})
5951+
return &container.GkeAutoUpgradeConfig{
5952+
PatchMode: config["patch_mode"].(string),
5953+
}
5954+
}
5955+
58915956
func expandClusterTelemetry(configured interface{}) *container.ClusterTelemetry {
58925957
l := configured.([]interface{})
58935958
if len(l) == 0 || l[0] == nil {
@@ -6629,6 +6694,21 @@ func flattenReleaseChannel(c *container.ReleaseChannel) []map[string]interface{}
66296694
return result
66306695
}
66316696

6697+
func flattenGkeAutoUpgradeConfig(c *container.GkeAutoUpgradeConfig) []map[string]interface{} {
6698+
if c == nil {
6699+
return nil
6700+
}
6701+
6702+
result := []map[string]interface{}{}
6703+
if c.PatchMode != "" {
6704+
result = append(result, map[string]interface{}{
6705+
"patch_mode": c.PatchMode,
6706+
})
6707+
}
6708+
6709+
return result
6710+
}
6711+
66326712
func flattenClusterTelemetry(c *container.ClusterTelemetry) []map[string]interface{} {
66336713
result := []map[string]interface{}{}
66346714
if c != nil {

google-beta/services/container/resource_container_cluster_test.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1331,6 +1331,31 @@ func TestAccContainerCluster_withInvalidReleaseChannel(t *testing.T) {
13311331
})
13321332
}
13331333

1334+
func TestAccContainerCluster_withAcceleratedGkeAutoUpgradeConfig(t *testing.T) {
1335+
t.Parallel()
1336+
clusterName := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10))
1337+
networkName := acctest.BootstrapSharedTestNetwork(t, "gke-cluster")
1338+
subnetworkName := acctest.BootstrapSubnet(t, "gke-cluster", networkName)
1339+
1340+
acctest.VcrTest(t, resource.TestCase{
1341+
PreCheck: func() { acctest.AccTestPreCheck(t) },
1342+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
1343+
CheckDestroy: testAccCheckContainerClusterDestroyProducer(t),
1344+
Steps: []resource.TestStep{
1345+
{
1346+
Config: testAccContainerCluster_withGkeAutoUpgradeConfig(clusterName, "ACCELERATED", networkName, subnetworkName),
1347+
},
1348+
{
1349+
ResourceName: "google_container_cluster.with_gke_auto_upgrade_config",
1350+
ImportStateIdPrefix: "us-central1-a/",
1351+
ImportState: true,
1352+
ImportStateVerify: true,
1353+
ImportStateVerifyIgnore: []string{"min_master_version", "deletion_protection"},
1354+
},
1355+
},
1356+
})
1357+
}
1358+
13341359
func TestAccContainerCluster_withTelemetryEnabled(t *testing.T) {
13351360
t.Parallel()
13361361
clusterName := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10))
@@ -7457,6 +7482,24 @@ resource "google_container_cluster" "with_release_channel" {
74577482
`, clusterName, channel, networkName, subnetworkName)
74587483
}
74597484

7485+
func testAccContainerCluster_withGkeAutoUpgradeConfig(clusterName, patchMode, networkName, subnetworkName string) string {
7486+
return fmt.Sprintf(`
7487+
resource "google_container_cluster" "with_gke_auto_upgrade_config" {
7488+
name = "%s"
7489+
location = "us-central1-a"
7490+
initial_node_count = 1
7491+
7492+
gke_auto_upgrade_config {
7493+
patch_mode = "%s"
7494+
}
7495+
network = "%s"
7496+
subnetwork = "%s"
7497+
7498+
deletion_protection = false
7499+
}
7500+
`, clusterName, patchMode, networkName, subnetworkName)
7501+
}
7502+
74607503
func testAccContainerCluster_withTelemetryEnabled(clusterName, telemetryType, networkName, subnetworkName string) string {
74617504
return fmt.Sprintf(`
74627505
resource "google_container_cluster" "with_cluster_telemetry" {

website/docs/r/container_cluster.html.markdown

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,10 @@ field from your config will cause Terraform to stop managing your cluster's
344344
release channel, but will not unenroll it. Instead, use the `"UNSPECIFIED"`
345345
channel. Structure is [documented below](#nested_release_channel).
346346

347+
* `gke_auto_upgrade_config` - (Optional)
348+
Configuration options for the auto-upgrade patch type feature, which provide more control over the speed of automatic upgrades of your GKE clusters.
349+
Structure is [documented below](#nested_gke_auto_upgrade_config).
350+
347351
* `remove_default_node_pool` - (Optional) If `true`, deletes the default node
348352
pool upon cluster creation. If you're using `google_container_node_pool`
349353
resources with no default node pool, this should be set to `true`, alongside
@@ -1349,6 +1353,12 @@ not.
13491353
* STABLE: Every few months upgrade cadence; Production users who need stability above all else, and for whom frequent upgrades are too risky.
13501354
* EXTENDED: GKE provides extended support for Kubernetes minor versions through the Extended channel. With this channel, you can stay on a minor version for up to 24 months.
13511355

1356+
<a name="nested_gke_auto_upgrade_config"></a>The `gke_auto_upgrade_config` block supports:
1357+
1358+
* `patch_mode` - (Required) The selected patch mode.
1359+
Accepted values are:
1360+
* ACCELERATED: Upgrades to the latest available patch version in a given minor and release channel.
1361+
13521362
<a name="nested_cost_management_config"></a>The `cost_management_config` block supports:
13531363

13541364
* `enabled` (Optional) - Whether to enable the [cost allocation](https://cloud.google.com/kubernetes-engine/docs/how-to/cost-allocations) feature.

0 commit comments

Comments
 (0)