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

feat: add variable for setting the cpu_credits parameter in launch template #35

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ Optional policies have the option of being created by default, but are specified
| controlplane\_allowed\_cidrs | Server pool security group allowed cidr ranges | `list(string)` | <pre>[<br> "0.0.0.0/0"<br>]</pre> | no |
| controlplane\_enable\_cross\_zone\_load\_balancing | Toggle between controlplane cross zone load balancing | `bool` | `true` | no |
| controlplane\_internal | Toggle between public or private control plane load balancer | `bool` | `true` | no |
| cpu\_credits | n/a | `string` | `"standard"` | no |
| download | Toggle best effort download of rke2 dependencies (rke2 and aws cli), if disabled, dependencies are assumed to exist in $PATH | `bool` | `true` | no |
| enable\_ccm | Toggle enabling the cluster as aws aware, this will ensure the appropriate IAM policies are present | `bool` | `false` | no |
| extra\_block\_device\_mappings | Additional server pool block device mappings configuration | `list(map(string))` | `[]` | no |
Expand All @@ -167,7 +168,7 @@ Optional policies have the option of being created by default, but are specified
| post\_userdata | Custom userdata to run immediately after rke2 node attempts to join cluster | `string` | `""` | no |
| pre\_userdata | Custom userdata to run immediately before rke2 node attempts to join cluster, after required rke2, dependencies are installed | `string` | `""` | no |
| rke2\_config | Server pool additional configuration passed as rke2 config file, see https://docs.rke2.io/install/install_options/server_config for full list of options | `string` | `""` | no |
| rke2\_version | Version to use for RKE2 server nodes | `string` | `"v1.18.12+rke2r2"` | no |
| rke2\_version | Version to use for RKE2 server nodes | `string` | `"v1.19.7+rke2r1"` | no |
| servers | Number of servers to create | `number` | `1` | no |
| spot | Toggle spot requests for server pool | `bool` | `false` | no |
| ssh\_authorized\_keys | Server pool list of public keys to add as authorized ssh keys | `list(string)` | `[]` | no |
Expand All @@ -191,4 +192,3 @@ Optional policies have the option of being created by default, but are specified
| server\_nodepool\_name | n/a |
| server\_sg | n/a |
| server\_url | n/a |

