Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't set initial_node_count when autoscaling disabled on node pool #313

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions autogen/cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -316,16 +316,18 @@ resource "google_container_node_pool" "pools" {
"version",
local.node_version,
)
initial_node_count = lookup(

initial_node_count = lookup(var.node_pools[count.index], "autoscaling", true) ? lookup(
var.node_pools[count.index],
"initial_node_count",
lookup(var.node_pools[count.index], "min_count", 1),
)
lookup(var.node_pools[count.index], "min_count", 1)
) : null

{% if beta_cluster %}
max_pods_per_node = lookup(var.node_pools[count.index], "max_pods_per_node", null)
{% endif %}

node_count = lookup(var.node_pools[count.index], "autoscaling", true) ? null : lookup(var.node_pools[count.index], "min_count", 1)
node_count = lookup(var.node_pools[count.index], "autoscaling", true) ? null : lookup(var.node_pools[count.index], "node_count", 1)

dynamic "autoscaling" {
for_each = lookup(var.node_pools[count.index], "autoscaling", true) ? [var.node_pools[count.index]] : []
Expand Down
10 changes: 6 additions & 4 deletions cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,15 @@ resource "google_container_node_pool" "pools" {
"version",
local.node_version,
)
initial_node_count = lookup(

initial_node_count = lookup(var.node_pools[count.index], "autoscaling", true) ? lookup(
var.node_pools[count.index],
"initial_node_count",
lookup(var.node_pools[count.index], "min_count", 1),
)
lookup(var.node_pools[count.index], "min_count", 1)
) : null


node_count = lookup(var.node_pools[count.index], "autoscaling", true) ? null : lookup(var.node_pools[count.index], "min_count", 1)
node_count = lookup(var.node_pools[count.index], "autoscaling", true) ? null : lookup(var.node_pools[count.index], "node_count", 1)

dynamic "autoscaling" {
for_each = lookup(var.node_pools[count.index], "autoscaling", true) ? [var.node_pools[count.index]] : []
Expand Down
12 changes: 12 additions & 0 deletions examples/node_pool/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,20 @@ module "gke" {
auto_repair = false
service_account = var.compute_engine_service_account
},
{
name = "pool-03"
autoscaling = false
node_count = 2
service_account = var.compute_engine_service_account
auto_upgrade = true
},
]

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

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

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

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

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

Expand Down
10 changes: 6 additions & 4 deletions modules/beta-private-cluster-update-variant/cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -290,14 +290,16 @@ resource "google_container_node_pool" "pools" {
"version",
local.node_version,
)
initial_node_count = lookup(

initial_node_count = lookup(var.node_pools[count.index], "autoscaling", true) ? lookup(
var.node_pools[count.index],
"initial_node_count",
lookup(var.node_pools[count.index], "min_count", 1),
)
lookup(var.node_pools[count.index], "min_count", 1)
) : null

max_pods_per_node = lookup(var.node_pools[count.index], "max_pods_per_node", null)

node_count = lookup(var.node_pools[count.index], "autoscaling", true) ? null : lookup(var.node_pools[count.index], "min_count", 1)
node_count = lookup(var.node_pools[count.index], "autoscaling", true) ? null : lookup(var.node_pools[count.index], "node_count", 1)

dynamic "autoscaling" {
for_each = lookup(var.node_pools[count.index], "autoscaling", true) ? [var.node_pools[count.index]] : []
Expand Down
10 changes: 6 additions & 4 deletions modules/beta-private-cluster/cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -218,14 +218,16 @@ resource "google_container_node_pool" "pools" {
"version",
local.node_version,
)
initial_node_count = lookup(

initial_node_count = lookup(var.node_pools[count.index], "autoscaling", true) ? lookup(
var.node_pools[count.index],
"initial_node_count",
lookup(var.node_pools[count.index], "min_count", 1),
)
lookup(var.node_pools[count.index], "min_count", 1)
) : null

max_pods_per_node = lookup(var.node_pools[count.index], "max_pods_per_node", null)

node_count = lookup(var.node_pools[count.index], "autoscaling", true) ? null : lookup(var.node_pools[count.index], "min_count", 1)
node_count = lookup(var.node_pools[count.index], "autoscaling", true) ? null : lookup(var.node_pools[count.index], "node_count", 1)

dynamic "autoscaling" {
for_each = lookup(var.node_pools[count.index], "autoscaling", true) ? [var.node_pools[count.index]] : []
Expand Down
10 changes: 6 additions & 4 deletions modules/beta-public-cluster/cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -213,14 +213,16 @@ resource "google_container_node_pool" "pools" {
"version",
local.node_version,
)
initial_node_count = lookup(

initial_node_count = lookup(var.node_pools[count.index], "autoscaling", true) ? lookup(
var.node_pools[count.index],
"initial_node_count",
lookup(var.node_pools[count.index], "min_count", 1),
)
lookup(var.node_pools[count.index], "min_count", 1)
) : null

max_pods_per_node = lookup(var.node_pools[count.index], "max_pods_per_node", null)

node_count = lookup(var.node_pools[count.index], "autoscaling", true) ? null : lookup(var.node_pools[count.index], "min_count", 1)
node_count = lookup(var.node_pools[count.index], "autoscaling", true) ? null : lookup(var.node_pools[count.index], "node_count", 1)

dynamic "autoscaling" {
for_each = lookup(var.node_pools[count.index], "autoscaling", true) ? [var.node_pools[count.index]] : []
Expand Down
10 changes: 6 additions & 4 deletions modules/private-cluster-update-variant/cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,15 @@ resource "google_container_node_pool" "pools" {
"version",
local.node_version,
)
initial_node_count = lookup(

initial_node_count = lookup(var.node_pools[count.index], "autoscaling", true) ? lookup(
var.node_pools[count.index],
"initial_node_count",
lookup(var.node_pools[count.index], "min_count", 1),
)
lookup(var.node_pools[count.index], "min_count", 1)
) : null


node_count = lookup(var.node_pools[count.index], "autoscaling", true) ? null : lookup(var.node_pools[count.index], "min_count", 1)
node_count = lookup(var.node_pools[count.index], "autoscaling", true) ? null : lookup(var.node_pools[count.index], "node_count", 1)

dynamic "autoscaling" {
for_each = lookup(var.node_pools[count.index], "autoscaling", true) ? [var.node_pools[count.index]] : []
Expand Down
10 changes: 6 additions & 4 deletions modules/private-cluster/cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,15 @@ resource "google_container_node_pool" "pools" {
"version",
local.node_version,
)
initial_node_count = lookup(

initial_node_count = lookup(var.node_pools[count.index], "autoscaling", true) ? lookup(
var.node_pools[count.index],
"initial_node_count",
lookup(var.node_pools[count.index], "min_count", 1),
)
lookup(var.node_pools[count.index], "min_count", 1)
) : null


node_count = lookup(var.node_pools[count.index], "autoscaling", true) ? null : lookup(var.node_pools[count.index], "min_count", 1)
node_count = lookup(var.node_pools[count.index], "autoscaling", true) ? null : lookup(var.node_pools[count.index], "node_count", 1)

dynamic "autoscaling" {
for_each = lookup(var.node_pools[count.index], "autoscaling", true) ? [var.node_pools[count.index]] : []
Expand Down
97 changes: 95 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,99 @@
)
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 disabled" do
expect(data['nodePools']).not_to include(
including(
"name" => "pool-03",
"autoscaling" => including(
"enabled" => true,
),
)
)
end

it "has the expected node count" do
expect(data['nodePools']).to include(
including(
"name" => "pool-03",
"initialNodeCount" => 2
)
)
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

it "has the expected labels" do
expect(data['nodePools']).to include(
including(
"name" => "pool-03",
"config" => including(
"labels" => {
"all-pools-example" => "true",
"cluster_name" => cluster_name,
"node_pool" => "pool-03",
},
),
)
)
end

it "has the expected network tags" do
expect(data['nodePools']).to include(
including(
"name" => "pool-03",
"config" => including(
"tags" => match_array([
"all-node-example",
"gke-#{cluster_name}",
"gke-#{cluster_name}-pool-03",
]),
),
)
)
end
end
end
end
end
15 changes: 15 additions & 0 deletions test/integration/node_pool/controls/kubectl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,21 @@
all_nodes.select { |n| n.metadata.labels.node_pool == "pool-02" }
end

it "has the expected taints" do
expect(taints).to include(
{
effect: "PreferNoSchedule",
key: "all-pools-example",
value: "true",
}
)
end
end
describe "pool-03" do
let(:nodes) do
all_nodes.select { |n| n.metadata.labels.node_pool == "pool-03" }
end

it "has the expected taints" do
expect(taints).to include(
{
Expand Down