Skip to content

Commit 3cda11f

Browse files
container: add support for network_performance_config (#14095) (#23098)
[upstream:249d6411f0e3a2046ca44760834c8f86e5647dd1] Signed-off-by: Modular Magician <[email protected]>
1 parent 479f2da commit 3cda11f

File tree

4 files changed

+132
-0
lines changed

4 files changed

+132
-0
lines changed

.changelog/14095.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 `network_performance_config` field to `google_container_cluster` resource
3+
```

google/services/container/resource_container_cluster.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2252,6 +2252,21 @@ func ResourceContainerCluster() *schema.Resource {
22522252
Description: `Defines the config of in-transit encryption`,
22532253
ValidateFunc: validation.StringInSlice([]string{"IN_TRANSIT_ENCRYPTION_CONFIG_UNSPECIFIED", "IN_TRANSIT_ENCRYPTION_DISABLED", "IN_TRANSIT_ENCRYPTION_INTER_NODE_TRANSPARENT"}, false),
22542254
},
2255+
"network_performance_config": {
2256+
Type: schema.TypeList,
2257+
Optional: true,
2258+
MaxItems: 1,
2259+
Description: `Network bandwidth tier configuration.`,
2260+
Elem: &schema.Resource{
2261+
Schema: map[string]*schema.Schema{
2262+
"total_egress_bandwidth_tier": {
2263+
Type: schema.TypeString,
2264+
Required: true,
2265+
Description: `Specifies the total network bandwidth tier for NodePools in the cluster.`,
2266+
},
2267+
},
2268+
},
2269+
},
22552270
},
22562271
}
22572272
}
@@ -2412,6 +2427,7 @@ func resourceContainerClusterCreate(d *schema.ResourceData, meta interface{}) er
24122427
EnableMultiNetworking: d.Get("enable_multi_networking").(bool),
24132428
DefaultEnablePrivateNodes: expandDefaultEnablePrivateNodes(d),
24142429
EnableFqdnNetworkPolicy: d.Get("enable_fqdn_network_policy").(bool),
2430+
NetworkPerformanceConfig: expandNetworkPerformanceConfig(d.Get("network_performance_config")),
24152431
},
24162432
MasterAuth: expandMasterAuth(d.Get("master_auth")),
24172433
NotificationConfig: expandNotificationConfig(d.Get("notification_config")),
@@ -3078,6 +3094,9 @@ func resourceContainerClusterRead(d *schema.ResourceData, meta interface{}) erro
30783094
if err := d.Set("gateway_api_config", flattenGatewayApiConfig(cluster.NetworkConfig.GatewayApiConfig)); err != nil {
30793095
return err
30803096
}
3097+
if err := d.Set("network_performance_config", flattenNetworkPerformanceConfig(cluster.NetworkConfig.NetworkPerformanceConfig)); err != nil {
3098+
return err
3099+
}
30813100
if err := d.Set("fleet", flattenFleet(cluster.Fleet)); err != nil {
30823101
return err
30833102
}
@@ -4284,6 +4303,24 @@ func resourceContainerClusterUpdate(d *schema.ResourceData, meta interface{}) er
42844303
log.Printf("[INFO] GKE cluster %s resource usage export config has been updated", d.Id())
42854304
}
42864305

4306+
if d.HasChange("network_performance_config") {
4307+
if npc, ok := d.GetOk("network_performance_config"); ok {
4308+
req := &container.UpdateClusterRequest{
4309+
Update: &container.ClusterUpdate{
4310+
DesiredNetworkPerformanceConfig: expandNetworkPerformanceConfig(npc),
4311+
},
4312+
}
4313+
4314+
updateF := updateFunc(req, "updating GKE Network Performance Config")
4315+
// Call update serially.
4316+
if err := transport_tpg.LockedCall(lockKey, updateF); err != nil {
4317+
return err
4318+
}
4319+
4320+
log.Printf("[INFO] GKE cluster %s Network Performance Config has been updated", d.Id())
4321+
}
4322+
}
4323+
42874324
if d.HasChange("gateway_api_config") {
42884325
if gac, ok := d.GetOk("gateway_api_config"); ok {
42894326
req := &container.UpdateClusterRequest{
@@ -5629,6 +5666,18 @@ func expandDnsConfig(configured interface{}) *container.DNSConfig {
56295666
}
56305667
}
56315668

5669+
func expandNetworkPerformanceConfig(configured interface{}) *container.ClusterNetworkPerformanceConfig {
5670+
l := configured.([]interface{})
5671+
if len(l) == 0 || l[0] == nil {
5672+
return nil
5673+
}
5674+
5675+
config := l[0].(map[string]interface{})
5676+
return &container.ClusterNetworkPerformanceConfig{
5677+
TotalEgressBandwidthTier: config["total_egress_bandwidth_tier"].(string),
5678+
}
5679+
}
5680+
56325681
func expandGatewayApiConfig(configured interface{}) *container.GatewayAPIConfig {
56335682
l := configured.([]interface{})
56345683
if len(l) == 0 || l[0] == nil {
@@ -6548,6 +6597,17 @@ func flattenDnsConfig(c *container.DNSConfig) []map[string]interface{} {
65486597
}
65496598
}
65506599

6600+
func flattenNetworkPerformanceConfig(c *container.ClusterNetworkPerformanceConfig) []map[string]interface{} {
6601+
if c == nil {
6602+
return nil
6603+
}
6604+
return []map[string]interface{}{
6605+
{
6606+
"total_egress_bandwidth_tier": c.TotalEgressBandwidthTier,
6607+
},
6608+
}
6609+
}
6610+
65516611
func flattenGatewayApiConfig(c *container.GatewayAPIConfig) []map[string]interface{} {
65526612
if c == nil {
65536613
return nil

google/services/container/resource_container_cluster_test.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,45 @@ func TestAccContainerCluster_inTransitEncryptionConfig(t *testing.T) {
701701
})
702702
}
703703

704+
func TestAccContainerCluster_networkPerformanceConfig(t *testing.T) {
705+
t.Parallel()
706+
707+
clusterName := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10))
708+
networkName := acctest.BootstrapSharedTestNetwork(t, "gke-cluster")
709+
subnetworkName := acctest.BootstrapSubnet(t, "gke-cluster", networkName)
710+
acctest.VcrTest(t, resource.TestCase{
711+
PreCheck: func() { acctest.AccTestPreCheck(t) },
712+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
713+
CheckDestroy: testAccCheckContainerClusterDestroyProducer(t),
714+
Steps: []resource.TestStep{
715+
{
716+
Config: testAccContainerCluster_networkPerformanceConfig(clusterName, networkName, subnetworkName, "TIER_1"),
717+
Check: resource.ComposeAggregateTestCheckFunc(
718+
resource.TestCheckResourceAttr("google_container_cluster.primary", "network_performance_config.0.total_egress_bandwidth_tier", "TIER_1"),
719+
),
720+
},
721+
{
722+
ResourceName: "google_container_cluster.primary",
723+
ImportState: true,
724+
ImportStateVerify: true,
725+
ImportStateVerifyIgnore: []string{"deletion_protection"},
726+
},
727+
{
728+
Config: testAccContainerCluster_networkPerformanceConfig(clusterName, networkName, subnetworkName, "TIER_UNSPECIFIED"),
729+
Check: resource.ComposeAggregateTestCheckFunc(
730+
resource.TestCheckResourceAttr("google_container_cluster.primary", "network_performance_config.0.total_egress_bandwidth_tier", "TIER_UNSPECIFIED"),
731+
),
732+
},
733+
{
734+
ResourceName: "google_container_cluster.primary",
735+
ImportState: true,
736+
ImportStateVerify: true,
737+
ImportStateVerifyIgnore: []string{"deletion_protection"},
738+
},
739+
},
740+
})
741+
}
742+
704743
func TestAccContainerCluster_withFQDNNetworkPolicy(t *testing.T) {
705744
t.Parallel()
706745

@@ -12846,3 +12885,27 @@ resource "google_container_cluster" "primary" {
1284612885
}
1284712886
`, name, networkName, subnetworkName, config)
1284812887
}
12888+
12889+
func testAccContainerCluster_networkPerformanceConfig(name, networkName, subnetworkName, config string) string {
12890+
return fmt.Sprintf(`
12891+
resource "google_container_cluster" "primary" {
12892+
name = "%s"
12893+
location = "us-central1-a"
12894+
initial_node_count = 1
12895+
network = "%s"
12896+
subnetwork = "%s"
12897+
deletion_protection = false
12898+
12899+
node_config {
12900+
machine_type = "n2-standard-32"
12901+
gvnic {
12902+
enabled = true
12903+
}
12904+
}
12905+
12906+
network_performance_config {
12907+
total_egress_bandwidth_tier = "%s"
12908+
}
12909+
}
12910+
`, name, networkName, subnetworkName, config)
12911+
}

