Skip to content

Commit 5cd0fba

Browse files
move multi-network to GA (#11062) (#18842)
[upstream:06b986e64435d596263f0f5bbe0f3121cc51561e] Signed-off-by: Modular Magician <[email protected]>
1 parent f675b32 commit 5cd0fba

7 files changed

+367
-9
lines changed

.changelog/11062.txt

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
```release-note:enhancement
2+
container: promoted `enable_multi_networking` to GA in the `google_container_cluster` resource
3+
```
4+
```release-note:enhancement
5+
container: promoted `additional_node_network_configs` and `additional_pod_network_configs` fields to GA in the `google_container_node_pool` resource
6+
```

google/services/container/resource_container_cluster.go

+11
Original file line numberDiff line numberDiff line change
@@ -1832,6 +1832,13 @@ func ResourceContainerCluster() *schema.Resource {
18321832
Description: `Whether L4ILB Subsetting is enabled for this cluster.`,
18331833
Default: false,
18341834
},
1835+
"enable_multi_networking": {
1836+
Type: schema.TypeBool,
1837+
Optional: true,
1838+
ForceNew: true,
1839+
Description: `Whether multi-networking is enabled for this cluster.`,
1840+
Default: false,
1841+
},
18351842
"private_ipv6_google_access": {
18361843
Type: schema.TypeString,
18371844
Optional: true,
@@ -2119,6 +2126,7 @@ func resourceContainerClusterCreate(d *schema.ResourceData, meta interface{}) er
21192126
EnableL4ilbSubsetting: d.Get("enable_l4_ilb_subsetting").(bool),
21202127
DnsConfig: expandDnsConfig(d.Get("dns_config")),
21212128
GatewayApiConfig: expandGatewayApiConfig(d.Get("gateway_api_config")),
2129+
EnableMultiNetworking: d.Get("enable_multi_networking").(bool),
21222130
},
21232131
MasterAuth: expandMasterAuth(d.Get("master_auth")),
21242132
NotificationConfig: expandNotificationConfig(d.Get("notification_config")),
@@ -2640,6 +2648,9 @@ func resourceContainerClusterRead(d *schema.ResourceData, meta interface{}) erro
26402648
if err := d.Set("enable_intranode_visibility", cluster.NetworkConfig.EnableIntraNodeVisibility); err != nil {
26412649
return fmt.Errorf("Error setting enable_intranode_visibility: %s", err)
26422650
}
2651+
if err := d.Set("enable_multi_networking", cluster.NetworkConfig.EnableMultiNetworking); err != nil {
2652+
return fmt.Errorf("Error setting enable_multi_networking: %s", err)
2653+
}
26432654
if err := d.Set("private_ipv6_google_access", cluster.NetworkConfig.PrivateIpv6GoogleAccess); err != nil {
26442655
return fmt.Errorf("Error setting private_ipv6_google_access: %s", err)
26452656
}

google/services/container/resource_container_cluster_test.go

+81
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,29 @@ func TestAccContainerCluster_withILBSubsetting(t *testing.T) {
433433
})
434434
}
435435

436+
func TestAccContainerCluster_withMultiNetworking(t *testing.T) {
437+
t.Parallel()
438+
439+
clusterName := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10))
440+
441+
acctest.VcrTest(t, resource.TestCase{
442+
PreCheck: func() { acctest.AccTestPreCheck(t) },
443+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
444+
CheckDestroy: testAccCheckContainerClusterDestroyProducer(t),
445+
Steps: []resource.TestStep{
446+
{
447+
Config: testAccContainerCluster_enableMultiNetworking(clusterName),
448+
},
449+
{
450+
ResourceName: "google_container_cluster.cluster",
451+
ImportState: true,
452+
ImportStateVerify: true,
453+
ImportStateVerifyIgnore: []string{"deletion_protection"},
454+
},
455+
},
456+
})
457+
}
458+
436459
func TestAccContainerCluster_withMasterAuthConfig_NoCert(t *testing.T) {
437460
t.Parallel()
438461

@@ -558,6 +581,64 @@ func TestUnitContainerCluster_Rfc3339TimeDiffSuppress(t *testing.T) {
558581
}
559582
}
560583

