Skip to content

autoscaling #18

Merged
merged 33 commits into from
Mar 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
cc9251f
autoscaling
morga471 Feb 28, 2025
d2b761f
add startup taint
morga471 Mar 5, 2025
75c3c16
add namespace and startup taint to template
morga471 Mar 5, 2025
bc776f3
templatlize
morga471 Mar 5, 2025
151997f
fix vals
morga471 Mar 5, 2025
4e10249
fewer things
morga471 Mar 5, 2025
fe6559f
add a few missing values
morga471 Mar 5, 2025
ceb85f5
create ns
morga471 Mar 5, 2025
8bb3bc4
update values
morga471 Mar 5, 2025
4703425
add nodeSelector and tolerations
morga471 Mar 5, 2025
f0005df
remove digest
morga471 Mar 5, 2025
1aee35c
node group
morga471 Mar 5, 2025
a5ef77b
fmt
morga471 Mar 5, 2025
ed74776
syntax and startupTaints
morga471 Mar 5, 2025
cc134b4
fix syntax
morga471 Mar 5, 2025
b3a45c8
update values
morga471 Mar 5, 2025
960f663
remove ng selector
morga471 Mar 5, 2025
b4dcd79
lower cpu requests
morga471 Mar 5, 2025
d8785b2
use digest again
morga471 Mar 5, 2025
9409480
simplify repository
morga471 Mar 5, 2025
d658640
fix repository
morga471 Mar 5, 2025
ca03492
add digest value
morga471 Mar 5, 2025
cfa7798
escape the .
morga471 Mar 5, 2025
b310480
fix subnets_name
morga471 Mar 5, 2025
e1ccf85
subnet selector
morga471 Mar 5, 2025
705ebc0
use the outputs from karpenter module
morga471 Mar 5, 2025
c992ddc
create instance profile true
morga471 Mar 5, 2025
8e091d8
cleanup
morga471 Mar 5, 2025
0522914
without cluster tag
morga471 Mar 5, 2025
6be6c79
pass in vpc
morga471 Mar 5, 2025
b7aa5f1
enable debug and disable serviceMonitor
morga471 Mar 6, 2025
e2f7086
lower resources
morga471 Mar 7, 2025
c131b23
fix merge issues
morga471 Mar 11, 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
101 changes: 101 additions & 0 deletions .github/workflows/terragrunt-cicd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
name: 'Terraform Module CI'

on:
push:
branches:
- main
paths:
- '**/*.hcl'
- '**/*.tf'
pull_request:
branches:
- main
paths:
- '**/*.hcl'
- '**/*.tf'

permissions:
contents: read
pull-requests: write

jobs:
validate:
name: 'Validate Module'
runs-on: self-hosted

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
with:
terraform_version: 1.5.0

- name: Terraform Init
run: |
terraform init -backend=false
- name: Terraform Format
run: |
terraform fmt -check
- name: Terraform Validate
run: |
terraform validate
- name: Run tflint
uses: terraform-linters/setup-tflint@v3
if: github.event_name == 'pull_request'

- name: Lint Terraform
if: github.event_name == 'pull_request'
run: |
tflint --format compact
release:
name: 'Create Release'
needs: validate
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
runs-on: self-hosted
permissions:
contents: write

steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}

- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.9'

- name: Install Commitizen
run: |
pip install commitizen
- name: Configure Git
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
- name: Bump Version and Generate Changelog
id: cz
run: |
cz bump --yes
echo "new_version=$(cz version --project)" >> $GITHUB_OUTPUT
echo "changelog=$(cz changelog --dry-run)" >> $GITHUB_OUTPUT
- name: Create Release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ steps.cz.outputs.new_version }}
release_name: Release v${{ steps.cz.outputs.new_version }}
draft: false
prerelease: false
body: ${{ steps.cz.outputs.changelog }}
26 changes: 13 additions & 13 deletions .tflint.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ config {
disabled_by_default = false
}

rule "aws_instance_invalid_type" {
enabled = true
}
# rule "aws_instance_invalid_type" {
# enabled = true
# }

plugin "aws" {
enabled = true
version = "0.32.0"
source = "github.com/terraform-linters/tflint-ruleset-aws"
}
# plugin "aws" {
# enabled = true
# version = "0.32.0"
# source = "github.com/terraform-linters/tflint-ruleset-aws"
# }

plugin "terraform" {
enabled = true
version = "0.9.0"
source = "github.com/terraform-linters/tflint-ruleset-terraform"
}
# plugin "terraform" {
# enabled = true
# version = "0.9.0"
# source = "github.com/terraform-linters/tflint-ruleset-terraform"
# }
morga471 marked this conversation as resolved.
Show resolved Hide resolved
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ The module deploys Karpenter needed AWS resources, namely in IAM. It copies the

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

## Modules
Expand All @@ -39,7 +39,6 @@ The module deploys Karpenter needed AWS resources, namely in IAM. It copies the

