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

Added support for control plane node pool #8

Merged
merged 4 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
21 changes: 12 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ Truefoundry Google Cloud Cluster Classic Module
| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.4 |
| <a name="requirement_google"></a> [google](#requirement\_google) | 5.10.0 |
| <a name="requirement_google-beta"></a> [google-beta](#requirement\_google-beta) | 5.10.0 |
| <a name="requirement_google"></a> [google](#requirement\_google) | 5.18.0 |
| <a name="requirement_google-beta"></a> [google-beta](#requirement\_google-beta) | 5.18.0 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_google"></a> [google](#provider\_google) | 5.10.0 |
| <a name="provider_google-beta"></a> [google-beta](#provider\_google-beta) | 5.10.0 |
| <a name="provider_google"></a> [google](#provider\_google) | 5.18.0 |
| <a name="provider_google-beta"></a> [google-beta](#provider\_google-beta) | 5.18.0 |

## Modules

Expand All @@ -25,16 +25,17 @@ No modules.

| Name | Type |
|------|------|
| [google-beta_google_container_cluster.cluster](https://registry.terraform.io/providers/hashicorp/google-beta/5.10.0/docs/resources/google_container_cluster) | resource |
| [google_compute_firewall.fix_webhooks](https://registry.terraform.io/providers/hashicorp/google/5.10.0/docs/resources/compute_firewall) | resource |
| [google_container_node_pool.generic](https://registry.terraform.io/providers/hashicorp/google/5.10.0/docs/resources/container_node_pool) | resource |
| [google-beta_google_container_cluster.cluster](https://registry.terraform.io/providers/hashicorp/google-beta/5.18.0/docs/resources/google_container_cluster) | resource |
| [google_compute_firewall.fix_webhooks](https://registry.terraform.io/providers/hashicorp/google/5.18.0/docs/resources/compute_firewall) | resource |
| [google_container_node_pool.control_plane_pool](https://registry.terraform.io/providers/hashicorp/google/5.18.0/docs/resources/container_node_pool) | resource |
| [google_container_node_pool.generic](https://registry.terraform.io/providers/hashicorp/google/5.18.0/docs/resources/container_node_pool) | resource |

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_allowed_ip_ranges"></a> [allowed\_ip\_ranges](#input\_allowed\_ip\_ranges) | Allowed IP ranges to connect to master | `list(string)` | <pre>[<br> "0.0.0.0/0"<br>]</pre> | no |
| <a name="input_cluster_generic_node_config"></a> [cluster\_generic\_node\_config](#input\_cluster\_generic\_node\_config) | Cluster Generic Node configuration | <pre>object({<br> disk_size_gb = optional(string, "100")<br> disk_type = optional(string, "pd-balanced")<br> machine_type = optional(string, "e2-medium")<br> enable_secure_boot = optional(bool, true)<br> enable_integrity_monitoring = optional(bool, true)<br> auto_repair = optional(bool, true)<br> auto_upgrade = optional(bool, true)<br> node_count = optional(number, 1)<br> workload_metadata_config_mode = optional(string, "GKE_METADATA")<br> service_account = optional(string, "default")<br> preemptible = optional(bool, false)<br> spot = optional(bool, false)<br> })</pre> | `{}` | no |
| <a name="input_cluster_generic_node_config"></a> [cluster\_generic\_node\_config](#input\_cluster\_generic\_node\_config) | Cluster Generic Node configuration | <pre>object({<br> disk_size_gb = optional(string, "100")<br> disk_type = optional(string, "pd-balanced")<br> machine_type = optional(string, "e2-medium")<br> enable_secure_boot = optional(bool, true)<br> enable_integrity_monitoring = optional(bool, true)<br> auto_repair = optional(bool, true)<br> auto_upgrade = optional(bool, true)<br> node_count = optional(number, 1)<br> workload_metadata_config_mode = optional(string, "GKE_METADATA")<br> service_account = optional(string, "default")<br> preemptible = optional(bool, false)<br> spot = optional(bool, true)<br> })</pre> | `{}` | no |
| <a name="input_cluster_ipv4_cidr_block"></a> [cluster\_ipv4\_cidr\_block](#input\_cluster\_ipv4\_cidr\_block) | The IP address range for the cluster pod IPs. Set to blank to have a range chosen with the default size. Optional with cluster\_ipv4\_cidr\_block | `string` | `""` | no |
| <a name="input_cluster_master_ipv4_cidr_block"></a> [cluster\_master\_ipv4\_cidr\_block](#input\_cluster\_master\_ipv4\_cidr\_block) | Master nodes ipv4 cidr | `string` | n/a | yes |
| <a name="input_cluster_name"></a> [cluster\_name](#input\_cluster\_name) | Name of the cluster | `string` | n/a | yes |
Expand All @@ -44,9 +45,11 @@ No modules.
| <a name="input_cluster_node_locations"></a> [cluster\_node\_locations](#input\_cluster\_node\_locations) | AZ for nodes - this should match the region | `list(string)` | n/a | yes |
| <a name="input_cluster_secondary_range_name"></a> [cluster\_secondary\_range\_name](#input\_cluster\_secondary\_range\_name) | VPC Secondary range name for pods | `string` | `"notpods"` | no |
| <a name="input_cluster_subnet_id"></a> [cluster\_subnet\_id](#input\_cluster\_subnet\_id) | Subnetwork name for the cluster. | `string` | n/a | yes |
| <a name="input_control_plane_enabled"></a> [control\_plane\_enabled](#input\_control\_plane\_enabled) | Whether control plane is enabled or not | `bool` | `false` | no |
| <a name="input_control_plane_pool_config"></a> [control\_plane\_pool\_config](#input\_control\_plane\_pool\_config) | Control plane node pool config | <pre>object({<br> disk_size_gb = optional(string, "100")<br> disk_type = optional(string, "pd-balanced")<br> machine_type = optional(string, "e2-medium")<br> autoscaling = optional(object({<br> min_node_count = optional(number, 1)<br> max_node_count = optional(number, 2)<br> location_policy = optional(string, "BALANCED")<br> }), {})<br> enable_secure_boot = optional(bool, true)<br> enable_integrity_monitoring = optional(bool, true)<br> auto_repair = optional(bool, true)<br> auto_upgrade = optional(bool, true)<br> workload_metadata_config_mode = optional(string, "GKE_METADATA")<br> service_account = optional(string, "default")<br> labels = optional(map(string), {<br> "class.truefoundry.io/component" = "control-plane"<br> })<br> taints = optional(object(<br> {<br> key = optional(string, "class.truefoundry.io/component")<br> value = optional(string, "control-plane")<br> effect = optional(string, "NO_SCHEDULE")<br> }<br> ), {})<br> preemptible = optional(bool, false)<br> spot = optional(bool, true)<br> })</pre> | `{}` | no |
| <a name="input_deletion_protection"></a> [deletion\_protection](#input\_deletion\_protection) | Deletion protection enabled/disabled | `bool` | `false` | no |
| <a name="input_enable_container_image_streaming"></a> [enable\_container\_image\_streaming](#input\_enable\_container\_image\_streaming) | Enable/disable container image streaming | `bool` | `true` | no |
| <a name="input_kubernetes_version"></a> [kubernetes\_version](#input\_kubernetes\_version) | Version of GKE | `string` | `"1.27"` | no |
| <a name="input_kubernetes_version"></a> [kubernetes\_version](#input\_kubernetes\_version) | Version of GKE | `string` | `"1.28"` | no |
| <a name="input_max_pods_per_node"></a> [max\_pods\_per\_node](#input\_max\_pods\_per\_node) | Maximum pods per node | `string` | `"32"` | no |
| <a name="input_oauth_scopes"></a> [oauth\_scopes](#input\_oauth\_scopes) | Oauth Scopes to attach to the cluste | `list(string)` | <pre>[<br> "https://www.googleapis.com/auth/cloud-platform",<br> "https://www.googleapis.com/auth/devstorage.read_only",<br> "https://www.googleapis.com/auth/logging.write",<br> "https://www.googleapis.com/auth/monitoring.write"<br>]</pre> | no |
| <a name="input_project"></a> [project](#input\_project) | GCP Project | `string` | n/a | yes |
Expand Down
54 changes: 54 additions & 0 deletions gke.tf
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ resource "google_container_cluster" "cluster" {

# Customizable node pool
# See: https://registry.terraform.io/providers/hashicorp/google/4.1.0/docs/resources/container_node_pool

##########################################################################################
## Generic node pool
##########################################################################################
resource "google_container_node_pool" "generic" {
name = "generic"
cluster = google_container_cluster.cluster.id
Expand Down Expand Up @@ -196,6 +200,56 @@ resource "google_container_node_pool" "generic" {
}
}

##########################################################################################
## Control plane node pool
##########################################################################################
resource "google_container_node_pool" "control_plane_pool" {
count = var.control_plane_enabled ? 1 : 0
name = "control-plane"
cluster = google_container_cluster.cluster.id
location = var.region
node_locations = var.cluster_node_locations
management {
auto_repair = var.control_plane_pool_config.auto_repair
auto_upgrade = var.control_plane_pool_config.auto_upgrade
}
autoscaling {
min_node_count = var.control_plane_pool_config.autoscaling.min_node_count
max_node_count = var.control_plane_pool_config.autoscaling.max_node_count
location_policy = var.control_plane_pool_config.autoscaling.location_policy
}
node_config {
disk_size_gb = var.control_plane_pool_config.disk_size_gb
disk_type = var.control_plane_pool_config.disk_type
gcfs_config {
enabled = var.enable_container_image_streaming
}
labels = var.control_plane_pool_config.labels
taint {
key = var.control_plane_pool_config.taints.key
value = var.control_plane_pool_config.taints.value
effect = var.control_plane_pool_config.taints.effect
}
resource_labels = local.control_plane_tags
machine_type = var.control_plane_pool_config.machine_type
shielded_instance_config {
enable_secure_boot = var.control_plane_pool_config.enable_secure_boot
enable_integrity_monitoring = var.control_plane_pool_config.enable_integrity_monitoring
}
workload_metadata_config {
mode = var.control_plane_pool_config.workload_metadata_config_mode
}
oauth_scopes = var.oauth_scopes
preemptible = var.control_plane_pool_config.preemptible
spot = var.control_plane_pool_config.spot
service_account = var.control_plane_pool_config.service_account

tags = ["tfy-control-plane"]

}
}


/******************************************
CRD are broken in GKE
https://github.com/kubernetes/kubernetes/issues/79739
Expand Down
11 changes: 11 additions & 0 deletions locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,18 @@ locals {
"terraform-module" = "truefoundry-cluster-classic"
"terraform" = "true"
"cluster-name" = var.cluster_name
"truefoundry" = "managed"
},
var.tags
)
generic_tags = merge({
node_usage = "generic"
},
local.tags
)
control_plane_tags = merge({
node_usage = "tfy-control-plane"
},
local.tags
)
}
47 changes: 44 additions & 3 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ variable "max_pods_per_node" {
default = "32"
type = string
}

variable "cluster_generic_node_config" {
description = "Cluster Generic Node configuration"
type = object({
Expand All @@ -33,7 +34,7 @@ variable "cluster_generic_node_config" {
workload_metadata_config_mode = optional(string, "GKE_METADATA")
service_account = optional(string, "default")
preemptible = optional(bool, false)
spot = optional(bool, false)
spot = optional(bool, true)
})
default = {

Expand Down Expand Up @@ -79,7 +80,7 @@ variable "oauth_scopes" {

variable "kubernetes_version" {
description = "Version of GKE"
default = "1.27"
default = "1.28"
type = string
}

Expand All @@ -89,6 +90,46 @@ variable "deletion_protection" {
type = bool
}

variable "control_plane_enabled" {
description = "Whether control plane is enabled or not"
default = false
type = bool
}

variable "control_plane_pool_config" {
description = "Control plane node pool config"
type = object({
disk_size_gb = optional(string, "100")
disk_type = optional(string, "pd-balanced")
machine_type = optional(string, "e2-medium")
autoscaling = optional(object({
min_node_count = optional(number, 1)
max_node_count = optional(number, 2)
location_policy = optional(string, "BALANCED")
}), {})
enable_secure_boot = optional(bool, true)
enable_integrity_monitoring = optional(bool, true)
auto_repair = optional(bool, true)
auto_upgrade = optional(bool, true)
workload_metadata_config_mode = optional(string, "GKE_METADATA")
service_account = optional(string, "default")
labels = optional(map(string), {
"class.truefoundry.io/component" = "control-plane"
})
taints = optional(object(
{
key = optional(string, "class.truefoundry.io/component")
value = optional(string, "control-plane")
effect = optional(string, "NO_SCHEDULE")
}
), {})
preemptible = optional(bool, false)
spot = optional(bool, true)
})
default = {

}
}
################################################################################
# Network
################################################################################
Expand All @@ -97,6 +138,7 @@ variable "cluster_network_name" {
description = "Network name for the cluster"
type = string
}

variable "cluster_subnet_id" {
description = "Subnetwork name for the cluster."
type = string
Expand Down Expand Up @@ -147,7 +189,6 @@ variable "allowed_ip_ranges" {
# Generic
################################################################################


variable "tags" {
description = "A map of tags to add to all resources"
type = map(string)
Expand Down
4 changes: 2 additions & 2 deletions versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ terraform {
required_providers {
google-beta = {
source = "hashicorp/google-beta"
version = "5.10.0"
version = "5.18.0"
}
google = {
source = "hashicorp/google"
version = "5.10.0"
version = "5.18.0"
}
}
}