From 5cabd6fd5c7367c68e014fff0401c1275424f2f4 Mon Sep 17 00:00:00 2001 From: Jia Deng <ddjia@amazon.com> Date: Fri, 8 Sep 2023 07:48:46 -0700 Subject: [PATCH 1/2] fix cli upgrade mgmt kubeconfig flag --- cmd/eksctl-anywhere/cmd/upgradecluster.go | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/cmd/eksctl-anywhere/cmd/upgradecluster.go b/cmd/eksctl-anywhere/cmd/upgradecluster.go index 225fc4e083d0..8910b10400a2 100644 --- a/cmd/eksctl-anywhere/cmd/upgradecluster.go +++ b/cmd/eksctl-anywhere/cmd/upgradecluster.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "log" "strings" "github.com/spf13/cobra" @@ -34,10 +35,21 @@ type upgradeClusterOptions struct { var uc = &upgradeClusterOptions{} var upgradeClusterCmd = &cobra.Command{ - Use: "cluster", - Short: "Upgrade workload cluster", - Long: "This command is used to upgrade workload clusters", - PreRunE: bindFlagsToViper, + Use: "cluster", + Short: "Upgrade workload cluster", + Long: "This command is used to upgrade workload clusters", + PreRunE: func(cmd *cobra.Command, args []string) error { + if err := bindFlagsToViper(cmd, args); err != nil { + log.Fatal(err) + } + + if uc.wConfig == "" && uc.managementKubeconfig != "" { + uc.wConfig = uc.managementKubeconfig + uc.managementKubeconfig = "" + } + + return nil + }, SilenceUsage: true, RunE: func(cmd *cobra.Command, args []string) error { if uc.forceClean { From 406e8eccd8a255a4dc655c83fbd059e77a82c94d Mon Sep 17 00:00:00 2001 From: Jia Deng <ddjia@amazon.com> Date: Fri, 8 Sep 2023 14:41:09 -0700 Subject: [PATCH 2/2] move to common validation --- cmd/eksctl-anywhere/cmd/upgradecluster.go | 25 ++++++++--------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/cmd/eksctl-anywhere/cmd/upgradecluster.go b/cmd/eksctl-anywhere/cmd/upgradecluster.go index 8910b10400a2..6a1d3cdce8f7 100644 --- a/cmd/eksctl-anywhere/cmd/upgradecluster.go +++ b/cmd/eksctl-anywhere/cmd/upgradecluster.go @@ -4,7 +4,6 @@ import ( "context" "errors" "fmt" - "log" "strings" "github.com/spf13/cobra" @@ -35,21 +34,10 @@ type upgradeClusterOptions struct { var uc = &upgradeClusterOptions{} var upgradeClusterCmd = &cobra.Command{ - Use: "cluster", - Short: "Upgrade workload cluster", - Long: "This command is used to upgrade workload clusters", - PreRunE: func(cmd *cobra.Command, args []string) error { - if err := bindFlagsToViper(cmd, args); err != nil { - log.Fatal(err) - } - - if uc.wConfig == "" && uc.managementKubeconfig != "" { - uc.wConfig = uc.managementKubeconfig - uc.managementKubeconfig = "" - } - - return nil - }, + Use: "cluster", + Short: "Upgrade workload cluster", + Long: "This command is used to upgrade workload clusters", + PreRunE: bindFlagsToViper, SilenceUsage: true, RunE: func(cmd *cobra.Command, args []string) error { if uc.forceClean { @@ -226,6 +214,11 @@ func (uc *upgradeClusterOptions) commonValidations(ctx context.Context) (cluster return nil, err } + if uc.wConfig == "" && uc.managementKubeconfig != "" && clusterConfig.IsSelfManaged() { + uc.wConfig = uc.managementKubeconfig + uc.managementKubeconfig = "" + } + kubeconfigPath := getKubeconfigPath(clusterConfig.Name, uc.wConfig) if err := kubeconfig.ValidateFilename(kubeconfigPath); err != nil { return nil, err