Skip to content

🐛 fix(main.tf): fix service-linked-role creation #4

Merged
merged 3 commits into from
Sep 4, 2024
Merged
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
15 changes: 2 additions & 13 deletions ec2_node_class.yaml.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,9 @@ kind: EC2NodeClass
metadata:
name: ${cluster_name}-karpenter-node-class
annotations:
kubernetes.io/description: "EC2NodeClass for running Bottlerocket nodes"
kubernetes.io/description: "EC2NodeClass for running ${amd_ami_family} nodes"
spec:
kubelet:
podsPerCore: 2
maxPods: 20
systemReserved:
cpu: 100m
memory: 100Mi
ephemeral-storage: 1Gi
kubeReserved:
cpu: 200m
memory: 100Mi
ephemeral-storage: 3Gi
evictionHard:
memory.available: 5%
nodefs.available: 10%
Expand All @@ -32,12 +22,11 @@ spec:
evictionMaxPodGracePeriod: 60
imageGCHighThresholdPercent: 85
imageGCLowThresholdPercent: 80
cpuCFSQuota: true

# Required, resolves a default ami and userdata
amiFamily: ${amd_ami_family}
amiSelectorTerms:
- alias: bottlerocket@latest # Bottlerocket
- alias: ${amd_ami_alias}@latest # Bottlerocket
# Required, discovers subnets to attach to instances
# Each term in the array of subnetSelectorTerms is ORed together
# Within a single term, all conditions are ANDed
Expand Down
37 changes: 18 additions & 19 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -152,22 +152,22 @@ resource "helm_release" "karpenter" {
name = "controller.env[0].value"
value = var.region
}
set {
name = "resources.requests.cpu"
value = 1
}
set {
name = "resources.requests.memory"
value = "1Gi"
}
set {
name = "resources.limits.cpu"
value = 1
}
set {
name = "resources.limits.memory"
value = "1Gi"
}
# set {
# name = "resources.requests.cpu"
# value = 1
# }
# set {
# name = "resources.requests.memory"
# value = "1Gi"
# }
# set {
# name = "resources.limits.cpu"
# value = 1
# }
# set {
# name = "resources.limits.memory"
# value = "1Gi"
# }
set {
name = "serviceAccount.annotations.eks\\.amazonaws\\.com/role-arn"
value = module.karpenter_resources.iam_role_arn
Expand All @@ -183,17 +183,15 @@ resource "aws_iam_instance_profile" "karpenter_node_instance_profile" {

# Query to see if service-linked role exists
data "aws_iam_roles" "roles" {
path_prefix = "/aws-reserved/spot.amazonaws.com/${var.cluster_name}"
path_prefix = "/aws-reserved/spot.amazonaws.com"
}

# Permission for spot
resource "aws_iam_service_linked_role" "ec2_spot" {
count = data.aws_iam_roles.roles == null ? 1 : 0
aws_service_name = "spot.amazonaws.com"
custom_suffix = var.cluster_name
}


# SHOULD PROBABLY PUT THESE OBJECTS INTO A HELM CHART
# Create karpenter default
resource "kubectl_manifest" "karpenter_ec2_node_class" {
Expand All @@ -203,6 +201,7 @@ resource "kubectl_manifest" "karpenter_ec2_node_class" {
yaml_body = templatefile("${path.module}/ec2_node_class.yaml.tpl", {
cluster_name = var.cluster_name
amd_ami_family = "Bottlerocket"
amd_ami_alias = "bottlerocket"
})
}

Expand Down