Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: punkwalker/karpenter-generate
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.0.3
Choose a base ref
...
head repository: punkwalker/karpenter-generate
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref
  • 5 commits
  • 24 files changed
  • 2 contributors

Commits on May 28, 2024

  1. Add support for BlockDeviceMapping and MetadataOption (#1)

    * feat: Add nodepool and nodeclass validtion
    * feat: Add support for BlockDeviceMapping and MetadataOption
    punkwalker authored May 28, 2024
    Copy the full SHA
    22294fb View commit details
  2. Copy the full SHA
    69981ae View commit details

Commits on May 29, 2024

  1. doc: Update README.md for release (#4)

    Updated docs for release v0.0.5
    punkwalker authored May 29, 2024
    Copy the full SHA
    086826d View commit details

Commits on Jun 13, 2024

  1. feat: Merge CRDs if specification similar (#5)

    * feat: Merge CRDs if `.spec` is similar
    punkwalker authored Jun 13, 2024
    Copy the full SHA
    142a1f2 View commit details

Commits on Jul 31, 2024

  1. doc: Update License (#6)

    Co-authored-by: pankaj.walke@mavs.uta.edu <advaitt@amazon.com>
    punkwalker and pankaj.walke@mavs.uta.edu authored Jul 31, 2024
    Copy the full SHA
    48a1e60 View commit details
12 changes: 12 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -24,6 +24,18 @@ jobs:
uses: golangci/golangci-lint-action@v6
with:
version: latest
test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- uses: actions/setup-go@v5
with:
go-version: '1.22'

- name: Test
run: make test

build:
runs-on: ubuntu-latest
4 changes: 1 addition & 3 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -27,6 +27,4 @@ linters-settings:

issues:
exclude-dirs:
- dist
# TODO: remove when linting errors in existing code have been cleared
new-from-rev: HEAD~1
- dist
2 changes: 1 addition & 1 deletion .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -35,7 +35,7 @@ brews:
name: homebrew-tap
branch: main
token: "{{ .Env.TAP_GITHUB_TOKEN }}"
folder: Formula
directory: Formula
homepage: https://github.com/punkwalker/karpenter-generate
description: A simple CLI tool to generate Karpenter CRDs from EKS Managed Node Groups
license: MIT-0
30 changes: 17 additions & 13 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
MIT No Attribution
MIT License

Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
Copyright (c) 2024 punkwalker

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -20,6 +20,12 @@ lint:
tidy:
go mod tidy

.PHONY: build install lint tidy
test:
go test ./... -coverprofile=cover.out

coverage:
go tool cover -html=cover.out

.PHONY: build install lint tidy test coverage


100 changes: 71 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
# `karpenter-generate`
This is a simple CLI tool to generate AWS Karpenter Custom Kubernetes Resources (Nodepool & EC2NodeClass) from AWS EKS Managed Nodegroup information. The generated resources can be stored in as a yaml manifest file or can be directly applied to the cluster.
# `karpenter-generate`
This is a simple CLI tool to generate AWS Karpenter Custom Kubernetes Resources (Nodepool & EC2NodeClass) from AWS EKS Managed Nodegroup information. It will merge similar CRDs if they are equal which reduce number of generated resources. The generated resources can be stored in as a yaml manifest file or can be directly applied to the cluster.

> [!WARNING]
> The tool can only generate ***v1beta*** resources for [Karpenter on AWS](https://karpenter.sh/).
> Compatible with Karpenter ***v.0.32.0*** onwards
## Example Usage
### For All Managed Nodegroups
The tool can be used without any flag and it will scan all the Managed Nodegroups in the cluster. The cluster to scan is decided based on current-context in kubeconfig
```bash
karpenter-generate
```
karpenter-generate --cluster <Cluster_Name> --karpenter-nodegroup fargate (If Karpenter is deployed on Fargate)
## OR ##
karpenter-generate --cluster <Cluster_Name> --karpenter-nodegroup <Managed Node Group Name>
```

### For specific Managed Nodegroup
To generate Karpenter Custom Resources for a specific Managed Nodegroup.
```bash
karpenter-generate --nodegroup <Managed_Nodegroup_Name>
```

### For cluster other than current-context
To specifcy other cluster than current-context
```bash
karpenter-generate --cluster <Cluster_Name> --region <Region>
karpenter-generate --cluster <Cluster_Name> --karpenter-nodegroup fargate --nodegroup <Managed_Nodegroup_Name>
```

## Prerequisites
- Configured [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html)
- Valid kubeconfig store at `$HOME/.kube/config`
- Propely Configured [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html)

## Installation
### MacOS & Linux
Use [Homebrew](https://brew.sh/) and run following command.
```bash
```
brew tap punkwalker/tap
brew install karpenter-generate
```
@@ -36,38 +37,79 @@ Downloaded archive file from release artifacts. Download the archive file from r

| OS | Arch | Download|
| ------ | ------ | ------ |
| Linux | AMD64/x86_64 | [Link](https://github.com/punkwalker/karpenter-generate/releases/download/v0.0.3/karpenter-generate_Linux_x86_64.tar.gz)|
| | ARM64| [Link](https://github.com/punkwalker/karpenter-generate/releases/download/v0.0.3/karpenter-generate_Linux_arm64.tar.gz)|
| Windows | AMD64/x86_64 | [Link](https://github.com/punkwalker/karpenter-generate/releases/download/v0.0.3/karpenter-generate_Windows_x86_64.tar.gz)|
| | ARM64| [Link](https://github.com/punkwalker/karpenter-generate/releases/download/v0.0.3/karpenter-generate_Windows_arm64.tar.gz)|
| Linux | AMD64/x86_64 | [Link](https://github.com/punkwalker/karpenter-generate/releases/download/v0.0.6/karpenter-generate_Linux_x86_64.tar.gz)|
| | ARM64| [Link](https://github.com/punkwalker/karpenter-generate/releases/download/v0.0.6/karpenter-generate_Linux_arm64.tar.gz)|
| Windows | AMD64/x86_64 | [Link](https://github.com/punkwalker/karpenter-generate/releases/download/v0.0.6/karpenter-generate_Windows_x86_64.tar.gz)|
| | ARM64| [Link](https://github.com/punkwalker/karpenter-generate/releases/download/v0.0.6/karpenter-generate_Windows_arm64.tar.gz)|

After downloading the archive, extract it and copy the binary/executable to `/usr/local/bin` for Linux. For Windows, run the `karpenter-generate.exe` from extracted folder.

## Using generated CRDs
1. Install Karpenter

Follow instructions from [Karpenter installation](https://karpenter.sh/v0.32/getting-started/getting-started-with-karpenter/#4-install-karpenter) and install Karpenter v0.32.0+. _(Recommended: Deploy Karpenter on Fargate)_

2. Generate Custom Resources using `karpenter-generate`

Run following commands to generate the resources and store in a file.
```
$ karpenter-generate --cluster <Cluster_Name> --karpenter-nodegroup fargate > karpenter-resources.yaml
```
3. [Optional] Review generated resources or make any changes if desired.
4. Create resources
Run following command to create resources using YAML file
```
$ kubectl apply -f karpenter-resources.yaml
```
5. Scale down Managed Node Groups
Once the resources are created successfully,
+ Taint Managed Node Group with following taint to evict pods:
```
Key: karpenter-migration
Value: true
Effect: NoExecute
## OR Individual node can be tainted using below command ##
$ kubectl taint node <node_name> karpenter-migration=true:NoExecute
```
+ Keep following karpenter pod logs to check if karpenter is scaling the nodes for evicted pods.
+ After all evicted pods are successfully scheduled on Karpneter nodes. Scale down Managed Node Groups to 0.
## Help
```bash
```
karpeter-generate --help

Description:
A CLI tool to generate Karpenter Custom Resources such as
Nodepools and EC2NodeClass from details of EKS Managed Nodegroup

Usage:
karpenter-generate [command]
karpenter-generate [flags]
karpenter-generate --cluster <Cluster Name> --karpenter-nodegroup <Karpenter Nodegroup Name> [flags]

Available Commands:
version Print the version and build information for karpenter-generate

Optional Flags:
--cluster string name of the EKS cluster
(default: from kubeconfig current-context)
Flags:
--cluster string name of the EKS cluster
--karpenter-nodegroup string name of the EKS managed nodegroup running Karpenter deployment or Fargate

Optiona Flags:
--nodegroup string name of the EKS managed nodegroup
(default: all the nodegroups)
--region string the region to use, overrides config/env settings
(default: from kubeconfig current-context or AWS config)
(default: all the nodegroups expectthe one running Karpenter)
--region string region of EKS cluster, overrides AWS CLI configuration/ENV values
(default: AWS CLI configuration)
--profile string use the specific profile from your credential file
(default: from kubeconfig current-context or AWS config)
(default: AWS CLI configuration)
--output string output format (yaml or json)
(default: yaml)
-h, --help help for karpenter-generate
`
```
## Contributing
25 changes: 22 additions & 3 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -5,7 +5,10 @@ import (

"github.com/spf13/cobra"

"github.com/punkwalker/karpenter-generate/pkg/aws"
"github.com/punkwalker/karpenter-generate/pkg/karpenteraws"
"github.com/punkwalker/karpenter-generate/pkg/options"
"github.com/punkwalker/karpenter-generate/pkg/printers"
)

var opts *options.Options
@@ -16,9 +19,7 @@ var rootCmd = &cobra.Command{
Long: `This is a CLI tool which can be used to generate Karpenter Custom Resources such as
Nodepools and EC2NodeClass from details of EKS Managed Nodegroup. Which will allow seamless migration to Karpenter.`,
SilenceUsage: true,
RunE: func(_ *cobra.Command, _ []string) error {
return run(opts)
},
RunE: run,
}

func init() {
@@ -36,3 +37,21 @@ func Execute() {
func AddCommand(cmd *cobra.Command) {
rootCmd.AddCommand(cmd)
}

func run(_ *cobra.Command, _ []string) error {
aws.Init(opts)
if err := opts.Parse(); err != nil {
return err
}

printer, err := printers.NewPrinter(printers.Output(opts.Output))
if err != nil {
return err
}

nodePools, nodeClasses, err := karpenteraws.Generate(opts)
if err != nil {
return err
}
return printers.Print(printer, nodePools, nodeClasses)
}
46 changes: 0 additions & 46 deletions cmd/run.go

This file was deleted.

Loading