584+
func testAccContainerCluster_enableMultiNetworking(clusterName string) string {
585+
return fmt.Sprintf(`
586+
resource "google_compute_network" "container_network" {
587+
name = "%s-nw"
588+
auto_create_subnetworks = false
589+
}
590+
591+
resource "google_compute_subnetwork" "container_subnetwork" {
592+
name = google_compute_network.container_network.name
593+
network = google_compute_network.container_network.name
594+
ip_cidr_range = "10.0.36.0/24"
595+
region = "us-central1"
596+
private_ip_google_access = true
597+
598+
secondary_ip_range {
599+
range_name = "pod"
600+
ip_cidr_range = "10.0.0.0/19"
601+
}
602+
603+
secondary_ip_range {
604+
range_name = "svc"
605+
ip_cidr_range = "10.0.32.0/22"
606+
}
607+
608+
secondary_ip_range {
609+
range_name = "another-pod"
610+
ip_cidr_range = "10.1.32.0/22"
611+
}
612+
613+
lifecycle {
614+
ignore_changes = [
615+
# The auto nodepool creates a secondary range which diffs this resource.
616+
secondary_ip_range,
617+
]
618+
}
619+
}
620+
621+
resource "google_container_cluster" "cluster" {
622+
name = "%s"
623+
location = "us-central1"
624+
initial_node_count = 1
625+
626+
network = google_compute_network.container_network.name
627+
subnetwork = google_compute_subnetwork.container_subnetwork.name
628+
ip_allocation_policy {
629+
cluster_secondary_range_name = google_compute_subnetwork.container_subnetwork.secondary_ip_range[0].range_name
630+
services_secondary_range_name = google_compute_subnetwork.container_subnetwork.secondary_ip_range[1].range_name
631+
}
632+
release_channel {
633+
channel = "RAPID"
634+
}
635+
enable_multi_networking = true
636+
datapath_provider = "ADVANCED_DATAPATH"
637+
deletion_protection = false
638+
}
639+
`, clusterName, clusterName)
640+
}
641+
561642
func TestAccContainerCluster_withNetworkPolicyEnabled(t *testing.T) {
562643
t.Parallel()
563644

google/services/container/resource_container_node_pool.go

+121-6
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,57 @@ var schemaNodePool = map[string]*schema.Schema{
391391
ValidateFunc: verify.ValidateIpCidrRange,
392392
Description: `The IP address range for pod IPs in this node pool. Only applicable if create_pod_range is true. Set to blank to have a range chosen with the default size. Set to /netmask (e.g. /14) to have a range chosen with a specific netmask. Set to a CIDR notation (e.g. 10.96.0.0/14) to pick a specific range to use.`,
393393
},
394+
"additional_node_network_configs": {
395+
Type: schema.TypeList,
396+
Optional: true,
397+
ForceNew: true,
398+
Description: `We specify the additional node networks for this node pool using this list. Each node network corresponds to an additional interface`,
399+
Elem: &schema.Resource{
400+
Schema: map[string]*schema.Schema{
401+
"network": {
402+
Type: schema.TypeString,
403+
Optional: true,
404+
ForceNew: true,
405+
Description: `Name of the VPC where the additional interface belongs.`,
406+
},
407+
"subnetwork": {
408+
Type: schema.TypeString,
409+
Optional: true,
410+
ForceNew: true,
411+
Description: `Name of the subnetwork where the additional interface belongs.`,
412+
},
413+
},
414+
},
415+
},
416+
"additional_pod_network_configs": {
417+
Type: schema.TypeList,
418+
Optional: true,
419+
ForceNew: true,
420+
Description: `We specify the additional pod networks for this node pool using this list. Each pod network corresponds to an additional alias IP range for the node`,
421+
Elem: &schema.Resource{
422+
Schema: map[string]*schema.Schema{
423+
"subnetwork": {
424+
Type: schema.TypeString,
425+
Optional: true,
426+
ForceNew: true,
427+
Description: `Name of the subnetwork where the additional pod network belongs.`,
428+
},
429+
"secondary_pod_range": {
430+
Type: schema.TypeString,
431+
Optional: true,
432+
ForceNew: true,
433+
Description: `The name of the secondary range on the subnet which provides IP address for this pod range.`,
434+
},
435+
"max_pods_per_node": {
436+
Type: schema.TypeInt,
437+
Optional: true,
438+
ForceNew: true,
439+
Computed: true,
440+
Description: `The maximum number of pods per node which use this pod network.`,
441+
},
442+
},
443+
},
444+
},
394445
"pod_cidr_overprovision_config": {
395446
Type: schema.TypeList,
396447
Optional: true,
@@ -1164,12 +1215,14 @@ func flattenNodeNetworkConfig(c *container.NodeNetworkConfig, d *schema.Resource
11641215
result := []map[string]interface{}{}
11651216
if c != nil {
11661217
result = append(result, map[string]interface{}{
1167-
"create_pod_range": d.Get(prefix + "network_config.0.create_pod_range"), // API doesn't return this value so we set the old one. Field is ForceNew + Required
1168-
"pod_ipv4_cidr_block": c.PodIpv4CidrBlock,
1169-
"pod_range": c.PodRange,
1170-
"enable_private_nodes": c.EnablePrivateNodes,
1171-
"pod_cidr_overprovision_config": flattenPodCidrOverprovisionConfig(c.PodCidrOverprovisionConfig),
1172-
"network_performance_config": flattenNodeNetworkPerformanceConfig(c.NetworkPerformanceConfig),
1218+
"create_pod_range": d.Get(prefix + "network_config.0.create_pod_range"), // API doesn't return this value so we set the old one. Field is ForceNew + Required
1219+
"pod_ipv4_cidr_block": c.PodIpv4CidrBlock,
1220+
"pod_range": c.PodRange,
1221+
"enable_private_nodes": c.EnablePrivateNodes,
1222+
"pod_cidr_overprovision_config": flattenPodCidrOverprovisionConfig(c.PodCidrOverprovisionConfig),
1223+
"network_performance_config": flattenNodeNetworkPerformanceConfig(c.NetworkPerformanceConfig),
1224+
"additional_node_network_configs": flattenAdditionalNodeNetworkConfig(c.AdditionalNodeNetworkConfigs),
1225+
"additional_pod_network_configs": flattenAdditionalPodNetworkConfig(c.AdditionalPodNetworkConfigs),
11731226
})
11741227
}
11751228
return result
@@ -1185,6 +1238,37 @@ func flattenNodeNetworkPerformanceConfig(c *container.NetworkPerformanceConfig)
11851238
return result
11861239
}
11871240

1241+
func flattenAdditionalNodeNetworkConfig(c []*container.AdditionalNodeNetworkConfig) []map[string]interface{} {
1242+
if c == nil {
1243+
return nil
1244+
}
1245+
1246+
result := []map[string]interface{}{}
1247+
for _, nodeNetworkConfig := range c {
1248+
result = append(result, map[string]interface{}{
1249+
"network": nodeNetworkConfig.Network,
1250+
"subnetwork": nodeNetworkConfig.Subnetwork,
1251+
})
1252+
}
1253+
return result
1254+
}
1255+
1256+
func flattenAdditionalPodNetworkConfig(c []*container.AdditionalPodNetworkConfig) []map[string]interface{} {
1257+
if c == nil {
1258+
return nil
1259+
}
1260+
1261+
result := []map[string]interface{}{}
1262+
for _, podNetworkConfig := range c {
1263+
result = append(result, map[string]interface{}{
1264+
"subnetwork": podNetworkConfig.Subnetwork,
1265+
"secondary_pod_range": podNetworkConfig.SecondaryPodRange,
1266+
"max_pods_per_node": podNetworkConfig.MaxPodsPerNode.MaxPodsPerNode,
1267+
})
1268+
}
1269+
return result
1270+
}
1271+
11881272
func expandNodeNetworkConfig(v interface{}) *container.NodeNetworkConfig {
11891273
networkNodeConfigs := v.([]interface{})
11901274

@@ -1213,6 +1297,37 @@ func expandNodeNetworkConfig(v interface{}) *container.NodeNetworkConfig {
12131297
nnc.ForceSendFields = []string{"EnablePrivateNodes"}
12141298
}
12151299

1300+
if v, ok := networkNodeConfig["additional_node_network_configs"]; ok && len(v.([]interface{})) > 0 {
1301+
node_network_configs := v.([]interface{})
1302+
nodeNetworkConfigs := make([]*container.AdditionalNodeNetworkConfig, 0, len(node_network_configs))
1303+
for _, raw := range node_network_configs {
1304+
data := raw.(map[string]interface{})
1305+
networkConfig := &container.AdditionalNodeNetworkConfig{
1306+
Network: data["network"].(string),
1307+
Subnetwork: data["subnetwork"].(string),
1308+
}
1309+
nodeNetworkConfigs = append(nodeNetworkConfigs, networkConfig)
1310+
}
1311+
nnc.AdditionalNodeNetworkConfigs = nodeNetworkConfigs
1312+
}
1313+
1314+
if v, ok := networkNodeConfig["additional_pod_network_configs"]; ok && len(v.([]interface{})) > 0 {
1315+
pod_network_configs := v.([]interface{})
1316+
podNetworkConfigs := make([]*container.AdditionalPodNetworkConfig, 0, len(pod_network_configs))
1317+
for _, raw := range pod_network_configs {
1318+
data := raw.(map[string]interface{})
1319+
podnetworkConfig := &container.AdditionalPodNetworkConfig{
1320+
Subnetwork: data["subnetwork"].(string),
1321+
SecondaryPodRange: data["secondary_pod_range"].(string),
1322+
MaxPodsPerNode: &container.MaxPodsConstraint{
1323+
MaxPodsPerNode: int64(data["max_pods_per_node"].(int)),
1324+
},
1325+
}
1326+
podNetworkConfigs = append(podNetworkConfigs, podnetworkConfig)
1327+
}
1328+
nnc.AdditionalPodNetworkConfigs = podNetworkConfigs
1329+
}
1330+
12161331
nnc.PodCidrOverprovisionConfig = expandPodCidrOverprovisionConfig(networkNodeConfig["pod_cidr_overprovision_config"])
12171332

12181333
if v, ok := networkNodeConfig["network_performance_config"]; ok && len(v.([]interface{})) > 0 {

0 commit comments

Comments
 (0)