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

GKE 101: added guest_accelerator feature and tests #157

3 changes: 3 additions & 0 deletions .kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ suites:
systems:
- name: deploy_service
backend: local
lifecycle:
pre_verify:
- sleep 10
provisioner:
name: terraform
- name: "disable_client_cert"
Expand Down
5 changes: 5 additions & 0 deletions autogen/cluster_regional.tf
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ resource "google_container_node_pool" "pools" {
"${concat(var.node_pools_oauth_scopes["all"],
var.node_pools_oauth_scopes[lookup(var.node_pools[count.index], "name")])}",
]

guest_accelerator {
type = "${lookup(var.node_pools[count.index], "accelerator_type", "")}"
count = "${lookup(var.node_pools[count.index], "accelerator_count", 0)}"
}
}

lifecycle {
Expand Down
5 changes: 5 additions & 0 deletions autogen/cluster_zonal.tf
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ resource "google_container_node_pool" "zonal_pools" {
"${concat(var.node_pools_oauth_scopes["all"],
var.node_pools_oauth_scopes[lookup(var.node_pools[count.index], "name")])}",
]

guest_accelerator {
type = "${lookup(var.node_pools[count.index], "accelerator_type", "")}"
count = "${lookup(var.node_pools[count.index], "accelerator_count", 0)}"
}
}

lifecycle {
Expand Down
5 changes: 5 additions & 0 deletions cluster_regional.tf
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ resource "google_container_node_pool" "pools" {
"${concat(var.node_pools_oauth_scopes["all"],
var.node_pools_oauth_scopes[lookup(var.node_pools[count.index], "name")])}",
]

guest_accelerator {
type = "${lookup(var.node_pools[count.index], "accelerator_type", "")}"
count = "${lookup(var.node_pools[count.index], "accelerator_count", 0)}"
}
}

lifecycle {
Expand Down
5 changes: 5 additions & 0 deletions cluster_zonal.tf
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ resource "google_container_node_pool" "zonal_pools" {
"${concat(var.node_pools_oauth_scopes["all"],
var.node_pools_oauth_scopes[lookup(var.node_pools[count.index], "name")])}",
]

guest_accelerator {
type = "${lookup(var.node_pools[count.index], "accelerator_type", "")}"
count = "${lookup(var.node_pools[count.index], "accelerator_count", 0)}"
}
}

lifecycle {
Expand Down
1 change: 1 addition & 0 deletions examples/disable_client_cert/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ This example illustrates how to create a simple cluster and disable deprecated s
| network | |
| project\_id | |
| region | |
| service\_account | The service account to default running nodes as if not overridden in `node_pools`. |
| subnetwork | |
| zones | List of zones in which the cluster resides |

Expand Down
20 changes: 11 additions & 9 deletions examples/node_pool/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,17 @@ module "gke" {
auto_upgrade = true
},
{
name = "pool-02"
machine_type = "n1-standard-2"
min_count = 1
max_count = 2
disk_size_gb = 30
disk_type = "pd-standard"
image_type = "COS"
auto_repair = false
service_account = "${var.compute_engine_service_account}"
name = "pool-02"
machine_type = "n1-standard-2"
min_count = 1
max_count = 2
disk_size_gb = 30
disk_type = "pd-standard"
accelerator_count = 1
accelerator_type = "nvidia-tesla-p4"
image_type = "COS"
auto_repair = false
service_account = "${var.compute_engine_service_account}"
},
]

Expand Down
6 changes: 3 additions & 3 deletions helpers/generate_modules/generate_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@

TEMPLATE_FOLDER = "./autogen"
BASE_TEMPLATE_OPTIONS = {
'autogeneration_note': '// This file was automatically generated ' +
'from a template in {folder}'.format(
folder=TEMPLATE_FOLDER
'autogeneration_note': '// This file was automatically generated ' +
'from a template in {folder}'.format(
folder=TEMPLATE_FOLDER
),
}

Expand Down
5 changes: 5 additions & 0 deletions modules/private-cluster/cluster_regional.tf
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ resource "google_container_node_pool" "pools" {
"${concat(var.node_pools_oauth_scopes["all"],
var.node_pools_oauth_scopes[lookup(var.node_pools[count.index], "name")])}",
]

guest_accelerator {
type = "${lookup(var.node_pools[count.index], "accelerator_type", "")}"
count = "${lookup(var.node_pools[count.index], "accelerator_count", 0)}"
}
}

lifecycle {
Expand Down
5 changes: 5 additions & 0 deletions modules/private-cluster/cluster_zonal.tf
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ resource "google_container_node_pool" "zonal_pools" {
"${concat(var.node_pools_oauth_scopes["all"],
var.node_pools_oauth_scopes[lookup(var.node_pools[count.index], "name")])}",
]

guest_accelerator {
type = "${lookup(var.node_pools[count.index], "accelerator_type", "")}"
count = "${lookup(var.node_pools[count.index], "accelerator_count", 0)}"
}
}

lifecycle {
Expand Down
15 changes: 15 additions & 0 deletions test/integration/node_pool/controls/gcloud.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
location = attribute('location')
cluster_name = attribute('cluster_name')

expected_accelerators_count = "1"
expected_accelerators_type = "nvidia-tesla-p4"

control "gcloud" do
title "Google Compute Engine GKE configuration"
describe command("gcloud --project=#{project_id} container clusters --zone=#{location} describe #{cluster_name} --format=json") do
Expand Down Expand Up @@ -201,6 +204,18 @@
)
end

it "has the expected accelerators" do
expect(data['nodePools']).to include(
including(
"name" => "pool-02",
"config" => including(
"accelerators" => [{"acceleratorCount" => expected_accelerators_count,
"acceleratorType" => expected_accelerators_type}],
),
)
)
end

it "has the expected disk size" do
expect(data['nodePools']).to include(
including(
Expand Down
5 changes: 5 additions & 0 deletions test/integration/node_pool/controls/kubectl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@
key: "all-pools-example",
value: "true",
},
{
effect: "NoSchedule",
key: "nvidia.com/gpu",
value: "present",
},
])
end
end
Expand Down