| Name | Type |
|------|------|
| [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 |
| [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 |
Expand All @@ -56,11 +55,13 @@ The module deploys Karpenter needed AWS resources, namely in IAM. It copies the
| <a name="input_karpenter_helm_repo"></a> [karpenter\_helm\_repo](#input\_karpenter\_helm\_repo) | Helm repo for official karpenter chart | `string` | `"oci://public.ecr.aws/karpenter"` | no |
| <a name="input_karpenter_node_group_name"></a> [karpenter\_node\_group\_name](#input\_karpenter\_node\_group\_name) | The cluster node group that will host karpenter, should not be a karpenter managed node group | `string` | n/a | yes |
| <a name="input_karpenter_tag"></a> [karpenter\_tag](#input\_karpenter\_tag) | Which tag of karpenter image | `string` | `"1.1.1"` | no |
| <a name="input_namespace"></a> [namespace](#input\_namespace) | Namespace for Karpenter | `string` | `"namespace"` | no |
| <a name="input_oidc_provider_arn"></a> [oidc\_provider\_arn](#input\_oidc\_provider\_arn) | The ARN of the OIDC Provider if `enable_irsa = true` | `string` | n/a | yes |
| <a name="input_profile"></a> [profile](#input\_profile) | AWS config profile | `string` | `""` | no |
| <a name="input_region"></a> [region](#input\_region) | AWS region | `string` | n/a | yes |
| <a name="input_subnets_name"></a> [subnets\_name](#input\_subnets\_name) | Define the name of the subnets to be used by this cluster | `string` | `"*-container-*"` | no |
| <a name="input_tags"></a> [tags](#input\_tags) | AWS Tags to apply to appropriate resources | `map(string)` | `{}` | no |
| <a name="input_vpc_id"></a> [vpc\_id](#input\_vpc\_id) | The ID of the VPC where the resources will be deployed | `string` | n/a | yes |

## Outputs

Expand Down
8 changes: 4 additions & 4 deletions copy_images.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ locals {

# 224384469011.dkr.ecr.us-gov-east-1.amazonaws.com/platform-test-1/karpenter:0.37.0
# map[repository:224384469011.dkr.ecr.us-gov-east-1.amazonaws.com/platform-test-1/karpenter tag:0.37.0]

module "images" {
source = "git@github.e.it.census.gov:terraform-modules/aws-ecr-copy-images.git/?ref=tf-upgrade"

Expand All @@ -25,7 +24,8 @@ module "images" {
image_config = local.image_config
tags = {}

enable_lifecycle_policy = true
lifecycle_policy_all = true
force_delete = true
enable_lifecycle_policy = true
lifecycle_policy_all = true
force_delete = true
lifecycle_policy_keep_count = 3
}
4 changes: 4 additions & 0 deletions karpenter-resources/templates/node-pool.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ spec:
taints:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.nodePool.startupTaints }}
startupTaints:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.nodePool.requirements }}
requirements:
{{- toYaml . | nindent 8 }}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
# Shared values
name: default
clusterName: test-cluster
name: ${cluster_name}
clusterName: ${cluster_name}

# EC2NodeClass specific values
ec2NodeClass:
enabled: true
amiFamily: bottlerocket
amiFamily: ${amd_ami_family}
amiSelectorTerms:
- alias: "Bottlerocket@latest"
- alias: ${amd_ami_alias}
vpcId: ${vpc_id}
subnetSelectorTerms:
- tags:
Name: subnet-name
Name: "${subnets_name}"
securityGroupSelectorTerms:
- tags:
Name: security-group-name
karpenterRole: karpenter-role
Name: "${cluster_name}-node"
karpenterRole: ${karpenter_node_profile}
metadataOptions:
httpEndpoint: enabled
httpProtocolIPv6: enabled
Expand All @@ -27,28 +28,30 @@ ec2NodeClass:
volumeType: gp3
detailedMonitoring: true
instanceStorePolicy: RAID0

tags:
# These would be populated from var.tags in Terraform
"karpenter.sh/discovery": "${cluster_name}"

# NodePool specific values
nodePool:
name: example-cluster-node-pool
name: "${cluster_name}-worker-node-pool"
enabled: true
nodeClassRef:
name: default
name: "${cluster_name}-worker-node-class"
group: karpenter.k8s.aws
kind: EC2NodeClass
disruption:
consolidationPolicy: "WhenEmptyOrUnderutilized"
consolidateAfter: "5m"
budgets:
maxUnavailable: 1
maxUnavailablePercentage: 10
limits:
cpu: "1000"
memory: 1000Gi
weight: 1
labels: {}
taints: []
startupTaints:
- key: ebs.csi.aws.com/agent-not-ready
effect: NoExecute
requirements:
- key: "kubernetes.io/arch"
operator: "In"
Expand All @@ -59,11 +62,9 @@ nodePool:
- key: karpenter.sh/capacity-type
operator: In
values: ["on-demand", "spot"]
- key: karpenter.k8s.aws/instance-generation
operator: Gt
values: ["2"]
- key: "karpenter.k8s.aws/instance-hypervisor"
operator: In
values: ["nitro"]
expireAfter: "72h"
terminationGracePeriod: "4h"

# Extra value used in node-class.yaml template
nodeClass:
cluster_name: ${cluster_name}
Loading
Loading