Skip to content

Commit

Permalink
Merge pull request #105 from dasmeta/DMVP-5359
Browse files Browse the repository at this point in the history
fix(priority-class): DMVP-5359 add priority class
  • Loading branch information
aghamyan44 authored Sep 26, 2024
2 parents c1dc507 + 5702d19 commit f1e950b
Show file tree
Hide file tree
Showing 19 changed files with 250 additions and 3 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ worker_groups = {
| <a name="module_node-problem-detector"></a> [node-problem-detector](#module\_node-problem-detector) | ./modules/node-problem-detector | n/a |
| <a name="module_olm"></a> [olm](#module\_olm) | ./modules/olm | n/a |
| <a name="module_portainer"></a> [portainer](#module\_portainer) | ./modules/portainer | n/a |
| <a name="module_priority_class"></a> [priority\_class](#module\_priority\_class) | ./modules/priority-class/ | n/a |
| <a name="module_sso-rbac"></a> [sso-rbac](#module\_sso-rbac) | ./modules/sso-rbac | n/a |
| <a name="module_vpc"></a> [vpc](#module\_vpc) | dasmeta/vpc/aws | 1.0.1 |
| <a name="module_weave-scope"></a> [weave-scope](#module\_weave-scope) | ./modules/weave-scope | n/a |
Expand All @@ -236,6 +237,7 @@ worker_groups = {
| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_account_id"></a> [account\_id](#input\_account\_id) | AWS Account Id to apply changes into | `string` | `null` | no |
| <a name="input_additional_priority_classes"></a> [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. | <pre>list(object({<br> name = string<br> value = string # number in string form<br> }))</pre> | `[]` | no |
| <a name="input_adot_config"></a> [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. | <pre>object({<br> accept_namespace_regex = optional(string, "(default|kube-system)")<br> additional_metrics = optional(list(string), [])<br> log_group_name = optional(string, "adot")<br> log_retention = optional(number, 14)<br> helm_values = optional(any, null)<br> logging_enable = optional(bool, false)<br> resources = optional(object({<br> limit = object({<br> cpu = optional(string, "200m")<br> memory = optional(string, "200Mi")<br> })<br> requests = object({<br> cpu = optional(string, "200m")<br> memory = optional(string, "200Mi")<br> })<br> }), {<br> limit = {<br> cpu = "200m"<br> memory = "200Mi"<br> }<br> requests = {<br> cpu = "200m"<br> memory = "200Mi"<br> }<br> })<br> })</pre> | <pre>{<br> "accept_namespace_regex": "(default|kube-system)",<br> "additional_metrics": [],<br> "helm_values": null,<br> "log_group_name": "adot",<br> "log_retention": 14,<br> "logging_enable": false,<br> "resources": {<br> "limit": {<br> "cpu": "200m",<br> "memory": "200Mi"<br> },<br> "requests": {<br> "cpu": "200m",<br> "memory": "200Mi"<br> }<br> }<br>}</pre> | no |
| <a name="input_adot_version"></a> [adot\_version](#input\_adot\_version) | The version of the AWS Distro for OpenTelemetry addon to use. | `string` | `"v0.78.0-eksbuild.1"` | no |
| <a name="input_alarms"></a> [alarms](#input\_alarms) | Alarms enabled by default you need set sns topic name for send alarms for customize alarms threshold use custom\_values | <pre>object({<br> enabled = optional(bool, true)<br> sns_topic = string<br> custom_values = optional(any, {})<br> })</pre> | n/a | yes |
Expand Down
2 changes: 1 addition & 1 deletion examples/spot-instance/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

| Name | Version |
|------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 3.41 |
| <a name="provider_aws"></a> [aws](#provider\_aws) | 4.67.0 |

## Modules

Expand Down
37 changes: 37 additions & 0 deletions modules/priority-class/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# priority-class

<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
## Requirements

| Name | Version |
|------|---------|
| <a name="requirement_kubernetes"></a> [kubernetes](#requirement\_kubernetes) | ~>2.23 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_kubernetes"></a> [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 |
|------|-------------|------|---------|:--------:|
| <a name="input_additional_priority_classes"></a> [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. | <pre>list(object({<br> name = string<br> value = string # number in string form<br> }))</pre> | `[]` | no |

## Outputs

| Name | Description |
|------|-------------|
| <a name="output_priority_class"></a> [priority\_class](#output\_priority\_class) | n/a |
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
28 changes: 28 additions & 0 deletions modules/priority-class/main.tf
Original file line number Diff line number Diff line change
@@ -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
}
3 changes: 3 additions & 0 deletions modules/priority-class/output.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
output "priority_class" {
value = local.priority_class
}
37 changes: 37 additions & 0 deletions modules/priority-class/tests/add-new-priority-class/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# add-new-priority-class

<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
## Requirements

No requirements.

## Providers

| Name | Version |
|------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | 5.68.0 |

## Modules

| Name | Source | Version |
|------|--------|---------|
| <a name="module_test"></a> [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 |
|------|-------------|
| <a name="output_priority_class"></a> [priority\_class](#output\_priority\_class) | n/a |
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
10 changes: 10 additions & 0 deletions modules/priority-class/tests/add-new-priority-class/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module "test" {
source = "../../"

additional_priority_classes = [
{
name = "important"
value = "2000000"
},
]
}
3 changes: 3 additions & 0 deletions modules/priority-class/tests/add-new-priority-class/output.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
output "priority_class" {
value = module.test.priority_class
}
27 changes: 27 additions & 0 deletions modules/priority-class/tests/add-new-priority-class/providers.tf
Original file line number Diff line number Diff line change
@@ -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"
}
}
37 changes: 37 additions & 0 deletions modules/priority-class/tests/basic/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# basic

<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
## Requirements

No requirements.

## Providers

| Name | Version |
|------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | n/a |

## Modules

| Name | Source | Version |
|------|--------|---------|
| <a name="module_test"></a> [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 |
|------|-------------|
| <a name="output_priority_class"></a> [priority\_class](#output\_priority\_class) | n/a |
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
3 changes: 3 additions & 0 deletions modules/priority-class/tests/basic/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module "test" {
source = "../../"
}
3 changes: 3 additions & 0 deletions modules/priority-class/tests/basic/output.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
output "priority_class" {
value = module.test.priority_class
}
27 changes: 27 additions & 0 deletions modules/priority-class/tests/basic/providers.tf
Original file line number Diff line number Diff line change
@@ -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"
}
}
8 changes: 8 additions & 0 deletions modules/priority-class/variables.tf
Original file line number Diff line number Diff line change
@@ -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 = []
}
8 changes: 8 additions & 0 deletions modules/priority-class/version.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
terraform {
required_providers {
kubernetes = {
source = "hashicorp/kubernetes"
version = "~>2.23"
}
}
}
5 changes: 5 additions & 0 deletions priority-class.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module "priority_class" {
source = "./modules/priority-class/"

additional_priority_classes = var.additional_priority_classes
}
2 changes: 1 addition & 1 deletion tests/basic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ No requirements.

| Name | Version |
|------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | 4.67.0 |
| <a name="provider_aws"></a> [aws](#provider\_aws) | n/a |

## Modules

Expand Down
2 changes: 1 addition & 1 deletion tests/eks-fluent-bit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

| Name | Version |
|------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | 4.67.0 |
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 3.41 |

## Modules

Expand Down
9 changes: 9 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
}

0 comments on commit f1e950b

Please sign in to comment.