Skip to content

Commit 0ca0b4b

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

File tree

6 files changed

+141
-5
lines changed

6 files changed

+141
-5
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/services/container/resource_container_cluster.go

Lines changed: 82 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1963,6 +1963,24 @@ func ResourceContainerCluster() *schema.Resource {
19631963
},
19641964
},
19651965

1966+
"gke_auto_upgrade_config": {
1967+
Type: schema.TypeList,
1968+
Optional: true,
1969+
Computed: true,
1970+
Description: `Configuration options for the auto-upgrade patch type feature, which provide more control over the speed of automatic upgrades of your GKE clusters.`,
1971+
MaxItems: 1,
1972+
Elem: &schema.Resource{
1973+
Schema: map[string]*schema.Schema{
1974+
"patch_mode": {
1975+
Type: schema.TypeString,
1976+
Required: true,
1977+
Description: `The selected auto-upgrade patch type. Accepted values are:
1978+
* ACCELERATED: Upgrades to the latest available patch version in a given minor and release channel.`,
1979+
},
1980+
},
1981+
},
1982+
},
1983+
19661984
"tpu_ipv4_cidr_block": {
19671985
Computed: true,
19681986
Type: schema.TypeString,
@@ -2427,8 +2445,9 @@ func resourceContainerClusterCreate(d *schema.ResourceData, meta interface{}) er
24272445
WorkloadPolicyConfig: workloadPolicyConfig,
24282446
ForceSendFields: []string{"Enabled"},
24292447
},
2430-
ReleaseChannel: expandReleaseChannel(d.Get("release_channel")),
2431-
EnableTpu: d.Get("enable_tpu").(bool),
2448+
ReleaseChannel: expandReleaseChannel(d.Get("release_channel")),
2449+
GkeAutoUpgradeConfig: expandGkeAutoUpgradeConfig(d.Get("gke_auto_upgrade_config")),
2450+
EnableTpu: d.Get("enable_tpu").(bool),
24322451
NetworkConfig: &container.NetworkConfig{
24332452
EnableIntraNodeVisibility: d.Get("enable_intranode_visibility").(bool),
24342453
DefaultSnatStatus: expandDefaultSnatStatus(d.Get("default_snat_status")),
@@ -2970,6 +2989,9 @@ func resourceContainerClusterRead(d *schema.ResourceData, meta interface{}) erro
29702989
if err := d.Set("release_channel", flattenReleaseChannel(cluster.ReleaseChannel)); err != nil {
29712990
return err
29722991
}
2992+
if err := d.Set("gke_auto_upgrade_config", flattenGkeAutoUpgradeConfig(cluster.GkeAutoUpgradeConfig)); err != nil {
2993+
return err
2994+
}
29732995
if err := d.Set("notification_config", flattenNotificationConfig(cluster.NotificationConfig)); err != nil {
29742996
return err
29752997
}
@@ -3384,6 +3406,38 @@ func resourceContainerClusterUpdate(d *schema.ResourceData, meta interface{}) er
33843406
log.Printf("[INFO] GKE cluster %s Release Channel has been updated to %#v", d.Id(), req.Update.DesiredReleaseChannel)
33853407
}
33863408

