Skip to content

No kubectl #16

Merged
merged 69 commits into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
bd2365c
convert to helm charts
morga471 Jan 29, 2025
c8418e7
update pathing
morga471 Jan 29, 2025
ac6898d
cruft and tags
morga471 Jan 29, 2025
3ce4222
jsonit
morga471 Jan 29, 2025
550b10f
tags
morga471 Jan 29, 2025
81ddbc4
formatting
morga471 Jan 29, 2025
b1e7e01
fmt
morga471 Jan 29, 2025
1e006ea
comment
morga471 Jan 29, 2025
87404a8
tags2
morga471 Jan 29, 2025
9bd4d9a
add json
morga471 Jan 29, 2025
f9ea1a4
fix fmt
morga471 Jan 29, 2025
37553d9
formatting v2
morga471 Jan 29, 2025
dcbd3bc
quotes
morga471 Jan 29, 2025
e6413dc
escape the slashes
morga471 Jan 29, 2025
1a27fca
fmt3
morga471 Jan 29, 2025
887959e
fmt4
morga471 Jan 29, 2025
6769217
subnet selectors
morga471 Jan 29, 2025
26cf47a
fmt4
morga471 Jan 29, 2025
c8daa08
quotes
morga471 Jan 29, 2025
03002e9
more quotes
morga471 Jan 29, 2025
4ae7bf2
remove values defaults
morga471 Jan 29, 2025
77eab48
remove problem lines
morga471 Jan 29, 2025
2cf00ec
add subnetSelectorTerms again
morga471 Jan 30, 2025
3e5c0e8
ergh
morga471 Jan 30, 2025
6211713
index
morga471 Jan 30, 2025
cc37cba
use the tools
morga471 Jan 30, 2025
4cc579a
Name?
morga471 Jan 30, 2025
6c684ad
pass in same
morga471 Jan 30, 2025
1822d20
wip
morga471 Jan 30, 2025
6cbdedd
add if around labels
morga471 Jan 30, 2025
fe05dc1
lints
morga471 Jan 30, 2025
ee201dd
data structures
morga471 Jan 30, 2025
1f9a27c
cleanup
morga471 Jan 30, 2025
0e05d6f
fmt
morga471 Jan 30, 2025
a359fda
index on securityGroup
morga471 Jan 30, 2025
aafe5d3
indexes
morga471 Jan 30, 2025
e3ce602
swap role for instanceProfile
morga471 Jan 30, 2025
7c010ed
.name
morga471 Jan 30, 2025
586c33f
comment out bad default value
morga471 Feb 3, 2025
f77bce8
not a map
morga471 Feb 6, 2025
c2f6a68
not a map
morga471 Feb 6, 2025
7303072
not a map
morga471 Feb 6, 2025
4b61f0f
not a map
morga471 Feb 6, 2025
d5aefcf
remove commented value
morga471 Feb 6, 2025
1103cc1
weird tflint errors
morga471 Feb 7, 2025
52414a1
plugins
morga471 Feb 7, 2025
5d4265b
retry
morga471 Feb 7, 2025
a2f721d
parsing errors
morga471 Feb 7, 2025
dde2509
update values
morga471 Feb 7, 2025
30e69c0
add budgets
morga471 Feb 7, 2025
ec3de74
update nodepool.yaml
morga471 Feb 7, 2025
a1603ff
set limits
morga471 Feb 7, 2025
89161d5
more values
morga471 Feb 7, 2025
d2a223e
fmt
morga471 Feb 7, 2025
ac8b359
comment likely problem
morga471 Feb 7, 2025
4fe1440
update values
morga471 Feb 7, 2025
58d7f95
more
morga471 Feb 7, 2025
14f6a11
even more
morga471 Feb 7, 2025
fab33ab
undo
morga471 Feb 7, 2025
9edcc20
redo
morga471 Feb 7, 2025
b556fbb
undo
morga471 Feb 7, 2025
ec3ae8c
dont set default limits
morga471 Feb 12, 2025
76f61a4
more reqs
morga471 Feb 12, 2025
ed1c8bf
update default limits
morga471 Feb 12, 2025
c99fa51
update default limits
morga471 Feb 12, 2025
eccf52b
tags maybe
morga471 Feb 12, 2025
5d271f2
dont look up the value guess it
morga471 Feb 12, 2025
4a676fc
add instance profile again because govcloud
morga471 Feb 12, 2025
0c0e6ff
restore tflint config
morga471 Feb 12, 2025
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
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ repos:
args: [--markdown-linebreak-ext=md]
exclude: CHANGELOG.md

- id: check-yaml
# - id: check-yaml
- id: check-merge-conflict
- id: check-executables-have-shebangs

Expand All @@ -50,7 +50,7 @@ repos:

