Skip to content

Commit 49ad1dd

Browse files
committed
* Fix #93
Fixed autogen cluster config Updated docs Updated simple-regional-beta example
1 parent 08ba330 commit 49ad1dd

File tree

13 files changed

+236
-14
lines changed

13 files changed

+236
-14
lines changed

autogen/cluster.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,12 @@ resource "google_container_cluster" "primary" {
6868
resource_limits {
6969
resource_type = "cpu"
7070
minimum = lookup(var.cluster_autoscaling.resource_limits, "min_cpu_cores", 0)
71-
maximum = lookup(var.cluster_autoscaling.resource_limits, "man_cpu_cores", 0)
71+
maximum = lookup(var.cluster_autoscaling.resource_limits, "max_cpu_cores", 0)
7272
}
7373
resource_limits {
7474
resource_type = "memory"
75-
minimum = lookup(var.cluster_autoscaling.resource_limits, "min_cpu_cores", 0)
76-
maximum = lookup(var.cluster_autoscaling.resource_limits, "man_cpu_cores", 0)
75+
minimum = lookup(var.cluster_autoscaling.resource_limits, "min_memory_gb", 0)
76+
maximum = lookup(var.cluster_autoscaling.resource_limits, "max_memory_gb", 0)
7777
}
7878
}
7979

cluster.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ resource "google_container_cluster" "primary" {
4242
}
4343

4444

45+
4546
subnetwork = data.google_compute_subnetwork.gke_subnetwork.self_link
4647
min_master_version = local.master_version
4748