6 changes: 3 additions & 3 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,8 @@ resource "aws_iam_role_policy" "put_kubeconfig" {
# Server Nodepool
#
module "servers" {
source = "./modules/nodepool"
name = "${local.uname}-server"

source = "./modules/nodepool"
name = "${local.uname}-server"
vpc_id = var.vpc_id
subnets = var.subnets
ami = var.ami
Expand All @@ -187,6 +186,7 @@ module "servers" {
vpc_security_group_ids = concat([aws_security_group.server.id, aws_security_group.cluster.id], var.extra_security_group_ids)
spot = var.spot
load_balancers = [module.cp_lb.name]
cpu_credits = var.cpu_credits

# Overrideable variables
userdata = data.template_cloudinit_config.this.rendered
Expand Down
7 changes: 5 additions & 2 deletions modules/agent-nodepool/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
| asg | Node pool AutoScalingGroup scaling definition | <pre>object({<br> min = number<br> max = number<br> desired = number<br> })</pre> | <pre>{<br> "desired": 1,<br> "max": 10,<br> "min": 1<br>}</pre> | no |
| block\_device\_mappings | Node pool block device mapping configuration | `map(string)` | <pre>{<br> "size": 30,<br> "type": "gp2"<br>}</pre> | no |
| cluster\_data | Required data relevant to joining an existing rke2 cluster, sourced from main rke2 module, do NOT modify | <pre>object({<br> name = string<br> server_url = string<br> cluster_sg = string<br> token = object({<br> bucket = string<br> bucket_arn = string<br> object = string<br> policy_document = string<br> })<br> })</pre> | n/a | yes |
| cpu\_credits | n/a | `string` | `"standard"` | no |
| download | Toggle best effort download of rke2 dependencies (rke2 and aws cli), if disabled, dependencies are assumed to exist in $PATH | `bool` | `true` | no |
| enable\_autoscaler | Toggle configure the nodepool for cluster autoscaler, this will ensure the appropriate IAM policies are present, you are still responsible for ensuring cluster autoscaler is installed | `bool` | `false` | no |
| enable\_ccm | Toggle enabling the cluster as aws aware, this will ensure the appropriate IAM policies are present | `bool` | `false` | no |
| extra\_block\_device\_mappings | Additional node pool block device mappings configuration | `list(map(string))` | `[]` | no |
Expand All @@ -22,7 +24,8 @@
| post\_userdata | Custom userdata to run immediately after rke2 node attempts to join cluster | `string` | `""` | no |
| pre\_userdata | Custom userdata to run immediately before rke2 node attempts to join cluster, after required rke2, dependencies are installed | `string` | `""` | no |
| rke2\_config | Node pool additional configuration passed as rke2 config file, see https://docs.rke2.io/install/install_options/agent_config for full list of options | `string` | `""` | no |
| rke2\_version | Version to use for RKE2 server nodepool | `string` | `"v1.18.10+rke2r1"` | no |
| rke2\_version | Version to use for RKE2 server nodepool | `string` | `"v1.19.7+rke2r1"` | no |
| spot | Toggle spot requests for node pool | `bool` | `false` | no |
| ssh\_authorized\_keys | Node pool list of public keys to add as authorized ssh keys, not required | `list(string)` | `[]` | no |
| subnets | List of subnet IDs to create resources in | `list(string)` | n/a | yes |
| tags | Map of additional tags to add to all resources created | `map(string)` | `{}` | no |
Expand All @@ -34,8 +37,8 @@
|------|-------------|
| iam\_instance\_profile | IAM instance profile attached to nodes in nodepool |
| iam\_role | IAM role of node pool |
| iam\_role\_arn | IAM role arn of node pool |
| nodepool\_arn | n/a |
| nodepool\_id | n/a |
| nodepool\_name | n/a |
| security\_group | n/a |

7 changes: 3 additions & 4 deletions modules/agent-nodepool/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,8 @@ data "template_cloudinit_config" "init" {
# RKE2 Node Pool
#
module "nodepool" {
source = "../nodepool"
name = "${local.name}-agent"

source = "../nodepool"
name = "${local.name}-agent"
vpc_id = var.vpc_id
subnets = var.subnets
ami = var.ami
Expand All @@ -120,7 +119,7 @@ module "nodepool" {
iam_instance_profile = var.iam_instance_profile == "" ? module.iam[0].iam_instance_profile : var.iam_instance_profile
asg = var.asg
spot = var.spot

cpu_credits = var.cpu_credits
tags = merge({
"Role" = "agent",
}, local.default_tags, local.ccm_tags, local.autoscaler_tags, var.tags)
Expand Down
10 changes: 10 additions & 0 deletions modules/agent-nodepool/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,13 @@ variable "post_userdata" {
type = string
default = ""
}

variable "cpu_credits" {
type = string
default = "standard"
validation {
condition = contains(["standard", "unlimited"], var.cpu_credits)
error_message = "Unsupported CPU Credit option supplied. Can be 'standard', or 'unlimited'."
}
}

5 changes: 5 additions & 0 deletions modules/nodepool/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ resource "aws_launch_template" "this" {
}

tags = merge({}, var.tags)

credit_specification {
cpu_credits = var.cpu_credits
}

}

#
Expand Down
9 changes: 9 additions & 0 deletions modules/nodepool/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,12 @@ variable "min_elb_capacity" {
type = number
default = null
}

variable "cpu_credits" {
type = string
default = "standard"
validation {
condition = contains(["standard", "unlimited"], var.cpu_credits)
error_message = "Unsupported CPU Credit option supplied. Can be 'standard', or 'unlimited'."
}
}
9 changes: 9 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,12 @@ variable "enable_ccm" {
type = bool
default = false
}

variable "cpu_credits" {
type = string
default = "standard"
validation {
condition = contains(["standard", "unlimited"], var.cpu_credits)
error_message = "Unsupported CPU Credit option supplied. Can be 'standard', or 'unlimited'."
}
}