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

Provide support of Cluster Proportional Autoscaler (CPA) in calling module #61

Open
wants to merge 1 commit into
base: release-3.1.1
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
19 changes: 19 additions & 0 deletions examples/complete/config/cluster-propotional_autoscaler.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Formula for controlling the replicas. Adjust according to your needs
# replicas = max( ceil( cores * 1/coresPerReplica ) , ceil( nodes * 1/nodesPerReplica ) )
# replicas = min(replicas, max)
# replicas = max(replicas, min)
config:
linear:
coresPerReplica: 1
nodesPerReplica: 1
min: 1
max: 20
preventSinglePointFailure: true
includeUnschedulableNodes: true

# Target to scale. In format: deployment/*, replicationcontroller/* or replicaset/* (not case sensitive).
# The following option should be defined in user defined values.yaml using var.helm_config

options:
target: deployment/coredns

8 changes: 6 additions & 2 deletions examples/complete/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ locals {
Environment = local.environment
}
argocd_namespace = "atmosly" # Give Namespace
kms_key_arn = "arn:aws:kms:us-west-1:xxxxxxx:key/mrk-xxxxxxx" # pass ARN of EKS created KMS key
kms_key_arn = "" # pass ARN of EKS created KMS key
ipv6_enabled = false
}

module "eks-addons" {
source = "../.."
name = local.name
tags = local.additional_tags
vpc_id = "vpc-xxxxxx" # pass VPC ID
vpc_id = "vpc-xxxxxx" # pass VPC ID
private_subnet_ids = ["subnet-xxxxx", "subnet-xxxxx"] # pass Subnet IDs
environment = local.environment
ipv6_enabled = local.ipv6_enabled
Expand Down Expand Up @@ -58,6 +58,10 @@ module "eks-addons" {
cluster_autoscaler_enabled = false # to enable cluster autoscaller
cluster_autoscaler_helm_config = [file("${path.module}/config/cluster-autoscaler.yaml")]


cluster_propotional_autoscaler_enabled = false # to enable cluster proportional autoscaler
cluster_propotional_autoscaler_helm_config = [file("${path.module}/config/cluster-propotional_autoscaler.yaml")]

## NODE-TERMINATION-HANDLER
aws_node_termination_handler_enabled = false # to enable node termination handler
aws_node_termination_handler_helm_config = {
Expand Down
13 changes: 13 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,17 @@ module "cluster-autoscaler" {
addon_context = local.addon_context
}

module "cluster-propotional-autoscaler" {
source = "./modules/cluster-propotional-autoscaler"
count = var.cluster_propotional_autoscaler_enabled ? 1 : 0
helm_config = {
version = var.cluster_propotional_autoscaler_chart_version
values = var.cluster_propotional_autoscaler_helm_config
}
manage_via_gitops = var.argocd_manage_add_ons
addon_context = local.addon_context
}

## COREDNS HPA
module "coredns_hpa" {
source = "./modules/core-dns-hpa"
Expand Down Expand Up @@ -503,3 +514,5 @@ resource "helm_release" "falco" {
})
]
}


25 changes: 19 additions & 6 deletions modules/cluster-propotional-autoscaler/config/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
# replicas = max(replicas, min)
config:
linear:
coresPerReplica: 256
nodesPerReplica: 16
coresPerReplica: 10
nodesPerReplica: 2
min: 1
max: 100
preventSinglePointFailure: true
Expand All @@ -14,8 +14,11 @@ config:
# Target to scale. In format: deployment/*, replicationcontroller/* or replicaset/* (not case sensitive).
# The following option should be defined in user defined values.yaml using var.helm_config

#options:
# target:
options:
target: deployment/coredns

podAnnotations:
co.elastic.logs/enabled: "true"

podSecurityContext:
seccompProfile:
Expand All @@ -24,8 +27,8 @@ podSecurityContext:
fsGroup: 65534

nodeSelector:
kubernetes.io/os: ${operating_system}

kubernetes.io/os: linux
resources:
limits:
cpu: 100m
Expand All @@ -37,3 +40,13 @@ resources:
tolerations:
- key: "CriticalAddonsOnly"
operator: "Exists"

affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: "Addons-Services"
operator: In
values:
- "true"
52 changes: 0 additions & 52 deletions modules/cluster-propotional-autoscaler/cpa.yaml

This file was deleted.

29 changes: 29 additions & 0 deletions modules/cluster-propotional-autoscaler/locals.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
locals {
name = "cluster-proportional-autoscaler"
namespace = "kube-system"

default_helm_values = [templatefile("${path.module}/config/values.yaml", {
enable_service_monitor = var.enable_service_monitor
})]

default_helm_config = {
name = local.name
chart = local.name
repository = "https://kubernetes-sigs.github.io/cluster-proportional-autoscaler"
version = "1.1.0"
namespace = local.namespace
description = "Cluster Proportional Autoscaler Helm Chart"
values = local.default_helm_values
}

helm_config = merge(
local.default_helm_config,
var.helm_config,
{
values = concat(
local.default_helm_values, # Values from config folder
var.helm_config.values # Values from the variable
)
}
)
}
18 changes: 1 addition & 17 deletions modules/cluster-propotional-autoscaler/main.tf
Original file line number Diff line number Diff line change
@@ -1,22 +1,6 @@
module "helm_addon" {
source = "../helm-addon"

# https://github.com/kubernetes-sigs/cluster-proportional-autoscaler/blob/master/charts/cluster-proportional-autoscaler/Chart.yaml
helm_config = merge(
{
name = "cluster-proportional-autoscaler"
chart = "cluster-proportional-autoscaler"
repository = "https://kubernetes-sigs.github.io/cluster-proportional-autoscaler"
version = "1.1.0"
namespace = "kube-system"
values = [templatefile("${path.module}/config/values.yaml", {
operating_system = "linux"
})]
description = "Cluster Proportional Autoscaler Helm Chart"
},
var.helm_config
)

helm_config = local.helm_config
manage_via_gitops = var.manage_via_gitops
addon_context = var.addon_context
}
8 changes: 7 additions & 1 deletion modules/cluster-propotional-autoscaler/variables.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
variable "helm_config" {
description = "Helm provider config for the Karpenter"
description = "Helm provider config for cluster proportional autoscaler "
type = any
default = {}
}
Expand All @@ -24,3 +24,9 @@ variable "addon_context" {
tags = map(string)
})
}

variable "enable_service_monitor" {
description = "Enable Service monitor for Kubernetes Services"
type = bool
default = false
}
2 changes: 1 addition & 1 deletion modules/helm-addon/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ resource "helm_release" "addon" {
name = var.helm_config["name"]
repository = try(var.helm_config["repository"], null)
chart = var.helm_config["chart"]
version = try(var.helm_config["version"], null)
version = try(var.helm_config["version"][0], null)
timeout = try(var.helm_config["timeout"], 1200)
values = try(var.helm_config["values"], null)
create_namespace = length(var.irsa_config) > 0 ? false : try(var.helm_config["create_namespace"], false)
Expand Down
16 changes: 16 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -656,4 +656,20 @@ variable "karpenter_node_iam_instance_profile" {
default = ""
}

variable "cluster_propotional_autoscaler_enabled" {
description = "Whether to enable the Cluster propotional Autoscaler add-on or not."
default = true
type = bool
}

variable "cluster_propotional_autoscaler_chart_version" {
description = "Version of the cluster propotional autoscaler helm chart"
default = "1.1.0"
type = string
}

variable "cluster_propotional_autoscaler_helm_config" {
description = "Configuration options for the Cluster Propotional Autoscaler Helm chart."
type = any
default = {}
}