Skip to content

Commit 81f8bef

Browse files
Add support for max pods per node to node pool. (#2038)
1 parent 5110800 commit 81f8bef

File tree

6 files changed

+616
-35
lines changed

6 files changed

+616
-35
lines changed

google/resource_container_node_pool.go

+15
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ var schemaNodePool = map[string]*schema.Schema{
8484
},
8585
},
8686

87+
"max_pods_per_node": &schema.Schema{
88+
Type: schema.TypeInt,
89+
Optional: true,
90+
},
91+
8792
"initial_node_count": &schema.Schema{
8893
Type: schema.TypeInt,
8994
Optional: true,
@@ -468,6 +473,12 @@ func expandNodePool(d *schema.ResourceData, prefix string) (*containerBeta.NodeP
468473
}
469474
}
470475

476+
if v, ok := d.GetOk(prefix + "max_pods_per_node"); ok {
477+
np.MaxPodsConstraint = &containerBeta.MaxPodsConstraint{
478+
MaxPodsPerNode: int64(v.(int)),
479+
}
480+
}
481+
471482
if v, ok := d.GetOk(prefix + "management"); ok {
472483
managementConfig := v.([]interface{})[0].(map[string]interface{})
473484
np.Management = &containerBeta.NodeManagement{}
@@ -520,6 +531,10 @@ func flattenNodePool(d *schema.ResourceData, config *Config, np *containerBeta.N
520531
}
521532
}
522533

534+
if np.MaxPodsConstraint != nil {
535+
nodePool["max_pods_per_node"] = np.MaxPodsConstraint.MaxPodsPerNode
536+
}
537+
523538
nodePool["management"] = []map[string]interface{}{
524539
{
525540
"auto_repair": np.Management.AutoRepair,

google/resource_container_node_pool_test.go

+75
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,29 @@ func TestAccContainerNodePool_basic(t *testing.T) {
3232
})
3333
}
3434

35+
func TestAccContainerNodePool_maxPodsPerNode(t *testing.T) {
36+
t.Parallel()
37+
38+
cluster := fmt.Sprintf("tf-nodepool-test-%s", acctest.RandString(10))
39+
np := fmt.Sprintf("tf-nodepool-test-%s", acctest.RandString(10))
40+
41+
resource.Test(t, resource.TestCase{
42+
PreCheck: func() { testAccPreCheck(t) },
43+
Providers: testAccProviders,
44+
CheckDestroy: testAccCheckContainerNodePoolDestroy,
45+
Steps: []resource.TestStep{
46+
resource.TestStep{
47+
Config: testAccContainerNodePool_maxPodsPerNode(cluster, np),
48+
},
49+
resource.TestStep{
50+
ResourceName: "google_container_node_pool.np",
51+
ImportState: true,
52+
ImportStateVerify: true,
53+
},
54+
},
55+
})
56+
}
57+
3558
func TestAccContainerNodePool_namePrefix(t *testing.T) {
3659
t.Parallel()
3760

@@ -513,6 +536,58 @@ resource "google_container_node_pool" "np" {
513536
}`, cluster, np)
514537
}
515538

539+
func testAccContainerNodePool_maxPodsPerNode(cluster, np string) string {
540+
return fmt.Sprintf(`
541+
resource "google_compute_network" "container_network" {
542+
name = "container-net-%s"
543+
auto_create_subnetworks = false
544+
}
545+
546+
resource "google_compute_subnetwork" "container_subnetwork" {
547+
name = "${google_compute_network.container_network.name}"
548+
network = "${google_compute_network.container_network.name}"
549+
ip_cidr_range = "10.0.36.0/24"
550+
region = "us-central1"
551+
private_ip_google_access = true
552+
553+
secondary_ip_range {
554+
range_name = "pod"
555+
ip_cidr_range = "10.0.0.0/19"
556+
}
557+
558+
secondary_ip_range {
559+
range_name = "svc"
560+
ip_cidr_range = "10.0.32.0/22"
561+
}
562+
}
563+
564+
resource "google_container_cluster" "cluster" {
565+
name = "%s"
566+
zone = "us-central1-a"
567+
initial_node_count = 3
568+
569+
network = "${google_compute_network.container_network.name}"
570+
subnetwork = "${google_compute_subnetwork.container_subnetwork.name}"
571+
private_cluster = true
572+
master_ipv4_cidr_block = "10.42.0.0/28"
573+
ip_allocation_policy {
574+
cluster_secondary_range_name = "${google_compute_subnetwork.container_subnetwork.secondary_ip_range.0.range_name}"
575+
services_secondary_range_name = "${google_compute_subnetwork.container_subnetwork.secondary_ip_range.1.range_name}"
576+
}
577+
master_authorized_networks_config {
578+
cidr_blocks = []
579+
}
580+
}
581+
582+
resource "google_container_node_pool" "np" {
583+
name = "%s"
584+
zone = "us-central1-a"
585+
cluster = "${google_container_cluster.cluster.name}"
586+
max_pods_per_node = 30
587+
initial_node_count = 2
588+
}`, cluster, cluster, np)
589+
}
590+
516591
func testAccContainerNodePool_regionalClusters(cluster, np string) string {
517592
return fmt.Sprintf(`
518593
resource "google_container_cluster" "cluster" {

0 commit comments

Comments
 (0)