-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 0fa90a6
Showing
20 changed files
with
1,591 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: release | ||
|
||
on: | ||
push: | ||
tags: | ||
- '*' | ||
|
||
permissions: | ||
contents: write | ||
|
||
jobs: | ||
goreleaser: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- uses: actions/setup-go@v5 | ||
|
||
- name: Run GoReleaser | ||
uses: goreleaser/goreleaser-action@v5 | ||
with: | ||
version: latest | ||
args: release --clean | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# If you prefer the allow list template instead of the deny list, see community template: | ||
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore | ||
# | ||
# Binaries for programs and plugins | ||
*.exe | ||
*.exe~ | ||
*.dll | ||
*.so | ||
*.dylib | ||
|
||
# Test binary, built with `go test -c` | ||
*.test | ||
|
||
# Output of the go coverage tool, specifically when used with LiteIDE | ||
*.out | ||
|
||
# Dependency directories (remove the comment below to include it) | ||
# vendor/ | ||
|
||
# Go workspace file | ||
go.work | ||
|
||
# cluster-config | ||
cluster-config.yml | ||
dist/ | ||
|
||
# local build artifacts | ||
karpenter-generate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
version: 1 | ||
|
||
before: | ||
hooks: | ||
- go mod tidy | ||
|
||
builds: | ||
- env: | ||
- CGO_ENABLED=0 | ||
goos: | ||
- linux | ||
- windows | ||
- darwin | ||
|
||
archives: | ||
- format: tar.gz | ||
# this name template makes the OS and Arch compatible with the results of `uname`. | ||
name_template: >- | ||
{{ .ProjectName }}_ | ||
{{- title .Os }}_ | ||
{{- if eq .Arch "amd64" }}x86_64 | ||
{{- else if eq .Arch "386" }}i386 | ||
{{- else }}{{ .Arch }}{{ end }} | ||
{{- if .Arm }}v{{ .Arm }}{{ end }} | ||
# use zip for windows archives | ||
format_overrides: | ||
- goos: windows | ||
format: zip | ||
|
||
changelog: | ||
sort: asc | ||
filters: | ||
exclude: | ||
- "^docs:" | ||
- "^test:" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
MIT No Attribution | ||
|
||
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
|
||
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. | ||
|
||
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. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# `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. | ||
|
||
## 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 | ||
``` | ||
### 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> | ||
``` | ||
|
||
## Prerequisites | ||
- Configured [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html) | ||
- Valid kubeconfig store at `$HOME/.kube/config` | ||
|
||
## Installation | ||
To install the tool, follow these steps: | ||
|
||
As of now the tool can only be downloaded as a archive file from release artifacts. Download the archive file from relase page according to the Arch of your machine | ||
|
||
| OS | Arch | Download| | ||
| ------ | ------ | ------ | | ||
| MacOS | AMD64/x86_64 | [Link](https://github.com/punkwalker/karpenter-generate/releases/download/v0.0.1/karpenter-generate_Darwin_x86_64.tar.gz)| | ||
| | ARM64| [Link](https://github.com/punkwalker/karpenter-generate/releases/download/v0.0.1/karpenter-generate_Darwin_arm64.tar.gz)| | ||
| Linux | AMD64/x86_64 | [Link](https://github.com/punkwalker/karpenter-generate/releases/download/v0.0.1/karpenter-generate_Linux_x86_64.tar.gz)| | ||
| | ARM64| [Link](https://github.com/punkwalker/karpenter-generate/releases/download/v0.0.1/karpenter-generate_Linux_arm64.tar.gz)| | ||
| Windows | AMD64/x86_64 | [Link](https://github.com/punkwalker/karpenter-generate/releases/download/v0.0.1/karpenter-generate_Windows_x86_64.tar.gz)| | ||
| | ARM64| [Link](https://github.com/punkwalker/karpenter-generate/releases/download/v0.0.1/karpenter-generate_Windows_arm64.tar.gz)| | ||
|
||
After downloading the archive, extract it and run the binary/executable of the tool. | ||
|
||
## 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 [flags] | ||
|
||
Optional Flags: | ||
--cluster string name of the EKS cluster | ||
(default: from kubeconfig current-context) | ||
--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) | ||
--profile string use the specific profile from your credential file | ||
(default: from kubeconfig current-context or AWS config) | ||
-h, --help help for karpenter-generate | ||
``` | ||
|
||
## Contributing | ||
Contributions are welcome! If you encounter any issues or have suggestions for improvements, please follow these steps: | ||
|
||
1. Fork the repository. | ||
2. Create a new branch for your feature or bug fix. | ||
3. Make your changes and commit them with descriptive commit messages. | ||
4. Push your changes to your forked repository. | ||
5. Submit a pull request to the main repository. | ||
|
||
Please ensure that your code adheres to the project's coding standards and includes appropriate tests. | ||
|
||
## License | ||
This tool is licensed under the License Name License. See the `LICENSE.md` file for more information. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package cmd | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/punkwalker/karpenter-generate/pkg/options" | ||
) | ||
|
||
var opts *options.Options | ||
|
||
var rootCmd = &cobra.Command{ | ||
Use: "karpenter-generate", | ||
Short: "Tool to generate Karpenter CRDs from EKS Managed Nodegroups", | ||
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(cmd *cobra.Command, args []string) error { | ||
return run(opts) | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.CompletionOptions.HiddenDefaultCmd = true | ||
opts = options.New(rootCmd) | ||
} | ||
|
||
func Execute() { | ||
err := rootCmd.Execute() | ||
if err != nil { | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
func AddCommand(cmd *cobra.Command) { | ||
rootCmd.AddCommand(cmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/aws/aws-sdk-go-v2/service/eks/types" | ||
|
||
"github.com/punkwalker/karpenter-generate/pkg/aws" | ||
"github.com/punkwalker/karpenter-generate/pkg/karpenter" | ||
"github.com/punkwalker/karpenter-generate/pkg/options" | ||
) | ||
|
||
func run(opts *options.Options) error { | ||
aws.Init(opts) | ||
opts.Parse() | ||
var nodeGroups []types.Nodegroup | ||
|
||
eksClient := aws.NewEKSClient() | ||
if opts.NodegroupName != "" { | ||
nodeGroup, err := eksClient.DescribeNodegroup(opts.ClusterName, opts.NodegroupName) | ||
if err != nil { | ||
return aws.FormatErrorAsMessageOnly(err) | ||
} | ||
nodeGroups = append(nodeGroups, *nodeGroup) | ||
return karpenter.Generate(&nodeGroups) | ||
} | ||
|
||
nodeGroups, err := eksClient.GetAllNodeGroups(opts) | ||
if err != nil { | ||
return aws.FormatErrorAsMessageOnly(err) | ||
} | ||
|
||
if len(nodeGroups) == 0 { | ||
return fmt.Errorf("no nodegroups found") | ||
} | ||
|
||
return karpenter.Generate(&nodeGroups) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
module github.com/punkwalker/karpenter-generate | ||
|
||
go 1.22.0 | ||
|
||
toolchain go1.22.2 | ||
|
||
require ( | ||
github.com/aws/aws-sdk-go-v2 v1.26.1 | ||
github.com/aws/aws-sdk-go-v2/config v1.27.11 | ||
github.com/aws/aws-sdk-go-v2/service/autoscaling v1.40.5 | ||
github.com/aws/aws-sdk-go-v2/service/ec2 v1.160.0 | ||
github.com/aws/aws-sdk-go-v2/service/eks v1.42.1 | ||
github.com/aws/karpenter-provider-aws v0.36.1 | ||
github.com/aws/smithy-go v1.20.2 | ||
github.com/spf13/cobra v1.8.0 | ||
k8s.io/api v0.30.0 | ||
k8s.io/apimachinery v0.30.0 | ||
k8s.io/cli-runtime v0.30.0 | ||
k8s.io/client-go v0.30.0 | ||
sigs.k8s.io/karpenter v0.36.1 | ||
) | ||
|
||
require ( | ||
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect | ||
github.com/aws/aws-sdk-go v1.51.16 // indirect | ||
github.com/aws/aws-sdk-go-v2/credentials v1.17.11 // indirect | ||
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.1 // indirect | ||
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.5 // indirect | ||
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.5 // indirect | ||
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0 // indirect | ||
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.2 // indirect | ||
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.7 // indirect | ||
github.com/aws/aws-sdk-go-v2/service/sso v1.20.5 // indirect | ||
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.23.4 // indirect | ||
github.com/aws/aws-sdk-go-v2/service/sts v1.28.6 // indirect | ||
github.com/davecgh/go-spew v1.1.1 // indirect | ||
github.com/emicklei/go-restful/v3 v3.11.0 // indirect | ||
github.com/evanphx/json-patch v5.7.0+incompatible // indirect | ||
github.com/go-errors/errors v1.4.2 // indirect | ||
github.com/go-logr/logr v1.4.1 // indirect | ||
github.com/go-openapi/jsonpointer v0.20.0 // indirect | ||
github.com/go-openapi/jsonreference v0.20.2 // indirect | ||
github.com/go-openapi/swag v0.22.4 // indirect | ||
github.com/gogo/protobuf v1.3.2 // indirect | ||
github.com/golang/protobuf v1.5.4 // indirect | ||
github.com/google/btree v1.0.1 // indirect | ||
github.com/google/gnostic-models v0.6.8 // indirect | ||
github.com/google/go-cmp v0.6.0 // indirect | ||
github.com/google/gofuzz v1.2.0 // indirect | ||
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect | ||
github.com/google/uuid v1.3.1 // indirect | ||
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7 // indirect | ||
github.com/imdario/mergo v0.3.16 // indirect | ||
github.com/inconshreveable/mousetrap v1.1.0 // indirect | ||
github.com/jmespath/go-jmespath v0.4.0 // indirect | ||
github.com/josharian/intern v1.0.0 // indirect | ||
github.com/json-iterator/go v1.1.12 // indirect | ||
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de // indirect | ||
github.com/mailru/easyjson v0.7.7 // indirect | ||
github.com/mitchellh/hashstructure/v2 v2.0.2 // indirect | ||
github.com/moby/term v0.0.0-20221205130635-1aeaba878587 // indirect | ||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect | ||
github.com/modern-go/reflect2 v1.0.2 // indirect | ||
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect | ||
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect | ||
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect | ||
github.com/pkg/errors v0.9.1 // indirect | ||
github.com/robfig/cron/v3 v3.0.1 // indirect | ||
github.com/samber/lo v1.39.0 // indirect | ||
github.com/spf13/pflag v1.0.5 // indirect | ||
github.com/xlab/treeprint v1.2.0 // indirect | ||
go.starlark.net v0.0.0-20230525235612-a134d8f9ddca // indirect | ||
go.uber.org/multierr v1.11.0 // indirect | ||
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect | ||
golang.org/x/net v0.23.0 // indirect | ||
golang.org/x/oauth2 v0.16.0 // indirect | ||
golang.org/x/sync v0.7.0 // indirect | ||
golang.org/x/sys v0.18.0 // indirect | ||
golang.org/x/term v0.18.0 // indirect | ||
golang.org/x/text v0.14.0 // indirect | ||
golang.org/x/time v0.5.0 // indirect | ||
google.golang.org/appengine v1.6.8 // indirect | ||
google.golang.org/protobuf v1.33.0 // indirect | ||
gopkg.in/inf.v0 v0.9.1 // indirect | ||
gopkg.in/yaml.v2 v2.4.0 // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
k8s.io/klog/v2 v2.120.1 // indirect | ||
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 // indirect | ||
k8s.io/utils v0.0.0-20240102154912-e7106e64919e // indirect | ||
knative.dev/pkg v0.0.0-20231010144348-ca8c009405dd // indirect | ||
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect | ||
sigs.k8s.io/kustomize/api v0.13.5-0.20230601165947-6ce0bf390ce3 // indirect | ||
sigs.k8s.io/kustomize/kyaml v0.14.3-0.20230601165947-6ce0bf390ce3 // indirect | ||
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect | ||
sigs.k8s.io/yaml v1.4.0 // indirect | ||
) |
Oops, something went wrong.