Skip to content

Commit

Permalink
fix: check node state before udating
Browse files Browse the repository at this point in the history
Signed-off-by: minhthong582000 <[email protected]>
  • Loading branch information
minhthong582000 committed Aug 29, 2023
1 parent 8ae5073 commit 2b07b45
Show file tree
Hide file tree
Showing 10 changed files with 320 additions and 201 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*.swp
.idea

.vscode
dist/
15 changes: 7 additions & 8 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,27 @@ archives:
{{- if .Arm }}v{{ .Arm }}{{ end }}
# use zip for windows archives
format_overrides:
- goos: windows
format: zip
- goos: windows
format: zip
checksum:
name_template: 'checksums.txt'
name_template: "checksums.txt"
snapshot:
name_template: "{{ incpatch .Version }}-next"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
- "^docs:"
- "^test:"
dockers:
## standard AMIs e.g. eks m5.2xlarae types
## standard AMIs e.g. eks m5.2xlarae types
- image_templates:
- "ghcr.io/armory-io/eks-auto-updater:{{ .Version }}-linux-amd64"
use: buildx
goos: linux
build_flag_templates:
- "--platform=linux/amd64"
## This is graviton2 in AWS like mg5g.2xlarge types
## This is graviton2 in AWS like mg5g.2xlarge types
- image_templates:
- "ghcr.io/armory-io/eks-auto-updater:{{ .Version }}-linux-arm64v8"
use: buildx
Expand All @@ -62,7 +62,6 @@ docker_manifests:
image_templates:
- "ghcr.io/armory-io/eks-auto-updater:{{ .Version }}-linux-amd64"
- "ghcr.io/armory-io/eks-auto-updater:{{ .Version }}-linux-arm64v8"

# The lines beneath this are called `modelines`. See `:help modeline`
# Feel free to remove those if you don't want/use them.
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
Expand Down
51 changes: 51 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
Copyright © 2023 NAME HERE <EMAIL ADDRESS>
*/
package cmd

import (
"os"

"github.com/spf13/cobra"
)



// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "eks-auto-updater",
Short: "A brief description of your application",
Long: `A longer description that spans multiple lines and likely contains
examples and usage of using your application. For example:
Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.`,
// Uncomment the following line if your bare application
// has an action associated with it:
// Run: func(cmd *cobra.Command, args []string) { },
}

// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
err := rootCmd.Execute()
if err != nil {
os.Exit(1)
}
}

func init() {
// Here you will define your flags and configuration settings.
// Cobra supports persistent flags, which, if defined here,
// will be global for your application.

// rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.eks-auto-updater.yaml)")

// Cobra also supports local flags, which will only run
// when this action is called directly.
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}


63 changes: 63 additions & 0 deletions cmd/run.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package cmd

import (
"github.com/armory-io/eks-auto-updater/internal/updater"
"github.com/armory-io/eks-auto-updater/pkg/aws"

"github.com/spf13/cobra"
)

// runCmd represents the run command
var runCmd = &cobra.Command{
Use: "run",
Short: "A brief description of your command",
Long: `A longer description that spans multiple lines and likely contains examples
and usage of using your command. For example:
Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.`,
RunE: func(cmd *cobra.Command, args []string) error {
ctx := cmd.Context()
region := cmd.Flag("region").Value.String()
roleArn := cmd.Flag("role-arn").Value.String()
clusterName := cmd.Flag("cluster-name").Value.String()
nodegroupName := cmd.Flag("nodegroup-name").Value.String()
waitForNodeUpdates, _ := cmd.Flags().GetInt("nodegroup-wait-time")

awsClient, err := aws.GetEksClient(ctx, region, roleArn)
if err != nil {
return err
}

updater := updater.NewEKSUpdater(awsClient)
err = updater.UpdateClusterNodeGroup(ctx, &clusterName, &nodegroupName, waitForNodeUpdates)
if err != nil {
return err
}

return nil
},
}

func init() {
rootCmd.AddCommand(runCmd)

// Region
runCmd.Flags().String("region", "us-west-2", "AWS Region to use")
runCmd.MarkFlagRequired("region")

// Cluster Name
runCmd.Flags().String("cluster-name", "", "Name of the EKS cluster to update")
runCmd.MarkFlagRequired("cluster-name")

// Nodegroup Name
runCmd.Flags().String("nodegroup-name", "", "Name of the EKS nodegroup to update")
runCmd.MarkFlagRequired("nodegroup-name")

// Role ARN
runCmd.Flags().String("role-arn", "", "Role ARN to assume")

// Nodegroup Wait Time
runCmd.Flags().Int("nodegroup-wait-time", 120, "Time in minutes to wait for node group update to complete. Defaults to 120 minutes")
}
191 changes: 0 additions & 191 deletions eks-updater.go

This file was deleted.

5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module eks-updater
module github.com/armory-io/eks-auto-updater

go 1.20

Expand All @@ -9,6 +9,7 @@ require (
github.com/aws/aws-sdk-go-v2/service/eks v1.27.7
github.com/aws/aws-sdk-go-v2/service/sts v1.18.6
github.com/hashicorp/go-version v1.6.0
github.com/spf13/cobra v1.7.0
)

require (
Expand All @@ -20,5 +21,7 @@ require (
github.com/aws/aws-sdk-go-v2/service/sso v1.12.5 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.14.5 // indirect
github.com/aws/smithy-go v1.13.5 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
)
Loading

0 comments on commit 2b07b45

Please sign in to comment.