# Terraform Hooks
- repo: https://github.com/antonbabenko/pre-commit-terraform
rev: v1.96.1 # Get the latest from: https://github.com/antonbabenko/pre-commit-terraform/releases
rev: v1.97.3 # Get the latest from: https://github.com/antonbabenko/pre-commit-terraform/releases
hooks:
- id: terraform_fmt
args:
Expand Down
7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,13 @@ The module deploys Karpenter needed AWS resources, namely in IAM. It copies the
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.14.0 |
| <a name="requirement_helm"></a> [helm](#requirement\_helm) | >= 2.11.0 |
| <a name="requirement_kubernetes"></a> [kubernetes](#requirement\_kubernetes) | >= 2.23.0 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | 5.84.0 |
| <a name="provider_helm"></a> [helm](#provider\_helm) | 2.17.0 |
| <a name="provider_kubernetes"></a> [kubernetes](#provider\_kubernetes) | 2.35.1 |

## Modules

Expand All @@ -41,10 +39,9 @@ The module deploys Karpenter needed AWS resources, namely in IAM. It copies the

| Name | Type |
|------|------|
| [aws_iam_instance_profile.karpenter_node_instance_profile](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_instance_profile) | resource |
| [aws_iam_instance_profile.karpenter_node](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_instance_profile) | resource |
| [helm_release.karpenter](https://registry.terraform.io/providers/hashicorp/helm/latest/docs/resources/release) | resource |
| [kubernetes_manifest.karpenter_node_class](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/manifest) | resource |
| [kubernetes_manifest.karpenter_node_pool](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/manifest) | resource |
| [helm_release.nodepool_resources](https://registry.terraform.io/providers/hashicorp/helm/latest/docs/resources/release) | resource |
| [aws_arn.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/arn) | data source |
| [aws_caller_identity.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source |
| [aws_ecr_image.karpenter_image](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ecr_image) | data source |
Expand Down
6 changes: 6 additions & 0 deletions karpenter-resources/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: v2
name: karpenter-resources
description: Helm chart for configuring custom resources for Karpenter on the cluster
version: 0.0.2
appVersion: 0.0.2
icon: https://repository-images.githubusercontent.com/278480393/dab059c8-caa1-4b55-aaa7-3d30e47a5616
71 changes: 71 additions & 0 deletions karpenter-resources/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Karpenter Resources Helm Chart

## Overview

This Helm chart is an abstraction layer designed for deploying various configurations of Karpenter nodes in a Kubernetes cluster managed by EKS. It integrates seamlessly with Terraform, allowing users to define different node pools and settings for their Kubernetes cluster.

## Prerequisites

- Helm 3.x or later installed
- Terraform installed
- Access to an AWS EKS cluster

## Configuration

The chart is configured to be used with Terraform. Here is an example of how you might define Helm releases for different Karpenter configurations in your Terraform files using EKS Blueprints add-ons:

```hcl
module "eks_blueprints_addons" {
# ... other configurations ...
helm_releases = {
karpenter-resources-default = {
name = "default"
description = "A Helm chart for default node pool"
chart = "${path.module}/helm-values/karpenter-resources"
values = [
<<-EOT
clusterName: ${module.eks.cluster_name}
ec2NodeClass:
karpenterRole: ${split("/", module.eks_blueprints_addons.karpenter.node_iam_role_arn)[1]}
nodePool:
labels:
- provisioner: default
- workload: rayhead
EOT
]
}
}
}
```

## Testing the Chart with Helm Template

To review the Kubernetes manifests that will be generated by the Helm chart based on your configuration, you can use the `helm template` command. This is especially useful for validating your Terraform configurations before applying them.

1. **Generate the Manifests**

Navigate to the directory where your Helm chart is located.

```sh
cd path/to/helm-chart
```

2. **Run Helm Template**

Use the `helm template` command with your custom values. For example:

```sh
helm template my-release-name . --values values.yaml
```

Replace `my-release-name` with a name for your release, and `values.yaml` with the path to your custom values file.

To test specific configurations defined in your Terraform file, you can create a temporary values file with the configuration snippet from your Terraform definition:

```sh
echo '<your Terraform values here>' > temp-values.yaml
helm template my-release-name . --values temp-values.yaml
rm temp-values.yaml
```

This will output the Kubernetes manifests to your terminal, allowing you to review them.
125 changes: 125 additions & 0 deletions karpenter-resources/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "karpenter-node-pool.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "karpenter-node-pool.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "karpenter-node-pool.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "karpenter-node-pool.labels" -}}
helm.sh/chart: {{ include "karpenter-node-pool.chart" . }}
{{ include "karpenter-node-pool.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "karpenter-node-pool.selectorLabels" -}}
app.kubernetes.io/name: {{ include "karpenter-node-pool.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "karpenter-node-pool.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "karpenter-node-pool.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}

{{/*
Expand the name of the chart.
*/}}
{{- define "karpenter-node-class.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "karpenter-node-class.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "karpenter-node-class.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "karpenter-node-class.labels" -}}
helm.sh/chart: {{ include "karpenter-node-class.chart" . }}
{{ include "karpenter-node-class.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "karpenter-node-class.selectorLabels" -}}
app.kubernetes.io/name: {{ include "karpenter-node-class.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "karpenter-node-class.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "karpenter-node-class.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
73 changes: 73 additions & 0 deletions karpenter-resources/templates/node-class.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{{- if .Values.ec2NodeClass.enabled }}
apiVersion: karpenter.k8s.aws/v1
kind: EC2NodeClass
metadata:
name: {{ .Values.nodePool.nodeClassRef.name }}
spec:
{{- if .Values.ec2NodeClass.amiFamily }}
amiFamily: {{ .Values.ec2NodeClass.amiFamily }}
{{- end }}
{{- if .Values.ec2NodeClass.amiSelectorTerms }}
amiSelectorTerms:
{{- toYaml .Values.ec2NodeClass.amiSelectorTerms | nindent 4 }}
{{- end }}
{{- if .Values.ec2NodeClass.subnetSelectorTerms }}
subnetSelectorTerms:
{{- range .Values.ec2NodeClass.subnetSelectorTerms }}
- {{- if .tags }}
tags:
{{- range $key, $value := .tags }}
{{ $key }}: {{ $value | quote }}
{{- end }}
{{- end }}
{{- if .id }}
id: {{ .id }}
{{- end }}
{{- end }}
{{- end }}
{{- if .Values.ec2NodeClass.securityGroupSelectorTerms }}
securityGroupSelectorTerms:
{{- range .Values.ec2NodeClass.securityGroupSelectorTerms }}
- {{- if .tags }}
tags:
{{- range $key, $value := .tags }}
{{ $key }}: {{ $value | quote }}
{{- end }}
{{- end }}
{{- if .id }}
id: {{ .id }}
{{- end }}
{{- if .name }}
name: {{ .name }}
{{- end }}
{{- end }}
{{- end }}
instanceProfile: {{ .Values.ec2NodeClass.karpenterRole }}
{{- if .Values.ec2NodeClass.tags }}
tags:
{{- range $key, $value := .Values.ec2NodeClass.tags }}
{{ $key }}: {{ $value | quote }}
{{- end }}
{{- end }}
metadataOptions:
httpEndpoint: {{ .Values.ec2NodeClass.metadataOptions.httpEndpoint }}
{{- if .Values.ec2NodeClass.metadataOptions.httpProtocolIPv6 }}
httpProtocolIPv6: {{ .Values.ec2NodeClass.metadataOptions.httpProtocolIPv6 }}
{{- end }}
{{- if .Values.ec2NodeClass.metadataOptions.httpPutResponseHopLimit }}
httpPutResponseHopLimit: {{ .Values.ec2NodeClass.metadataOptions.httpPutResponseHopLimit }}
{{- end }}
httpTokens: {{ .Values.ec2NodeClass.metadataOptions.httpTokens }}
{{- if .Values.ec2NodeClass.blockDeviceMappings }}
blockDeviceMappings:
{{- toYaml .Values.ec2NodeClass.blockDeviceMappings | nindent 4 }}
{{- end }}
detailedMonitoring: {{ .Values.ec2NodeClass.detailedMonitoring }}
{{- if .Values.ec2NodeClass.instanceStorePolicy }}
instanceStorePolicy: {{ .Values.ec2NodeClass.instanceStorePolicy }}
{{- end }}
{{- if .Values.ec2NodeClass.userData }}
userData: |
{{- .Values.ec2NodeClass.userData | nindent 4 }}
{{- end }}
{{- end }}
57 changes: 57 additions & 0 deletions karpenter-resources/templates/node-pool.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{{- if .Values.nodePool.enabled }}
apiVersion: karpenter.sh/v1
kind: NodePool
metadata:
name: {{ .Values.nodePool.name }}
spec:
template:
metadata:
labels:
NodePool: {{ .Values.nodePool.name }}
NodeGroupType: {{ .Values.nodePool.name }}
{{- if .Values.nodePool.labels }}
{{- with .Values.nodePool.labels }}
{{- range $key, $value := . }}
{{ $key }}: {{ $value | quote }}
{{- end }}
{{- end }}
{{- end }}
spec:
nodeClassRef:
name: {{ .Values.nodePool.nodeClassRef.name }}
group: {{ .Values.nodePool.nodeClassRef.group }}
kind: {{ .Values.nodePool.nodeClassRef.kind }}
{{- with .Values.nodePool.taints }}
taints:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.nodePool.requirements }}
requirements:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- if .Values.nodePool.expireAfter }}
expireAfter: {{ .Values.nodePool.expireAfter }}
{{- end }}
{{- if .Values.nodePool.terminationGracePeriod }}
terminationGracePeriod: {{ .Values.nodePool.terminationGracePeriod }}
{{- end }}
disruption:
consolidationPolicy: {{ .Values.nodePool.disruption.consolidationPolicy }}
consolidateAfter: {{ .Values.nodePool.disruption.consolidateAfter }}
{{- with .Values.nodePool.disruption.budgets }}
budgets:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- with .Values.nodePool.limits }}
limits:
{{- if .cpu }}
cpu: {{ .cpu }}
{{- end }}
{{- if .memory }}
memory: {{ .memory }}
{{- end }}
{{- end }}
{{- if .Values.nodePool.weight }}
weight: {{ .Values.nodePool.weight }}
{{- end }}
{{- end }}
Loading