Skip to content

Commit

Permalink
Merge pull request #303 from bharathkkb/feature/add-node-pool-location
Browse files Browse the repository at this point in the history
Add node_locations for node pools
  • Loading branch information
morgante committed Nov 11, 2019
2 parents 03f0931 + a4bfc30 commit 297f38d
Show file tree
Hide file tree
Showing 10 changed files with 125 additions and 6 deletions.
3 changes: 3 additions & 0 deletions autogen/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ module "gke" {
{
name = "default-node-pool"
machine_type = "n1-standard-2"
{% if beta_cluster %}
node_locations = "us-central1-b,us-central1-c"
{% endif %}
min_count = 1
max_count = 100
disk_size_gb = 100
Expand Down
4 changes: 4 additions & 0 deletions autogen/cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,10 @@ resource "google_container_node_pool" "pools" {
{% endif %}
project = var.project_id
location = local.location
{% if beta_cluster %}
// use node_locations if provided, defaults to cluster level node_locations if not specified
node_locations = lookup(var.node_pools[count.index], "node_locations", "") != "" ? split(",", var.node_pools[count.index]["node_locations"]) : google_container_cluster.primary.node_locations
{% endif %}
cluster = google_container_cluster.primary.name
version = lookup(var.node_pools[count.index], "auto_upgrade", false) ? "" : lookup(
var.node_pools[count.index],
Expand Down
17 changes: 16 additions & 1 deletion examples/node_pool/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ module "gke" {
source = "../../modules/beta-public-cluster/"
project_id = var.project_id
name = "${local.cluster_type}-cluster${var.cluster_name_suffix}"
regional = false
region = var.region
zones = var.zones
network = var.network
Expand Down Expand Up @@ -59,12 +58,24 @@ module "gke" {
auto_repair = false
service_account = var.compute_engine_service_account
},
{
name = "pool-03"
node_locations = "us-east4-b,us-east4-c"
machine_type = "n1-standard-2"
min_count = 1
max_count = 2
disk_type = "pd-standard"
image_type = "COS"
auto_upgrade = true
service_account = var.compute_engine_service_account
},
]

node_pools_oauth_scopes = {
all = []
pool-01 = []
pool-02 = []
pool-03 = []
}

node_pools_metadata = {
Expand All @@ -73,6 +84,7 @@ module "gke" {
shutdown-script = file("${path.module}/data/shutdown-script.sh")
}
pool-02 = {}
pool-03 = {}
}

node_pools_labels = {
Expand All @@ -83,6 +95,7 @@ module "gke" {
pool-01-example = true
}
pool-02 = {}
pool-03 = {}
}

node_pools_taints = {
Expand All @@ -101,6 +114,7 @@ module "gke" {
},
]
pool-02 = []
pool-03 = []
}

node_pools_tags = {
Expand All @@ -111,6 +125,7 @@ module "gke" {
"pool-01-example",
]
pool-02 = []
pool-03 = []
}
}

Expand Down
1 change: 1 addition & 0 deletions modules/beta-private-cluster-update-variant/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ module "gke" {
{
name = "default-node-pool"
machine_type = "n1-standard-2"
node_locations = "us-central1-b,us-central1-c"
min_count = 1
max_count = 100
disk_size_gb = 100
Expand Down
4 changes: 3 additions & 1 deletion modules/beta-private-cluster-update-variant/cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,9 @@ resource "google_container_node_pool" "pools" {
name = random_id.name.*.hex[count.index]
project = var.project_id
location = local.location
cluster = google_container_cluster.primary.name
// use node_locations if provided, defaults to cluster level node_locations if not specified
node_locations = lookup(var.node_pools[count.index], "node_locations", "") != "" ? split(",", var.node_pools[count.index]["node_locations"]) : google_container_cluster.primary.node_locations
cluster = google_container_cluster.primary.name
version = lookup(var.node_pools[count.index], "auto_upgrade", false) ? "" : lookup(
var.node_pools[count.index],
"version",
Expand Down
1 change: 1 addition & 0 deletions modules/beta-private-cluster/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ module "gke" {
{
name = "default-node-pool"
machine_type = "n1-standard-2"
node_locations = "us-central1-b,us-central1-c"
min_count = 1
max_count = 100
disk_size_gb = 100
Expand Down
4 changes: 3 additions & 1 deletion modules/beta-private-cluster/cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,9 @@ resource "google_container_node_pool" "pools" {
name = var.node_pools[count.index]["name"]
project = var.project_id
location = local.location
cluster = google_container_cluster.primary.name
// use node_locations if provided, defaults to cluster level node_locations if not specified
node_locations = lookup(var.node_pools[count.index], "node_locations", "") != "" ? split(",", var.node_pools[count.index]["node_locations"]) : google_container_cluster.primary.node_locations
cluster = google_container_cluster.primary.name
version = lookup(var.node_pools[count.index], "auto_upgrade", false) ? "" : lookup(
var.node_pools[count.index],
"version",
Expand Down
1 change: 1 addition & 0 deletions modules/beta-public-cluster/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ module "gke" {
{
name = "default-node-pool"
machine_type = "n1-standard-2"
node_locations = "us-central1-b,us-central1-c"
min_count = 1
max_count = 100
disk_size_gb = 100
Expand Down
4 changes: 3 additions & 1 deletion modules/beta-public-cluster/cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,9 @@ resource "google_container_node_pool" "pools" {
name = var.node_pools[count.index]["name"]
project = var.project_id
location = local.location
cluster = google_container_cluster.primary.name
// use node_locations if provided, defaults to cluster level node_locations if not specified
node_locations = lookup(var.node_pools[count.index], "node_locations", "") != "" ? split(",", var.node_pools[count.index]["node_locations"]) : google_container_cluster.primary.node_locations
cluster = google_container_cluster.primary.name
version = lookup(var.node_pools[count.index], "auto_upgrade", false) ? "" : lookup(
var.node_pools[count.index],
"version",
Expand Down
92 changes: 90 additions & 2 deletions test/integration/node_pool/controls/gcloud.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
describe "node pools" do
let(:node_pools) { data['nodePools'].reject { |p| p['name'] == "default-pool" } }

it "has 2" do
expect(node_pools.count).to eq 2
it "has 3" do
expect(node_pools.count).to eq 3
end

describe "pool-01" do
Expand Down Expand Up @@ -279,6 +279,94 @@
)
end
end
describe "pool-03" do
it "exists" do
expect(data['nodePools']).to include(
including(
"name" => "pool-03",
)
)
end
it "is the expected machine type" do
expect(data['nodePools']).to include(
including(
"name" => "pool-03",
"config" => including(
"machineType" => "n1-standard-2",
),
)
)
end

it "has autoscaling enabled" do
expect(data['nodePools']).to include(
including(
"name" => "pool-03",
"autoscaling" => including(
"enabled" => true,
),
)
)
end

it "has the expected minimum node count" do
expect(data['nodePools']).to include(
including(
"name" => "pool-03",
"autoscaling" => including(
"minNodeCount" => 1,
),
)
)
end

it "has autorepair enabled" do
expect(data['nodePools']).to include(
including(
"name" => "pool-03",
"management" => including(
"autoRepair" => true,
),
)
)
end

it "has automatic upgrades enabled" do
expect(data['nodePools']).to include(
including(
"name" => "pool-03",
"management" => including(
"autoUpgrade" => true,
),
)
)
end

end
end
end
describe command("gcloud beta --project=#{project_id} container clusters --zone=#{location} describe #{cluster_name} --format=json") do
its(:exit_status) { should eq 0 }
its(:stderr) { should eq '' }

let!(:data) do
if subject.exit_status == 0
JSON.parse(subject.stdout)
else
{}
end
end

it "pool-03 has nodes in correct locations" do
expect(data['nodePools']).to include(
including(
"name" => "pool-03",
"locations" => match_array([
"us-east4-b",
"us-east4-c",
]),
)
)
end
end
end

0 comments on commit 297f38d

Please sign in to comment.