website/docs/r/container_cluster.html.markdown

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -955,6 +955,8 @@ gvnic {
955955
* `local_ssd_count` - (Optional) The amount of local SSD disks that will be
956956
attached to each cluster node. Defaults to 0.
957957

958+
* `network_performance_config` - (Optional) Network bandwidth tier configuration. Structure is [documented below](#network_performance_config).
959+
958960
* `machine_type` - (Optional) The name of a Google Compute Engine machine type.
959961
Defaults to `e2-medium`. To create a custom machine type, value should be set as specified
960962
[here](https://cloud.google.com/compute/docs/reference/latest/instances#machineType).
@@ -1141,6 +1143,10 @@ sole_tenant_config {
11411143

11421144
* `max_shared_clients_per_gpu` (Required) - The maximum number of containers that can share a GPU.
11431145

1146+
<a name="network_performance_config"></a>The `network_performance_config` block supports:
1147+
1148+
* `total_egress_bandwidth_tier` (Required) - Specifies the total network bandwidth tier for NodePools in the cluster.
1149+
11441150
<a name="nested_workload_identity_config"></a> The `workload_identity_config` block supports:
11451151

11461152
* `workload_pool` (Optional) - The workload pool to attach all Kubernetes service accounts to.

0 commit comments

Comments
 (0)