-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert upgrader script used by in-place upgrades to a go binary to
make the project more conformant with the rest of the codebase. Signed-off-by: Rahul Ganesh <rahulgab@amazon.com>
- Loading branch information
Rahul Ganesh
committed
Mar 28, 2024
1 parent
56f3514
commit a4dbffc
Showing
25 changed files
with
1,649 additions
and
2 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 @@ | ||
1.22 |
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
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,43 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
|
||
"github.com/aws/eks-anywhere-build-tooling/tools/version-tracker/pkg/util/logger" | ||
) | ||
|
||
var rootCmd = &cobra.Command{ | ||
Use: "upgrader", | ||
Short: "EKS Anywhere InPlace upgrader", | ||
Long: `Use EKS Anywhere InPlace upgrader to upgrade your nodes InPlace`, | ||
PersistentPreRun: rootPersistentPreRun, | ||
} | ||
|
||
func init() { | ||
rootCmd.PersistentFlags().IntP("verbosity", "v", 0, "Set the log level verbosity") | ||
if err := viper.BindPFlags(rootCmd.PersistentFlags()); err != nil { | ||
log.Fatalf("failed to bind flags for root: %v", err) | ||
} | ||
} | ||
|
||
func rootPersistentPreRun(cmd *cobra.Command, args []string) { | ||
if err := initLogger(); err != nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
|
||
func initLogger() error { | ||
if err := logger.Init(viper.GetInt("verbosity")); err != nil { | ||
return fmt.Errorf("failed init zap logger in root command: %v", err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func Execute() error { | ||
return rootCmd.Execute() | ||
} |
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,36 @@ | ||
package cmd | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"log" | ||
|
||
"github.com/aws/eks-anywhere-build-tooling/projects/aws/upgrader/upgrade" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var upgradeStatusCmd = &cobra.Command{ | ||
Use: "status", | ||
Short: "Upgrade status", | ||
Long: "Use InPlace Upgrader upgrade status to get status of upgraded components on the node", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
err := upgradeStatus(cmd.Context()) | ||
if err != nil { | ||
log.Fatalf("upgrade status failed: %v", err) | ||
} | ||
return nil | ||
}, | ||
} | ||
|
||
func init() { | ||
upgradeCmd.AddCommand(upgradeStatusCmd) | ||
} | ||
|
||
func upgradeStatus(ctx context.Context) error { | ||
upg := upgrade.NewUpgrader() | ||
if err := upg.LogStatusAndCleanup(ctx); err != nil { | ||
return fmt.Errorf("fetching upgrade status on the node: %v", err) | ||
} | ||
|
||
return nil | ||
} |
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,15 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var upgradeCmd = &cobra.Command{ | ||
Use: "upgrade", | ||
Short: "Upgrade command", | ||
Long: "Use InPlace Upgrader upgrade to run different upgrade commands on the node", | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(upgradeCmd) | ||
} |
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 @@ | ||
package cmd | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"log" | ||
|
||
"github.com/aws/eks-anywhere-build-tooling/projects/aws/upgrader/upgrade" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var upgradeCniPluginsCmd = &cobra.Command{ | ||
Use: "cni-plugins", | ||
Short: "Upgrade cni-plugins", | ||
Long: "Use InPlace Upgrader upgrade cni-plugins to upgrade cni-plugins on the node", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
err := upgradeCniPlugins(cmd.Context()) | ||
if err != nil { | ||
log.Fatalf("upgrade cni-plugins failed: %v", err) | ||
} | ||
return nil | ||
}, | ||
} | ||
|
||
func init() { | ||
upgradeCmd.AddCommand(upgradeCniPluginsCmd) | ||
} | ||
|
||
func upgradeCniPlugins(ctx context.Context) error { | ||
upg := upgrade.NewUpgrader() | ||
if err := upg.CniPluginsUpgrade(ctx); err != nil { | ||
return fmt.Errorf("upgrading Cni-Plugins on the node: %v", err) | ||
} | ||
return nil | ||
} |
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,36 @@ | ||
package cmd | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"log" | ||
|
||
"github.com/aws/eks-anywhere-build-tooling/projects/aws/upgrader/upgrade" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var upgradeContainerdCmd = &cobra.Command{ | ||
Use: "containerd", | ||
Short: "Upgrade containerd", | ||
Long: "Use InPlace Upgrader upgrade containerd to upgrade containerd on the node", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
err := upgradeContainerd(cmd.Context()) | ||
if err != nil { | ||
log.Fatalf("upgrade containerd failed: %v", err) | ||
} | ||
return nil | ||
}, | ||
} | ||
|
||
func init() { | ||
upgradeCmd.AddCommand(upgradeContainerdCmd) | ||
} | ||
|
||
func upgradeContainerd(ctx context.Context) error { | ||
upg := upgrade.NewUpgrader() | ||
if err := upg.ContainerdUpgrade(ctx); err != nil { | ||
return fmt.Errorf("upgrading containerd on node: %v", err) | ||
} | ||
|
||
return nil | ||
} |
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,36 @@ | ||
package cmd | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"log" | ||
|
||
"github.com/aws/eks-anywhere-build-tooling/projects/aws/upgrader/upgrade" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var upgradeKubeletKubectlCmd = &cobra.Command{ | ||
Use: "kubelet-kubectl", | ||
Short: "Upgrade kubelet-kubectl", | ||
Long: "Use InPlace Upgrader upgrade kubelet-kubectl to upgrade kubelet and kubectl on the node", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
err := upgradeKubeletAndKubectl(cmd.Context()) | ||
if err != nil { | ||
log.Fatalf("upgrade kubelet-kubectl failed: %v", err) | ||
} | ||
return nil | ||
}, | ||
} | ||
|
||
func init() { | ||
upgradeCmd.AddCommand(upgradeKubeletKubectlCmd) | ||
} | ||
|
||
func upgradeKubeletAndKubectl(ctx context.Context) error { | ||
upg := upgrade.NewUpgrader() | ||
if err := upg.KubeletKubectlUpgrade(ctx); err != nil { | ||
return fmt.Errorf("upgrading kubelet and kubectl on node: %v", err) | ||
} | ||
|
||
return nil | ||
} |
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,74 @@ | ||
package cmd | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
"log" | ||
|
||
"github.com/aws/eks-anywhere-build-tooling/projects/aws/upgrader/upgrade" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
var upgradeNodeCmd = &cobra.Command{ | ||
Use: "node", | ||
Short: "Upgrade node", | ||
Long: "Use InPlace Upgrader upgrade node to upgrade kubeadm on the node", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
var err error | ||
|
||
nodeType := viper.GetString("type") | ||
k8sVersion := viper.GetString("k8sVersion") | ||
if k8sVersion == "" { | ||
return errors.New("k8sVersion flag has to be set for upgrade node command") | ||
} | ||
|
||
etcdVersion := viper.GetString("etcdVersion") | ||
if etcdVersion == "" { | ||
etcdVersion = "NO_UPDATE" | ||
} | ||
|
||
err = upgradeNode(cmd.Context(), nodeType, k8sVersion, etcdVersion) | ||
if err != nil { | ||
log.Fatalf("upgrade node failed: %v", err) | ||
} | ||
return nil | ||
}, | ||
} | ||
|
||
func init() { | ||
var err error | ||
|
||
upgradeCmd.AddCommand(upgradeNodeCmd) | ||
upgradeNodeCmd.Flags().String("type", "", "Node type flag") | ||
upgradeNodeCmd.Flags().String("k8sVersion", "", "kubernetes version flag") | ||
upgradeNodeCmd.Flags().String("etcdVersion", "", "etcd version flag") | ||
err = viper.BindPFlags(upgradeNodeCmd.Flags()) | ||
if err != nil { | ||
log.Fatalf("Error initializing flags: %v", err) | ||
} | ||
} | ||
|
||
func upgradeNode(ctx context.Context, nodeType, k8sVersion, etcdVersion string) error { | ||
upg := upgrade.NewUpgrader(upgrade.WithKubernetesVersion(k8sVersion), upgrade.WithEtcdVersion(etcdVersion)) | ||
|
||
switch nodeType { | ||
case "FirstCP": | ||
if err := upg.KubeAdmInFirstCP(ctx); err != nil { | ||
return fmt.Errorf("upgrading kubeadm in first controlplane node: %v", err) | ||
} | ||
case "RestCP": | ||
if err := upg.KubeAdmInRestCP(ctx); err != nil { | ||
return fmt.Errorf("upgrading kubeadm in controlplane node: %v", err) | ||
} | ||
case "Worker": | ||
if err := upg.KubeAdmInWorker(ctx); err != nil { | ||
return fmt.Errorf("upgrading kubeadm in worker node: %v", err) | ||
} | ||
default: | ||
return fmt.Errorf("invalid node type, please specify one of the three types: FirstCP, RestCP or Worker") | ||
} | ||
|
||
return nil | ||
} |
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,39 @@ | ||
module github.com/aws/eks-anywhere-build-tooling/projects/aws/upgrader | ||
|
||
go 1.22 | ||
|
||
require ( | ||
github.com/aws/eks-anywhere-build-tooling/tools/version-tracker v0.0.0-20240324014530-904f2adc3ec4 | ||
github.com/golang/mock v1.6.0 | ||
github.com/onsi/gomega v1.32.0 | ||
github.com/spf13/cobra v1.8.0 | ||
github.com/spf13/viper v1.18.2 | ||
) | ||
|
||
require ( | ||
github.com/fsnotify/fsnotify v1.7.0 // indirect | ||
github.com/go-logr/logr v1.3.0 // indirect | ||
github.com/go-logr/zapr v1.2.4 // indirect | ||
github.com/google/go-cmp v0.6.0 // indirect | ||
github.com/hashicorp/hcl v1.0.0 // indirect | ||
github.com/inconshreveable/mousetrap v1.1.0 // indirect | ||
github.com/magiconair/properties v1.8.7 // indirect | ||
github.com/mitchellh/mapstructure v1.5.0 // indirect | ||
github.com/pelletier/go-toml/v2 v2.1.0 // indirect | ||
github.com/sagikazarmark/locafero v0.4.0 // indirect | ||
github.com/sagikazarmark/slog-shim v0.1.0 // indirect | ||
github.com/sourcegraph/conc v0.3.0 // indirect | ||
github.com/spf13/afero v1.11.0 // indirect | ||
github.com/spf13/cast v1.6.0 // indirect | ||
github.com/spf13/pflag v1.0.5 // indirect | ||
github.com/subosito/gotenv v1.6.0 // indirect | ||
go.uber.org/atomic v1.10.0 // indirect | ||
go.uber.org/multierr v1.9.0 // indirect | ||
go.uber.org/zap v1.24.0 // indirect | ||
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect | ||
golang.org/x/net v0.20.0 // indirect | ||
golang.org/x/sys v0.16.0 // indirect | ||
golang.org/x/text v0.14.0 // indirect | ||
gopkg.in/ini.v1 v1.67.0 // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
) |
Oops, something went wrong.