From 9cf1a300335c2fd77ed46ed938608bb6101398af Mon Sep 17 00:00:00 2001 From: Jia Deng Date: Fri, 8 Sep 2023 07:48:46 -0700 Subject: [PATCH 1/3] fix cli upgrade mgmt kubeconfig flag --- cmd/eksctl-anywhere/cmd/upgradecluster.go | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/cmd/eksctl-anywhere/cmd/upgradecluster.go b/cmd/eksctl-anywhere/cmd/upgradecluster.go index 7ccad7bb0e97..926f25b53b98 100644 --- a/cmd/eksctl-anywhere/cmd/upgradecluster.go +++ b/cmd/eksctl-anywhere/cmd/upgradecluster.go @@ -32,10 +32,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 add01cb958aaa9682b74762abc92b73924c6406e Mon Sep 17 00:00:00 2001 From: Jia Deng Date: Fri, 8 Sep 2023 14:41:09 -0700 Subject: [PATCH 2/3] 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 926f25b53b98..bb7a3cf3c13e 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" @@ -32,21 +31,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 { @@ -208,6 +196,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 From 07142a75f507dd6a380e75f22f374c17707c252c Mon Sep 17 00:00:00 2001 From: Jia Deng <116687363+ddjjia@users.noreply.github.com> Date: Wed, 13 Sep 2023 10:22:56 -0700 Subject: [PATCH 3/3] not remove log import --- cmd/eksctl-anywhere/cmd/upgradecluster.go | 1 + 1 file changed, 1 insertion(+) diff --git a/cmd/eksctl-anywhere/cmd/upgradecluster.go b/cmd/eksctl-anywhere/cmd/upgradecluster.go index bb7a3cf3c13e..cf3bd046a351 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"