Skip to content

Commit

Permalink
chore(NO_CARD): add default provisioner & nodeTemplate
Browse files Browse the repository at this point in the history
  • Loading branch information
github-clement-bolin committed Nov 12, 2023
1 parent d0ea02a commit b39bb84
Show file tree
Hide file tree
Showing 3 changed files with 145 additions and 0 deletions.
22 changes: 22 additions & 0 deletions modules/karpenter/nodeTemplate.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
resource "kubectl_manifest" "aws_node_template" {
count = var.create && var.create_kubernetes_resources && var.create_aws_node_template ? 1 : 0

yaml_body = try(var.aws_node_template.yaml_body, <<-YAML
apiVersion: karpenter.k8s.aws/v1alpha1
kind: AWSNodeTemplate
metadata:
name: default
spec:
subnetSelector:
aws-ids: "${join(",", var.subnet_ids)}"
securityGroupSelector:
karpenter.sh/discovery: ${var.cluster_name}
tags:
karpenter.sh/discovery: ${var.cluster_name}
YAML
)

depends_on = [
module.eks_blueprints_addons[0].karpenter
]
}
43 changes: 43 additions & 0 deletions modules/karpenter/provisioner.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
resource "kubectl_manifest" "provisioner" {
count = var.create && var.create_kubernetes_resources && var.create_provisioner ? 1 : 0

yaml_body = try(var.provisioner.yaml_body, <<-YAML
apiVersion: karpenter.sh/v1alpha5
kind: Provisioner
metadata:
name: ${var.cluster_name}-default
spec:
requirements:
- key: "topology.kubernetes.io/zone"
operator: In
values: ${jsonencode(var.availability_zones)}
- key: karpenter.k8s.aws/instance-category
operator: In
values: ["c", "m", "r"]
- key: karpenter.k8s.aws/instance-generation
operator: Gt
values: ["2"]
- key: kubernetes.io/arch
operator: In
values: ["arm64", "amd64"]
- key: "karpenter.sh/capacity-type" # If not included, the webhook for the AWS cloud provider will default to on-demand
operator: In
values: ["spot", "on-demand"]
kubeletConfiguration:
containerRuntime: containerd
maxPods: 110
limits:
resources:
cpu: 1000
consolidation:
enabled: true
providerRef:
name: default
ttlSecondsUntilExpired: 2592000 # 30 Days = 60 * 60 * 24 * 30 Seconds
YAML
)

depends_on = [
module.eks_blueprints_addons[0].karpenter
]
}
80 changes: 80 additions & 0 deletions modules/karpenter/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
variable "env" {
description = "Environnement where the stack is running"
type = string
}

variable "service" {
description = "Service using this module"
type = string
}

variable "cluster_name" {
description = "Name of the EKS cluster"
type = string
}

variable "cluster_endpoint" {
description = "Endpoint for your Kubernetes API server"
type = string
}

variable "cluster_version" {
description = "Kubernetes `<major>.<minor>` version to use for the EKS cluster (i.e.: `1.24`)"
type = string
}

variable "oidc_provider_arn" {
description = "The ARN of the cluster OIDC Provider"
type = string
}

variable "create" {
description = "Controls if resources should be created (affects all resources)"
type = bool
default = true
}

variable "karpenter" {
description = "Karpenter add-on configuration values"
type = any
default = {}
}

variable "create_aws_node_template" {
type = bool
default = true
}

variable "subnet_ids" {
type = list(string)
}

variable "aws_node_template" {
type = any
default = {}
}

variable "create_provisioner" {
type = bool
default = true
}

variable "availability_zones" {
type = list(string)
}

variable "provisioner" {
description = "Provisioner configuration values"
type = any
default = {}
}

variable "create_delay_dependencies" {
type = list(string)
default = []
}

variable "create_kubernetes_resources" {
type = bool
default = true
}

0 comments on commit b39bb84

Please sign in to comment.