Skip to content

Commit 4b316f8

Browse files
Add support for default compute class on GKE (#14810) (#10552)
[upstream:79e70b1c649fdb914d2968a6c28d7bb5a2a8a8e0] Signed-off-by: Modular Magician <magic-modules@google.com>
1 parent 11e4f74 commit 4b316f8

File tree

4 files changed

+88
-0
lines changed

4 files changed

+88
-0
lines changed

.changelog/14810.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 `cluster_autoscaling.default_compute_class_enabled` field to `google_container_cluster` resource
3+
```

google-beta/services/container/resource_container_cluster.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -928,6 +928,11 @@ func ResourceContainerCluster() *schema.Resource {
928928
ValidateFunc: validation.StringInSlice([]string{"BALANCED", "OPTIMIZE_UTILIZATION"}, false),
929929
Description: `Configuration options for the Autoscaling profile feature, which lets you choose whether the cluster autoscaler should optimize for resource utilization or resource availability when deciding to remove nodes from a cluster. Can be BALANCED or OPTIMIZE_UTILIZATION. Defaults to BALANCED.`,
930930
},
931+
"default_compute_class_enabled": {
932+
Type: schema.TypeBool,
933+
Optional: true,
934+
Description: `Specifies whether default compute class behaviour is enabled. If enabled, cluster autoscaler will use Compute Class with name default for all the workloads, if not overriden.`,
935+
},
931936
},
932937
},
933938
},
@@ -5656,9 +5661,16 @@ func expandClusterAutoscaling(configured interface{}, d *schema.ResourceData) *c
56565661
}
56575662
}
56585663
}
5664+
var defaultCCConfig *container.DefaultComputeClassConfig
5665+
if defaultCCEnabled, ok := config["default_compute_class_enabled"]; ok {
5666+
defaultCCConfig = &container.DefaultComputeClassConfig{
5667+
Enabled: defaultCCEnabled.(bool),
5668+
}
5669+
}
56595670
return &container.ClusterAutoscaling{
56605671
EnableNodeAutoprovisioning: config["enabled"].(bool),
56615672
ResourceLimits: resourceLimits,
5673+
DefaultComputeClassConfig: defaultCCConfig,
56625674
AutoscalingProfile: config["autoscaling_profile"].(string),
56635675
AutoprovisioningNodePoolDefaults: expandAutoProvisioningDefaults(config["auto_provisioning_defaults"], d),
56645676
AutoprovisioningLocations: tpgresource.ConvertStringArr(config["auto_provisioning_locations"].([]interface{})),
@@ -7263,6 +7275,9 @@ func flattenClusterAutoscaling(a *container.ClusterAutoscaling) []map[string]int
72637275
r["enabled"] = false
72647276
}
72657277
r["autoscaling_profile"] = a.AutoscalingProfile
7278+
if a.DefaultComputeClassConfig != nil {
7279+
r["default_compute_class_enabled"] = a.DefaultComputeClassConfig.Enabled
7280+
}
72667281

72677282
return []map[string]interface{}{r}
72687283
}

google-beta/services/container/resource_container_cluster_test.go

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3777,6 +3777,74 @@ func TestAccContainerCluster_nodeAutoprovisioningNetworkTags(t *testing.T) {
37773777
})
37783778
}
37793779

3780+
func TestAccContainerCluster_withDefaultComputeClassEnabled(t *testing.T) {
3781+
t.Parallel()
3782+
3783+
clusterName := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10))
3784+
networkName := acctest.BootstrapSharedTestNetwork(t, "gke-cluster")
3785+
subnetworkName := acctest.BootstrapSubnet(t, "gke-cluster", networkName)
3786+
3787+
acctest.VcrTest(t, resource.TestCase{
3788+
PreCheck: func() { acctest.AccTestPreCheck(t) },
3789+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
3790+
CheckDestroy: testAccCheckContainerClusterDestroyProducer(t),
3791+
Steps: []resource.TestStep{
3792+
{
3793+
Config: testAccContainerCluster_withDefaultComputeClassEnabled(clusterName, networkName, subnetworkName, true),
3794+
Check: resource.ComposeTestCheckFunc(
3795+
resource.TestCheckResourceAttr("google_container_cluster.primary", "cluster_autoscaling.0.default_compute_class_enabled", "true"),
3796+
),
3797+
},
3798+
{
3799+
ResourceName: "google_container_cluster.primary",
3800+
ImportState: true,
3801+
ImportStateVerify: true,
3802+
ImportStateVerifyIgnore: []string{"deletion_protection"},
3803+
},
3804+
{
3805+
Config: testAccContainerCluster_withDefaultComputeClassEnabled(clusterName, networkName, subnetworkName, false),
3806+
Check: resource.ComposeTestCheckFunc(
3807+
resource.TestCheckResourceAttr("google_container_cluster.primary", "cluster_autoscaling.0.default_compute_class_enabled", "false"),
3808+
),
3809+
},
3810+
{
3811+
ResourceName: "google_container_cluster.primary",
3812+
ImportState: true,
3813+
ImportStateVerify: true,
3814+
ImportStateVerifyIgnore: []string{"deletion_protection"},
3815+
},
3816+
},
3817+
})
3818+
}
3819+
3820+
func testAccContainerCluster_withDefaultComputeClassEnabled(clusterName, networkName, subnetworkName string, enabled bool) string {
3821+
return fmt.Sprintf(`
3822+
resource "google_container_cluster" "primary" {
3823+
name = "%s"
3824+
location = "us-central1-a"
3825+
initial_node_count = 1
3826+
network = "%s"
3827+
subnetwork = "%s"
3828+
deletion_protection = false
3829+
3830+
cluster_autoscaling {
3831+
enabled = true
3832+
default_compute_class_enabled = %t
3833+
resource_limits {
3834+
resource_type = "cpu"
3835+
minimum = 1
3836+
maximum = 10
3837+
}
3838+
resource_limits {
3839+
resource_type = "memory"
3840+
minimum = 10
3841+
maximum = 100
3842+
}
3843+
}
3844+
}
3845+
`, clusterName, networkName, subnetworkName, enabled)
3846+
}
3847+
37803848
func TestAccContainerCluster_withShieldedNodes(t *testing.T) {
37813849
t.Parallel()
37823850

website/docs/r/container_cluster.html.markdown

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,8 @@ options for the [Autoscaling profile](https://cloud.google.com/kubernetes-engine
617617
feature, which lets you choose whether the cluster autoscaler should optimize for resource utilization or resource availability
618618
when deciding to remove nodes from a cluster. Can be `BALANCED` or `OPTIMIZE_UTILIZATION`. Defaults to `BALANCED`.
619619

620+
* `default_compute_class_enabled` - (Optional) Specifies whether default compute class behaviour is enabled. If enabled, cluster autoscaler will use Compute Class with name default for all the workloads, if not overriden.
621+
620622
<a name="nested_resource_limits"></a>The `resource_limits` block supports:
621623

622624
* `resource_type` - (Required) The type of the resource. For example, `cpu` and

0 commit comments

Comments
 (0)