diff --git a/pkg/cmd/create/environment.go b/pkg/cmd/create/environment.go index be38cfb1..20be8179 100644 --- a/pkg/cmd/create/environment.go +++ b/pkg/cmd/create/environment.go @@ -17,13 +17,14 @@ package create import ( "fmt" + "os" models "github.com/litmuschaos/litmus/chaoscenter/graphql/server/graph/model" "github.com/litmuschaos/litmusctl/pkg/apis" "github.com/litmuschaos/litmusctl/pkg/apis/environment" "github.com/litmuschaos/litmusctl/pkg/completion" - "github.com/litmuschaos/litmusctl/pkg/ops" + "github.com/litmuschaos/litmusctl/pkg/infra_ops" "github.com/litmuschaos/litmusctl/pkg/utils" "github.com/spf13/cobra" ) @@ -111,7 +112,7 @@ var environmentCmd = &cobra.Command{ } if isEnvExist { utils.Red.Println("\nChaos Environment with the given ID already exists, try with a different name") - ops.PrintExistingEnvironments(envs) + infra_ops.PrintExistingEnvironments(envs) os.Exit(1) } diff --git a/pkg/cmd/upgrade/agent.go b/pkg/cmd/upgrade/infra.go similarity index 59% rename from pkg/cmd/upgrade/agent.go rename to pkg/cmd/upgrade/infra.go index af39e9da..06fd7f22 100644 --- a/pkg/cmd/upgrade/agent.go +++ b/pkg/cmd/upgrade/infra.go @@ -19,6 +19,7 @@ import ( "context" "fmt" "os" + "strings" "github.com/litmuschaos/litmusctl/pkg/apis" "github.com/litmuschaos/litmusctl/pkg/completion" @@ -27,9 +28,9 @@ import ( ) // createCmd represents the create command -var agentCmd = &cobra.Command{ - Use: "chaos-delegate", - Short: `Upgrades the LitmusChaos agent plane.`, +var infraCmd = &cobra.Command{ + Use: "chaos-infra", + Short: `Upgrades the LitmusChaos Execution plane.`, Run: func(cmd *cobra.Command, args []string) { credentials, err := utils.GetCredentials(cmd) utils.PrintError(err) @@ -42,20 +43,24 @@ var agentCmd = &cobra.Command{ fmt.Scanln(&projectID) } - cluster_id, err := cmd.Flags().GetString("chaos-delegate-id") + infraID, err := cmd.Flags().GetString("chaos-infra-id") utils.PrintError(err) - if cluster_id == "" { - utils.White_B.Print("\nEnter the Chaos Delegate ID: ") - fmt.Scanln(&cluster_id) + if infraID == "" { + utils.White_B.Print("\nEnter the Chaos Infra ID: ") + fmt.Scanln(&infraID) } kubeconfig, err := cmd.Flags().GetString("kubeconfig") utils.PrintError(err) - output, err := apis.UpgradeInfra(context.Background(), credentials, projectID, cluster_id, kubeconfig) + output, err := apis.UpgradeInfra(context.Background(), credentials, projectID, infraID, kubeconfig) if err != nil { - utils.Red.Print("\nāŒ Failed upgrading Chaos Delegate: \n" + err.Error() + "\n") + if strings.Contains(err.Error(), "no documents in result") { + utils.Red.Println("āŒ The specified Project ID or Chaos Infrastructure ID doesn't exist.") + os.Exit(1) + } + utils.Red.Print("\nāŒ Failed upgrading Chaos Infrastructure: \n" + err.Error() + "\n") os.Exit(1) } utils.White_B.Print("\n", output) @@ -63,11 +68,11 @@ var agentCmd = &cobra.Command{ } func init() { - UpgradeCmd.AddCommand(agentCmd) - agentCmd.Flags().String("project-id", "", "Enter the project ID") - agentCmd.Flags().String("kubeconfig", "", "Enter the kubeconfig path(default: $HOME/.kube/config))") - agentCmd.Flags().String("chaos-delegate-id", "", "Enter the Chaos Delegate ID") - - agentCmd.RegisterFlagCompletionFunc("project-id", completion.ProjectIDFlagCompletion) + UpgradeCmd.AddCommand(infraCmd) + infraCmd.Flags().String("project-id", "", "Enter the project ID") + infraCmd.Flags().String("kubeconfig", "", "Enter the kubeconfig path(default: $HOME/.kube/config))") + infraCmd.Flags().String("chaos-infra-id", "", "Enter the Chaos Infrastructure ID") + infraCmd.RegisterFlagCompletionFunc("project-id", completion.ProjectIDFlagCompletion) + infraCmd.RegisterFlagCompletionFunc("chaos-infra-id", completion.ChaosInfraFlagCompletion) }