diff --git a/README.md b/README.md index ae3a3a2..9c22756 100644 --- a/README.md +++ b/README.md @@ -217,6 +217,7 @@ worker_groups = { | [node-problem-detector](#module\_node-problem-detector) | ./modules/node-problem-detector | n/a | | [olm](#module\_olm) | ./modules/olm | n/a | | [portainer](#module\_portainer) | ./modules/portainer | n/a | +| [priority\_class](#module\_priority\_class) | ./modules/priority-class/ | n/a | | [sso-rbac](#module\_sso-rbac) | ./modules/sso-rbac | n/a | | [vpc](#module\_vpc) | dasmeta/vpc/aws | 1.0.1 | | [weave-scope](#module\_weave-scope) | ./modules/weave-scope | n/a | @@ -236,6 +237,7 @@ worker_groups = { | Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| | [account\_id](#input\_account\_id) | AWS Account Id to apply changes into | `string` | `null` | no | +| [additional\_priority\_classes](#input\_additional\_priority\_classes) | Defines Priority Classes in Kubernetes, used to assign different levels of priority to pods. By default, this module creates three Priority Classes: 'high'(1000000), 'medium'(500000) and 'low'(250000) . You can also provide a custom list of Priority Classes if needed. |
list(object({| `[]` | no | | [adot\_config](#input\_adot\_config) | accept\_namespace\_regex defines the list of namespaces from which metrics will be exported, and additional\_metrics defines additional metrics to export. |
name = string
value = string # number in string form
}))
object({|
accept_namespace_regex = optional(string, "(default|kube-system)")
additional_metrics = optional(list(string), [])
log_group_name = optional(string, "adot")
log_retention = optional(number, 14)
helm_values = optional(any, null)
logging_enable = optional(bool, false)
resources = optional(object({
limit = object({
cpu = optional(string, "200m")
memory = optional(string, "200Mi")
})
requests = object({
cpu = optional(string, "200m")
memory = optional(string, "200Mi")
})
}), {
limit = {
cpu = "200m"
memory = "200Mi"
}
requests = {
cpu = "200m"
memory = "200Mi"
}
})
})
{| no | | [adot\_version](#input\_adot\_version) | The version of the AWS Distro for OpenTelemetry addon to use. | `string` | `"v0.78.0-eksbuild.1"` | no | | [alarms](#input\_alarms) | Alarms enabled by default you need set sns topic name for send alarms for customize alarms threshold use custom\_values |
"accept_namespace_regex": "(default|kube-system)",
"additional_metrics": [],
"helm_values": null,
"log_group_name": "adot",
"log_retention": 14,
"logging_enable": false,
"resources": {
"limit": {
"cpu": "200m",
"memory": "200Mi"
},
"requests": {
"cpu": "200m",
"memory": "200Mi"
}
}
}
object({| n/a | yes | diff --git a/examples/spot-instance/README.md b/examples/spot-instance/README.md index 41252e4..0bb326b 100644 --- a/examples/spot-instance/README.md +++ b/examples/spot-instance/README.md @@ -12,7 +12,7 @@ | Name | Version | |------|---------| -| [aws](#provider\_aws) | >= 3.41 | +| [aws](#provider\_aws) | 4.67.0 | ## Modules diff --git a/modules/priority-class/README.md b/modules/priority-class/README.md new file mode 100644 index 0000000..41009b3 --- /dev/null +++ b/modules/priority-class/README.md @@ -0,0 +1,37 @@ +# priority-class + + +## Requirements + +| Name | Version | +|------|---------| +| [kubernetes](#requirement\_kubernetes) | ~>2.23 | + +## Providers + +| Name | Version | +|------|---------| +| [kubernetes](#provider\_kubernetes) | ~>2.23 | + +## Modules + +No modules. + +## Resources + +| Name | Type | +|------|------| +| [kubernetes_priority_class.this](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/priority_class) | resource | + +## Inputs + +| Name | Description | Type | Default | Required | +|------|-------------|------|---------|:--------:| +| [additional\_priority\_classes](#input\_additional\_priority\_classes) | Defines Priority Classes in Kubernetes, used to assign different levels of priority to pods. By default, this module creates three Priority Classes: 'high'(1000000), 'medium'(500000) and 'low'(250000) . You can also provide a custom list of Priority Classes if needed. |
enabled = optional(bool, true)
sns_topic = string
custom_values = optional(any, {})
})
list(object({| `[]` | no | + +## Outputs + +| Name | Description | +|------|-------------| +| [priority\_class](#output\_priority\_class) | n/a | + diff --git a/modules/priority-class/main.tf b/modules/priority-class/main.tf new file mode 100644 index 0000000..2b23fdd --- /dev/null +++ b/modules/priority-class/main.tf @@ -0,0 +1,28 @@ +locals { + priority_class_default = [ + { + name = "high" + value = "1000000" + }, + { + name = "medium" + value = "500000" + }, + { + name = "low" + value = "250000" + } + ] + priority_class = concat(local.priority_class_default, var.additional_priority_classes) +} + +resource "kubernetes_priority_class" "this" { + # Transform the list of maps into a key-value map suitable for for_each + for_each = { for pc in local.priority_class : pc.name => pc } + + metadata { + name = each.key + } + + value = each.value.value +} diff --git a/modules/priority-class/output.tf b/modules/priority-class/output.tf new file mode 100644 index 0000000..9f0004d --- /dev/null +++ b/modules/priority-class/output.tf @@ -0,0 +1,3 @@ +output "priority_class" { + value = local.priority_class +} diff --git a/modules/priority-class/tests/add-new-priority-class/README.md b/modules/priority-class/tests/add-new-priority-class/README.md new file mode 100644 index 0000000..ac7b4c1 --- /dev/null +++ b/modules/priority-class/tests/add-new-priority-class/README.md @@ -0,0 +1,37 @@ +# add-new-priority-class + + +## Requirements + +No requirements. + +## Providers + +| Name | Version | +|------|---------| +| [aws](#provider\_aws) | 5.68.0 | + +## Modules + +| Name | Source | Version | +|------|--------|---------| +| [test](#module\_test) | ../../ | n/a | + +## Resources + +| Name | Type | +|------|------| +| [aws_eks_cluster.test-cluster](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/eks_cluster) | data source | +| [aws_eks_cluster_auth.test-cluster](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/eks_cluster_auth) | data source | +| [aws_iam_openid_connect_provider.test-cluster-oidc-provider](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_openid_connect_provider) | data source | + +## Inputs + +No inputs. + +## Outputs + +| Name | Description | +|------|-------------| +| [priority\_class](#output\_priority\_class) | n/a | + diff --git a/modules/priority-class/tests/add-new-priority-class/main.tf b/modules/priority-class/tests/add-new-priority-class/main.tf new file mode 100644 index 0000000..786020c --- /dev/null +++ b/modules/priority-class/tests/add-new-priority-class/main.tf @@ -0,0 +1,10 @@ +module "test" { + source = "../../" + + additional_priority_classes = [ + { + name = "important" + value = "2000000" + }, + ] +} diff --git a/modules/priority-class/tests/add-new-priority-class/output.tf b/modules/priority-class/tests/add-new-priority-class/output.tf new file mode 100644 index 0000000..01e8162 --- /dev/null +++ b/modules/priority-class/tests/add-new-priority-class/output.tf @@ -0,0 +1,3 @@ +output "priority_class" { + value = module.test.priority_class +} diff --git a/modules/priority-class/tests/add-new-priority-class/providers.tf b/modules/priority-class/tests/add-new-priority-class/providers.tf new file mode 100644 index 0000000..56dcb27 --- /dev/null +++ b/modules/priority-class/tests/add-new-priority-class/providers.tf @@ -0,0 +1,27 @@ +locals { + cluster_name = "stage" +} + +data "aws_eks_cluster" "test-cluster" { + name = local.cluster_name +} + +data "aws_eks_cluster_auth" "test-cluster" { + name = local.cluster_name +} + +data "aws_iam_openid_connect_provider" "test-cluster-oidc-provider" { + url = data.aws_eks_cluster.test-cluster.identity[0].oidc[0].issuer +} + +provider "kubernetes" { + host = data.aws_eks_cluster.test-cluster.endpoint + cluster_ca_certificate = base64decode(data.aws_eks_cluster.test-cluster.certificate_authority.0.data) + token = data.aws_eks_cluster_auth.test-cluster.token + + exec { + api_version = "client.authentication.k8s.io/v1beta1" + args = ["eks", "--region", "eu-central-1", "get-token", "--cluster-name", local.cluster_name] + command = "aws" + } +} diff --git a/modules/priority-class/tests/basic/README.md b/modules/priority-class/tests/basic/README.md new file mode 100644 index 0000000..b4ba7d6 --- /dev/null +++ b/modules/priority-class/tests/basic/README.md @@ -0,0 +1,37 @@ +# basic + + +## Requirements + +No requirements. + +## Providers + +| Name | Version | +|------|---------| +| [aws](#provider\_aws) | n/a | + +## Modules + +| Name | Source | Version | +|------|--------|---------| +| [test](#module\_test) | ../../ | n/a | + +## Resources + +| Name | Type | +|------|------| +| [aws_eks_cluster.test-cluster](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/eks_cluster) | data source | +| [aws_eks_cluster_auth.test-cluster](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/eks_cluster_auth) | data source | +| [aws_iam_openid_connect_provider.test-cluster-oidc-provider](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_openid_connect_provider) | data source | + +## Inputs + +No inputs. + +## Outputs + +| Name | Description | +|------|-------------| +| [priority\_class](#output\_priority\_class) | n/a | + diff --git a/modules/priority-class/tests/basic/main.tf b/modules/priority-class/tests/basic/main.tf new file mode 100644 index 0000000..016442f --- /dev/null +++ b/modules/priority-class/tests/basic/main.tf @@ -0,0 +1,3 @@ +module "test" { + source = "../../" +} diff --git a/modules/priority-class/tests/basic/output.tf b/modules/priority-class/tests/basic/output.tf new file mode 100644 index 0000000..01e8162 --- /dev/null +++ b/modules/priority-class/tests/basic/output.tf @@ -0,0 +1,3 @@ +output "priority_class" { + value = module.test.priority_class +} diff --git a/modules/priority-class/tests/basic/providers.tf b/modules/priority-class/tests/basic/providers.tf new file mode 100644 index 0000000..56dcb27 --- /dev/null +++ b/modules/priority-class/tests/basic/providers.tf @@ -0,0 +1,27 @@ +locals { + cluster_name = "stage" +} + +data "aws_eks_cluster" "test-cluster" { + name = local.cluster_name +} + +data "aws_eks_cluster_auth" "test-cluster" { + name = local.cluster_name +} + +data "aws_iam_openid_connect_provider" "test-cluster-oidc-provider" { + url = data.aws_eks_cluster.test-cluster.identity[0].oidc[0].issuer +} + +provider "kubernetes" { + host = data.aws_eks_cluster.test-cluster.endpoint + cluster_ca_certificate = base64decode(data.aws_eks_cluster.test-cluster.certificate_authority.0.data) + token = data.aws_eks_cluster_auth.test-cluster.token + + exec { + api_version = "client.authentication.k8s.io/v1beta1" + args = ["eks", "--region", "eu-central-1", "get-token", "--cluster-name", local.cluster_name] + command = "aws" + } +} diff --git a/modules/priority-class/variables.tf b/modules/priority-class/variables.tf new file mode 100644 index 0000000..e9fb597 --- /dev/null +++ b/modules/priority-class/variables.tf @@ -0,0 +1,8 @@ +variable "additional_priority_classes" { + type = list(object({ + name = string + value = string # number in string form + })) + description = "Defines Priority Classes in Kubernetes, used to assign different levels of priority to pods. By default, this module creates three Priority Classes: 'high'(1000000), 'medium'(500000) and 'low'(250000) . You can also provide a custom list of Priority Classes if needed." + default = [] +} diff --git a/modules/priority-class/version.tf b/modules/priority-class/version.tf new file mode 100644 index 0000000..3fbb9ef --- /dev/null +++ b/modules/priority-class/version.tf @@ -0,0 +1,8 @@ +terraform { + required_providers { + kubernetes = { + source = "hashicorp/kubernetes" + version = "~>2.23" + } + } +} diff --git a/priority-class.tf b/priority-class.tf new file mode 100644 index 0000000..c5695fe --- /dev/null +++ b/priority-class.tf @@ -0,0 +1,5 @@ +module "priority_class" { + source = "./modules/priority-class/" + + additional_priority_classes = var.additional_priority_classes +} diff --git a/tests/basic/README.md b/tests/basic/README.md index bcd75fe..3f65220 100644 --- a/tests/basic/README.md +++ b/tests/basic/README.md @@ -9,7 +9,7 @@ No requirements. | Name | Version | |------|---------| -| [aws](#provider\_aws) | 4.67.0 | +| [aws](#provider\_aws) | n/a | ## Modules diff --git a/tests/eks-fluent-bit/README.md b/tests/eks-fluent-bit/README.md index ee3b419..48f1b86 100644 --- a/tests/eks-fluent-bit/README.md +++ b/tests/eks-fluent-bit/README.md @@ -12,7 +12,7 @@ | Name | Version | |------|---------| -| [aws](#provider\_aws) | 4.67.0 | +| [aws](#provider\_aws) | >= 3.41 | ## Modules diff --git a/variables.tf b/variables.tf index a1008a7..28842c0 100644 --- a/variables.tf +++ b/variables.tf @@ -563,3 +563,12 @@ variable "alarms" { }) description = "Alarms enabled by default you need set sns topic name for send alarms for customize alarms threshold use custom_values" } + +variable "additional_priority_classes" { + type = list(object({ + name = string + value = string # number in string form + })) + description = "Defines Priority Classes in Kubernetes, used to assign different levels of priority to pods. By default, this module creates three Priority Classes: 'high'(1000000), 'medium'(500000) and 'low'(250000) . You can also provide a custom list of Priority Classes if needed." + default = [] +}
name = string
value = string # number in string form
}))