3409+
if d.HasChange("gke_auto_upgrade_config") {
3410+
req := &container.UpdateClusterRequest{
3411+
Update: &container.ClusterUpdate{
3412+
GkeAutoUpgradeConfig: expandGkeAutoUpgradeConfig(d.Get("gke_auto_upgrade_config")),
3413+
},
3414+
}
3415+
updateF := func() error {
3416+
log.Println("[DEBUG] updating gke_auto_upgrade_config")
3417+
name := containerClusterFullName(project, location, clusterName)
3418+
clusterUpdateCall := config.NewContainerClient(userAgent).Projects.Locations.Clusters.Update(name, req)
3419+
if config.UserProjectOverride {
3420+
clusterUpdateCall.Header().Add("X-Goog-User-Project", project)
3421+
}
3422+
op, err := clusterUpdateCall.Do()
3423+
if err != nil {
3424+
return err
3425+
}
3426+
3427+
// Wait until it's updated
3428+
err = ContainerOperationWait(config, op, project, location, "updating GKE Auto Upgrade Config", userAgent, d.Timeout(schema.TimeoutUpdate))
3429+
log.Println("[DEBUG] done updating gke_auto_upgrade_config")
3430+
return err
3431+
}
3432+
3433+
// Call update serially.
3434+
if err := transport_tpg.LockedCall(lockKey, updateF); err != nil {
3435+
return err
3436+
}
3437+
3438+
log.Printf("[INFO] GKE cluster %s GKE Auto Upgrade Config has been updated to %#v", d.Id(), req.Update.GkeAutoUpgradeConfig)
3439+
}
3440+
33873441
if d.HasChange("enable_intranode_visibility") {
33883442
enabled := d.Get("enable_intranode_visibility").(bool)
33893443
req := &container.UpdateClusterRequest{
@@ -5539,6 +5593,17 @@ func expandReleaseChannel(configured interface{}) *container.ReleaseChannel {
55395593
}
55405594
}
55415595

5596+
func expandGkeAutoUpgradeConfig(configured interface{}) *container.GkeAutoUpgradeConfig {
5597+
l := configured.([]interface{})
5598+
if len(l) == 0 || l[0] == nil {
5599+
return nil
5600+
}
5601+
config := l[0].(map[string]interface{})
5602+
return &container.GkeAutoUpgradeConfig{
5603+
PatchMode: config["patch_mode"].(string),
5604+
}
5605+
}
5606+
55425607
func expandDefaultSnatStatus(configured interface{}) *container.DefaultSnatStatus {
55435608
l := configured.([]interface{})
55445609
if len(l) == 0 || l[0] == nil {
@@ -6214,6 +6279,21 @@ func flattenReleaseChannel(c *container.ReleaseChannel) []map[string]interface{}
62146279
return result
62156280
}
62166281

6282+
func flattenGkeAutoUpgradeConfig(c *container.GkeAutoUpgradeConfig) []map[string]interface{} {
6283+
if c == nil {
6284+
return nil
6285+
}
6286+
6287+
result := []map[string]interface{}{}
6288+
if c.PatchMode != "" {
6289+
result = append(result, map[string]interface{}{
6290+
"patch_mode": c.PatchMode,
6291+
})
6292+
}
6293+
6294+
return result
6295+
}
6296+
62176297
func flattenDefaultSnatStatus(c *container.DefaultSnatStatus) []map[string]interface{} {
62186298
result := []map[string]interface{}{}
62196299
if c != nil {

google/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_withMasterAuthorizedNetworksConfig(t *testing.T) {
13351360
t.Parallel()
13361361

@@ -7028,6 +7053,24 @@ resource "google_container_cluster" "with_release_channel" {
70287053
`, clusterName, channel, networkName, subnetworkName)
70297054
}
70307055

7056+
func testAccContainerCluster_withGkeAutoUpgradeConfig(clusterName, patchMode, networkName, subnetworkName string) string {
7057+
return fmt.Sprintf(`
7058+
resource "google_container_cluster" "with_gke_auto_upgrade_config" {
7059+
name = "%s"
7060+
location = "us-central1-a"
7061+
initial_node_count = 1
7062+
7063+
gke_auto_upgrade_config {
7064+
patch_mode = "%s"
7065+
}
7066+
network = "%s"
7067+
subnetwork = "%s"
7068+
7069+
deletion_protection = false
7070+
}
7071+
`, clusterName, patchMode, networkName, subnetworkName)
7072+
}
7073+
70317074
func testAccContainerCluster_removeNetworkPolicy(clusterName, networkName, subnetworkName string) string {
70327075
return fmt.Sprintf(`
70337076
resource "google_container_cluster" "with_network_policy_enabled" {

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)