examples/simple_regional_beta/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ This example illustrates how to create a simple cluster with beta features.
88
| Name | Description | Type | Default | Required |
99
|------|-------------|:----:|:-----:|:-----:|
1010
| cloudrun | Boolean to enable / disable CloudRun | string | `"true"` | no |
11+
| cluster\_autoscaling | Cluster autoscaling configuration. See [more details](https://cloud.google.com/kubernetes-engine/docs/reference/rest/v1beta1/projects.locations.clusters#clusterautoscaling) | object | `<map>` | no |
1112
| cluster\_name\_suffix | A suffix to append to the default cluster name | string | `""` | no |
1213
| compute\_engine\_service\_account | Service account to associate to the nodes in the cluster | string | n/a | yes |
1314
| ip\_range\_pods | The secondary ip range to use for pods | string | n/a | yes |

examples/simple_regional_beta/main.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ provider "google-beta" {
2626
module "gke" {
2727
source = "../../modules/beta-public-cluster/"
2828
project_id = var.project_id
29-
name = "${local.cluster_type}-cluster${var.cluster_name_suffix}"
29+
name = join("", [local.cluster_type, "-cluster", var.cluster_name_suffix])
3030
regional = true
3131
region = var.region
3232
network = var.network
@@ -41,6 +41,7 @@ module "gke" {
4141
sandbox_enabled = var.sandbox_enabled
4242
remove_default_node_pool = var.remove_default_node_pool
4343
node_pools = var.node_pools
44+
cluster_autoscaling = var.cluster_autoscaling
4445
}
4546

4647
data "google_client_config" "default" {

examples/simple_regional_beta/variables.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,15 @@ variable "node_pools" {
8585
},
8686
]
8787
}
88+
89+
variable "cluster_autoscaling" {
90+
type = object({
91+
enabled = bool
92+
resource_limits = map(number)
93+
})
94+
default = {
95+
enabled = false
96+
resource_limits = {}
97+
}
98+
description = "Cluster autoscaling configuration. See [more details](https://cloud.google.com/kubernetes-engine/docs/reference/rest/v1beta1/projects.locations.clusters#clusterautoscaling)"
99+
}

modules/beta-private-cluster-update-variant/cluster.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,12 @@ resource "google_container_cluster" "primary" {
6161
resource_limits {
6262
resource_type = "cpu"
6363
minimum = lookup(var.cluster_autoscaling.resource_limits, "min_cpu_cores", 0)
64-
maximum = lookup(var.cluster_autoscaling.resource_limits, "man_cpu_cores", 0)
64+
maximum = lookup(var.cluster_autoscaling.resource_limits, "max_cpu_cores", 0)
6565
}
6666
resource_limits {
6767
resource_type = "memory"
68-
minimum = lookup(var.cluster_autoscaling.resource_limits, "min_cpu_cores", 0)
69-
maximum = lookup(var.cluster_autoscaling.resource_limits, "man_cpu_cores", 0)
68+
minimum = lookup(var.cluster_autoscaling.resource_limits, "min_memory_gb", 0)
69+
maximum = lookup(var.cluster_autoscaling.resource_limits, "max_memory_gb", 0)
7070
}
7171
}
7272

modules/beta-private-cluster/cluster.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,12 @@ resource "google_container_cluster" "primary" {
6161
resource_limits {
6262
resource_type = "cpu"
6363
minimum = lookup(var.cluster_autoscaling.resource_limits, "min_cpu_cores", 0)
64-
maximum = lookup(var.cluster_autoscaling.resource_limits, "man_cpu_cores", 0)
64+
maximum = lookup(var.cluster_autoscaling.resource_limits, "max_cpu_cores", 0)
6565
}
6666
resource_limits {
6767
resource_type = "memory"
68-
minimum = lookup(var.cluster_autoscaling.resource_limits, "min_cpu_cores", 0)
69-
maximum = lookup(var.cluster_autoscaling.resource_limits, "man_cpu_cores", 0)
68+
minimum = lookup(var.cluster_autoscaling.resource_limits, "min_memory_gb", 0)
69+
maximum = lookup(var.cluster_autoscaling.resource_limits, "max_memory_gb", 0)
7070
}
7171
}
7272

modules/beta-public-cluster/cluster.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,12 @@ resource "google_container_cluster" "primary" {
6161
resource_limits {
6262
resource_type = "cpu"
6363
minimum = lookup(var.cluster_autoscaling.resource_limits, "min_cpu_cores", 0)
64-
maximum = lookup(var.cluster_autoscaling.resource_limits, "man_cpu_cores", 0)
64+
maximum = lookup(var.cluster_autoscaling.resource_limits, "max_cpu_cores", 0)
6565
}
6666
resource_limits {
6767
resource_type = "memory"
68-
minimum = lookup(var.cluster_autoscaling.resource_limits, "min_cpu_cores", 0)
69-
maximum = lookup(var.cluster_autoscaling.resource_limits, "man_cpu_cores", 0)
68+
minimum = lookup(var.cluster_autoscaling.resource_limits, "min_memory_gb", 0)
69+
maximum = lookup(var.cluster_autoscaling.resource_limits, "max_memory_gb", 0)
7070
}
7171
}
7272

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* Copyright 2018 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
module "example" {
18+
source = "../../../examples/simple_regional_beta"
19+
20+
project_id = var.project_id
21+
cluster_name_suffix = "-${random_string.suffix.result}"
22+
region = var.region
23+
network = google_compute_network.main.name
24+
subnetwork = google_compute_subnetwork.main.name
25+
ip_range_pods = google_compute_subnetwork.main.secondary_ip_range[0].range_name
26+
ip_range_services = google_compute_subnetwork.main.secondary_ip_range[1].range_name
27+
compute_engine_service_account = var.compute_engine_service_account
28+
29+
cluster_autoscaling = {
30+
enabled = true
31+
resource_limits = {
32+
max_cpu_cores = 20
33+
min_cpu_cores = 5
34+
max_memory_gb = 30
35+
min_memory_gb = 10
36+
}
37+
}
38+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/**
2+
* Copyright 2018 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
resource "random_string" "suffix" {
18+
length = 4
19+
special = false
20+
upper = false
21+
}
22+
23+
provider "google" {
24+
project = var.project_id
25+
}
26+
27+
resource "google_compute_network" "main" {
28+
name = "cft-gke-test-${random_string.suffix.result}"
29+
auto_create_subnetworks = false
30+
}
31+
32+
resource "google_compute_subnetwork" "main" {
33+
name = "cft-gke-test-${random_string.suffix.result}"
34+
ip_cidr_range = "10.0.0.0/17"
35+
region = var.region
36+
network = google_compute_network.main.self_link
37+
38+
secondary_ip_range {
39+
range_name = "cft-gke-test-pods-${random_string.suffix.result}"
40+
ip_cidr_range = "192.168.0.0/18"
41+
}
42+
43+
secondary_ip_range {
44+
range_name = "cft-gke-test-services-${random_string.suffix.result}"
45+
ip_cidr_range = "192.168.64.0/18"
46+
}
47+
}
48+
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/**
2+
* Copyright 2018 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
output "project_id" {
18+
value = var.project_id
19+
}
20+
21+
output "region" {
22+
value = module.example.region
23+
}
24+
25+
output "cluster_name" {
26+
description = "Cluster name"
27+
value = module.example.cluster_name
28+
}
29+
30+
output "network" {
31+
value = google_compute_network.main.name
32+
}
33+
34+
output "subnetwork" {
35+
value = google_compute_subnetwork.main.name
36+
}
37+
38+
output "location" {
39+
value = module.example.location
40+
}
41+
42+
output "ip_range_pods" {
43+
description = "The secondary IP range used for pods"
44+
value = google_compute_subnetwork.main.secondary_ip_range[0].range_name
45+
}
46+
47+
output "ip_range_services" {
48+
description = "The secondary IP range used for services"
49+
value = google_compute_subnetwork.main.secondary_ip_range[1].range_name
50+
}
51+
52+
output "zones" {
53+
description = "List of zones in which the cluster resides"
54+
value = module.example.zones
55+
}
56+
57+
output "master_kubernetes_version" {
58+
description = "The master Kubernetes version"
59+
value = module.example.master_kubernetes_version
60+
}
61+
62+
output "kubernetes_endpoint" {
63+
sensitive = true
64+
value = module.example.kubernetes_endpoint
65+
}
66+
67+
output "client_token" {
68+
sensitive = true
69+
value = module.example.client_token
70+
}
71+
72+
output "ca_certificate" {
73+
description = "The cluster CA certificate"
74+
value = module.example.ca_certificate
75+
}
76+
77+
output "service_account" {
78+
description = "The service account to default running nodes as if not overridden in `node_pools`."
79+
value = module.example.service_account
80+
}
81+
82+
output "registry_project_id" {
83+
value = var.registry_project_id
84+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* Copyright 2018 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
variable "project_id" {
18+
description = "The GCP project to use for integration tests"
19+
}
20+
21+
variable "region" {
22+
description = "The GCP region to create and test resources in"
23+
default = "us-central1"
24+
}
25+
26+
variable "zones" {
27+
type = list(string)
28+
description = "The GCP zones to create and test resources in, for applicable tests"
29+
default = ["us-central1-a", "us-central1-b", "us-central1-c"]
30+
}
31+
32+
variable "compute_engine_service_account" {
33+
description = "The email address of the service account to associate with the GKE cluster"
34+
}
35+
36+
variable "registry_project_id" {
37+
description = "Project to use for granting access to the GCR registry, if requested"
38+
}

variables.tf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,6 @@ variable "node_pools_metadata" {
178178
default-node-pool = {}
179179
}
180180
}
181-
182181
variable "node_pools_tags" {
183182
type = map(list(string))
184183
description = "Map of lists containing node network tags by node-pool name"

0 commit comments

Comments
 (0)