From 14452c2ebe4f1e9de4b0620b956012e4348c1eee Mon Sep 17 00:00:00 2001 From: Vr00mm Date: Fri, 25 Aug 2023 22:43:48 +0200 Subject: [PATCH 1/7] Add completion for parameters values Signed-off-by: Vr00mm --- pkg/cmd/connect/infra.go | 9 ++- pkg/cmd/create/environment.go | 8 +- pkg/cmd/create/experiment.go | 10 ++- pkg/cmd/delete/experiment.go | 8 +- pkg/cmd/describe/experiment.go | 14 +++- pkg/cmd/disconnect/infra.go | 6 +- pkg/cmd/get/experimentruns.go | 8 +- pkg/cmd/get/experiments.go | 9 ++- pkg/cmd/get/infra.go | 10 ++- pkg/cmd/get/projects.go | 3 + pkg/cmd/run/experiment.go | 9 ++- pkg/cmd/save/experiment.go | 11 ++- pkg/cmd/upgrade/agent.go | 4 + pkg/completion/completion.go | 143 +++++++++++++++++++++++++++++++++ 14 files changed, 233 insertions(+), 19 deletions(-) create mode 100644 pkg/completion/completion.go diff --git a/pkg/cmd/connect/infra.go b/pkg/cmd/connect/infra.go index 0eae0bb5..f2ff1e2f 100644 --- a/pkg/cmd/connect/infra.go +++ b/pkg/cmd/connect/infra.go @@ -17,9 +17,11 @@ package connect import ( "fmt" + "os" + "github.com/litmuschaos/litmusctl/pkg/apis/environment" "github.com/litmuschaos/litmusctl/pkg/apis/infrastructure" - "os" + "github.com/litmuschaos/litmusctl/pkg/completion" "github.com/litmuschaos/litmusctl/pkg/apis" "github.com/litmuschaos/litmusctl/pkg/k8s" @@ -283,4 +285,9 @@ func init() { infraCmd.Flags().Bool("skip-ssl", false, "Set whether Chaos infra will skip ssl/tls check (can be used for self-signed certs, if cert is not provided in portal)") infraCmd.Flags().Bool("ns-exists", false, "Set the --ns-exists=false if the namespace mentioned in the --namespace flag is not existed else set it to --ns-exists=true | Note: Always set the boolean flag as --ns-exists=Boolean") infraCmd.Flags().Bool("sa-exists", false, "Set the --sa-exists=false if the service-account mentioned in the --service-account flag is not existed else set it to --sa-exists=true | Note: Always set the boolean flag as --sa-exists=Boolean\"\n") + + infraCmd.RegisterFlagCompletionFunc("project-id", completion.ProjectIDFlagCompletion) + infraCmd.RegisterFlagCompletionFunc("installation-mode", completion.InstallModeTypeFlagCompletion) + infraCmd.RegisterFlagCompletionFunc("platform-name", completion.PlatformNameFlagCompletion) + infraCmd.RegisterFlagCompletionFunc("chaos-infra-type", completion.ChaosInfraTypeFlagCompletion) } diff --git a/pkg/cmd/create/environment.go b/pkg/cmd/create/environment.go index 23e4aad2..be38cfb1 100644 --- a/pkg/cmd/create/environment.go +++ b/pkg/cmd/create/environment.go @@ -17,13 +17,15 @@ 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/utils" "github.com/spf13/cobra" - "os" ) // environmentCmd represents the Chaos infra command @@ -155,4 +157,8 @@ func init() { environmentCmd.Flags().String("type", "NON_PROD", "Set the installation mode for the kind of Chaos infra | Supported=cluster/namespace") environmentCmd.Flags().String("name", "", "Set the Chaos infra name") environmentCmd.Flags().String("description", "---", "Set the Chaos infra description") + + environmentCmd.RegisterFlagCompletionFunc("project-id", completion.ProjectIDFlagCompletion) + environmentCmd.RegisterFlagCompletionFunc("type", completion.InstallModeTypeFlagCompletion) + } diff --git a/pkg/cmd/create/experiment.go b/pkg/cmd/create/experiment.go index 8295b706..81b3c6f6 100644 --- a/pkg/cmd/create/experiment.go +++ b/pkg/cmd/create/experiment.go @@ -17,12 +17,14 @@ package create import ( "fmt" + "os" + "strings" + models "github.com/litmuschaos/litmus/chaoscenter/graphql/server/graph/model" "github.com/litmuschaos/litmusctl/pkg/apis" "github.com/litmuschaos/litmusctl/pkg/apis/experiment" + "github.com/litmuschaos/litmusctl/pkg/completion" "github.com/litmuschaos/litmusctl/pkg/utils" - "os" - "strings" "github.com/spf13/cobra" ) @@ -145,4 +147,8 @@ func init() { experimentCmd.Flags().String("chaos-infra-id", "", "Set the chaos-infra-id to create Chaos Experiment for the particular Chaos Infrastructure. To see the Chaos Infrastructures, apply litmusctl get chaos-infra") experimentCmd.Flags().StringP("file", "f", "", "The manifest file for the Chaos Experiment") experimentCmd.Flags().StringP("description", "d", "", "The Description for the Chaos Experiment") + + experimentCmd.RegisterFlagCompletionFunc("project-id", completion.ProjectIDFlagCompletion) + experimentCmd.RegisterFlagCompletionFunc("chaos-infra-id", completion.ChaosInfraFlagCompletion) + } diff --git a/pkg/cmd/delete/experiment.go b/pkg/cmd/delete/experiment.go index 2dd07131..2e70601b 100644 --- a/pkg/cmd/delete/experiment.go +++ b/pkg/cmd/delete/experiment.go @@ -17,9 +17,11 @@ package delete import ( "fmt" - "github.com/litmuschaos/litmusctl/pkg/apis/experiment" "os" + "github.com/litmuschaos/litmusctl/pkg/apis/experiment" + "github.com/litmuschaos/litmusctl/pkg/completion" + "github.com/litmuschaos/litmusctl/pkg/apis" "github.com/litmuschaos/litmusctl/pkg/utils" @@ -36,7 +38,7 @@ var experimentCmd = &cobra.Command{ Note: The default location of the config file is $HOME/.litmusconfig, and can be overridden by a --config flag `, - Args: cobra.ExactArgs(1), + ValidArgsFunction: completion.ExperimentIDCompletion, Run: func(cmd *cobra.Command, args []string) { // Fetch user credentials @@ -109,4 +111,6 @@ func init() { DeleteCmd.AddCommand(experimentCmd) experimentCmd.Flags().String("project-id", "", "Set the project-id to create Chaos Experiment for the particular project. To see the projects, apply litmusctl get projects") + experimentCmd.RegisterFlagCompletionFunc("project-id", completion.ProjectIDFlagCompletion) + } diff --git a/pkg/cmd/describe/experiment.go b/pkg/cmd/describe/experiment.go index 9b52ec0b..0ce8b78d 100644 --- a/pkg/cmd/describe/experiment.go +++ b/pkg/cmd/describe/experiment.go @@ -17,10 +17,12 @@ package describe import ( "fmt" - "github.com/litmuschaos/litmusctl/pkg/apis/experiment" "os" "strings" + "github.com/litmuschaos/litmusctl/pkg/apis/experiment" + "github.com/litmuschaos/litmusctl/pkg/completion" + "github.com/litmuschaos/litmus/chaoscenter/graphql/server/graph/model" "github.com/litmuschaos/litmusctl/pkg/utils" "github.com/spf13/cobra" @@ -29,9 +31,11 @@ import ( // experimentCmd represents the Chaos Experiment command var experimentCmd = &cobra.Command{ - Use: "chaos-experiment", - Short: "Describe a Chaos Experiment within the project", - Long: `Describe a Chaos Experiment within the project`, + Use: "chaos-experiment", + Short: "Describe a Chaos Experiment within the project", + Long: `Describe a Chaos Experiment within the project`, + ValidArgsFunction: completion.ExperimentIDCompletion, + Run: func(cmd *cobra.Command, args []string) { credentials, err := utils.GetCredentials(cmd) utils.PrintError(err) @@ -96,4 +100,6 @@ func init() { DescribeCmd.AddCommand(experimentCmd) experimentCmd.Flags().String("project-id", "", "Set the project-id to list Chaos Experiments from the particular project. To see the projects, apply litmusctl get projects") + experimentCmd.RegisterFlagCompletionFunc("project-id", completion.ProjectIDFlagCompletion) + } diff --git a/pkg/cmd/disconnect/infra.go b/pkg/cmd/disconnect/infra.go index e6ee9eba..966b5612 100644 --- a/pkg/cmd/disconnect/infra.go +++ b/pkg/cmd/disconnect/infra.go @@ -17,10 +17,12 @@ package disconnect import ( "fmt" - "github.com/litmuschaos/litmusctl/pkg/apis/infrastructure" "os" "strings" + "github.com/litmuschaos/litmusctl/pkg/apis/infrastructure" + "github.com/litmuschaos/litmusctl/pkg/completion" + "github.com/litmuschaos/litmusctl/pkg/apis" "github.com/litmuschaos/litmusctl/pkg/utils" @@ -114,4 +116,6 @@ func init() { DisconnectCmd.AddCommand(infraCmd) infraCmd.Flags().String("project-id", "", "Set the project-id to disconnect Chaos Infrastructure for the particular project. To see the projects, apply litmusctl get projects") + infraCmd.RegisterFlagCompletionFunc("project-id", completion.ProjectIDFlagCompletion) + } diff --git a/pkg/cmd/get/experimentruns.go b/pkg/cmd/get/experimentruns.go index 56b7e592..d01f2d6b 100644 --- a/pkg/cmd/get/experimentruns.go +++ b/pkg/cmd/get/experimentruns.go @@ -17,13 +17,15 @@ package get import ( "fmt" - "github.com/litmuschaos/litmusctl/pkg/apis/experiment" "os" "strconv" "strings" "text/tabwriter" "time" + "github.com/litmuschaos/litmusctl/pkg/apis/experiment" + "github.com/litmuschaos/litmusctl/pkg/completion" + "github.com/litmuschaos/litmus/chaoscenter/graphql/server/graph/model" "github.com/litmuschaos/litmusctl/pkg/utils" "github.com/spf13/cobra" @@ -120,4 +122,8 @@ func init() { experimentRunsCmd.Flags().BoolP("all", "A", false, "Set to true to display all Chaos Experiments runs") experimentRunsCmd.Flags().StringP("output", "o", "", "Output format. One of:\njson|yaml") + + experimentRunsCmd.RegisterFlagCompletionFunc("project-id", completion.ProjectIDFlagCompletion) + experimentRunsCmd.RegisterFlagCompletionFunc("output", completion.OutputFlagCompletion) + } diff --git a/pkg/cmd/get/experiments.go b/pkg/cmd/get/experiments.go index c2a4848a..f774d747 100644 --- a/pkg/cmd/get/experiments.go +++ b/pkg/cmd/get/experiments.go @@ -17,12 +17,14 @@ package get import ( "fmt" - "github.com/litmuschaos/litmusctl/pkg/apis/experiment" "os" "strings" "text/tabwriter" "time" + "github.com/litmuschaos/litmusctl/pkg/apis/experiment" + "github.com/litmuschaos/litmusctl/pkg/completion" + "github.com/gorhill/cronexpr" "github.com/litmuschaos/litmus/chaoscenter/graphql/server/graph/model" "github.com/litmuschaos/litmusctl/pkg/utils" @@ -121,4 +123,9 @@ func init() { experimentsCmd.Flags().StringP("chaos-infra", "A", "", "Set the Chaos Infrastructure name to display all Chaos experiments targeted towards that particular Chaos Infrastructure.") experimentsCmd.Flags().StringP("output", "o", "", "Output format. One of:\njson|yaml") + + experimentsCmd.RegisterFlagCompletionFunc("project-id", completion.ProjectIDFlagCompletion) + experimentsCmd.RegisterFlagCompletionFunc("chaos-infra", completion.ChaosInfraFlagCompletion) + experimentsCmd.RegisterFlagCompletionFunc("output", completion.OutputFlagCompletion) + } diff --git a/pkg/cmd/get/infra.go b/pkg/cmd/get/infra.go index 2d713489..6092144b 100644 --- a/pkg/cmd/get/infra.go +++ b/pkg/cmd/get/infra.go @@ -17,12 +17,14 @@ package get import ( "fmt" - models "github.com/litmuschaos/litmus/chaoscenter/graphql/server/graph/model" - "github.com/litmuschaos/litmusctl/pkg/apis/infrastructure" "os" "strings" "text/tabwriter" + models "github.com/litmuschaos/litmus/chaoscenter/graphql/server/graph/model" + "github.com/litmuschaos/litmusctl/pkg/apis/infrastructure" + "github.com/litmuschaos/litmusctl/pkg/completion" + "github.com/litmuschaos/litmusctl/pkg/utils" "github.com/spf13/cobra" ) @@ -94,4 +96,8 @@ func init() { InfraCmd.Flags().String("project-id", "", "Set the project-id. To retrieve projects. Apply `litmusctl get projects`") InfraCmd.Flags().StringP("output", "o", "", "Output format. One of:\njson|yaml") + + InfraCmd.RegisterFlagCompletionFunc("project-id", completion.ProjectIDFlagCompletion) + InfraCmd.RegisterFlagCompletionFunc("output", completion.OutputFlagCompletion) + } diff --git a/pkg/cmd/get/projects.go b/pkg/cmd/get/projects.go index 09ef073b..99326d22 100644 --- a/pkg/cmd/get/projects.go +++ b/pkg/cmd/get/projects.go @@ -21,6 +21,7 @@ import ( "time" "github.com/litmuschaos/litmusctl/pkg/apis" + "github.com/litmuschaos/litmusctl/pkg/completion" "github.com/litmuschaos/litmusctl/pkg/utils" "github.com/spf13/cobra" ) @@ -66,4 +67,6 @@ func init() { GetCmd.AddCommand(projectsCmd) projectsCmd.Flags().StringP("output", "o", "", "Output format. One of:\njson|yaml") + projectsCmd.RegisterFlagCompletionFunc("output", completion.OutputFlagCompletion) + } diff --git a/pkg/cmd/run/experiment.go b/pkg/cmd/run/experiment.go index 179e5d8e..d17ed794 100644 --- a/pkg/cmd/run/experiment.go +++ b/pkg/cmd/run/experiment.go @@ -17,12 +17,14 @@ package run import ( "fmt" + "os" + "strings" + "github.com/litmuschaos/litmusctl/pkg/apis" "github.com/litmuschaos/litmusctl/pkg/apis/experiment" + "github.com/litmuschaos/litmusctl/pkg/completion" "github.com/litmuschaos/litmusctl/pkg/utils" "github.com/spf13/cobra" - "os" - "strings" ) // experimentCmd represents the project command @@ -118,4 +120,7 @@ func init() { experimentCmd.Flags().String("project-id", "", "Set the project-id to create Chaos Experiment for the particular project. To see the projects, apply litmusctl get projects") experimentCmd.Flags().String("experiment-id", "", "Set the environment-id to create Chaos Experiment for the particular Chaos Infrastructure. To see the Chaos Infrastructures, apply litmusctl get chaos-infra") + + experimentCmd.RegisterFlagCompletionFunc("project-id", completion.ProjectIDFlagCompletion) + experimentCmd.RegisterFlagCompletionFunc("experiment-id", completion.ExperimentIDCompletion) } diff --git a/pkg/cmd/save/experiment.go b/pkg/cmd/save/experiment.go index 8ce9e248..3bad91e0 100644 --- a/pkg/cmd/save/experiment.go +++ b/pkg/cmd/save/experiment.go @@ -17,10 +17,13 @@ package save import ( "fmt" - models "github.com/litmuschaos/litmus/chaoscenter/graphql/server/graph/model" - "github.com/litmuschaos/litmusctl/pkg/apis/experiment" "os" "strings" + + models "github.com/litmuschaos/litmus/chaoscenter/graphql/server/graph/model" + "github.com/litmuschaos/litmusctl/pkg/apis/experiment" + "github.com/litmuschaos/litmusctl/pkg/completion" + //"time" //"github.com/gorhill/cronexpr" @@ -146,4 +149,8 @@ func init() { experimentCmd.Flags().String("chaos-infra-id", "", "Set the chaos-infra-id to create Chaos Experiment for the particular Chaos Infrastructure. To see the Chaos Infrastructures, apply litmusctl get chaos-infra") experimentCmd.Flags().StringP("file", "f", "", "The manifest file for the Chaos Experiment") experimentCmd.Flags().StringP("description", "d", "", "The Description for the Chaos Experiment") + + experimentCmd.RegisterFlagCompletionFunc("project-id", completion.ProjectIDFlagCompletion) + experimentCmd.RegisterFlagCompletionFunc("chaos-infra-id", completion.ChaosInfraFlagCompletion) + } diff --git a/pkg/cmd/upgrade/agent.go b/pkg/cmd/upgrade/agent.go index 7de68ca7..af39e9da 100644 --- a/pkg/cmd/upgrade/agent.go +++ b/pkg/cmd/upgrade/agent.go @@ -21,6 +21,7 @@ import ( "os" "github.com/litmuschaos/litmusctl/pkg/apis" + "github.com/litmuschaos/litmusctl/pkg/completion" "github.com/litmuschaos/litmusctl/pkg/utils" "github.com/spf13/cobra" ) @@ -66,4 +67,7 @@ func init() { 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) + } diff --git a/pkg/completion/completion.go b/pkg/completion/completion.go new file mode 100644 index 00000000..2e3021e8 --- /dev/null +++ b/pkg/completion/completion.go @@ -0,0 +1,143 @@ +package completion + +import ( + "strings" + + "github.com/litmuschaos/litmus/chaoscenter/graphql/server/graph/model" + "github.com/litmuschaos/litmusctl/pkg/apis" + "github.com/litmuschaos/litmusctl/pkg/apis/experiment" + "github.com/litmuschaos/litmusctl/pkg/apis/infrastructure" + "github.com/litmuschaos/litmusctl/pkg/utils" + "github.com/spf13/cobra" +) + +func ProjectIDFlagCompletion(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + credentials, err := utils.GetCredentials(cmd) + if err != nil { + return nil, cobra.ShellCompDirectiveError + } + + projects, err := apis.ListProject(credentials) + if err != nil { + return nil, cobra.ShellCompDirectiveError + } + + completions := make([]string, 0) + descriptions := make(map[string]string) + + for _, project := range projects.Data { + if strings.HasPrefix(project.ID, toComplete) { + completions = append(completions, project.ID) + descriptions[project.ID] = project.Name + } + } + + var result []string + for _, c := range completions { + result = append(result, c+"\t"+descriptions[c]) + } + + return result, cobra.ShellCompDirectiveNoFileComp +} + +func ExperimentIDCompletion(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + + if len(args) > 0 { + return nil, cobra.ShellCompDirectiveDefault + } + + credentials, err := utils.GetCredentials(cmd) + if err != nil { + // Handle the error here if needed + return nil, cobra.ShellCompDirectiveError + } + + pid := cmd.Flag("project-id").Value.String() + if pid == "" { + return nil, cobra.ShellCompDirectiveError + } + + var listExperimentRequest model.ListExperimentRequest + listExperimentRequest.Filter = &model.ExperimentFilterInput{} + + experiments, err := experiment.GetExperimentList(pid, listExperimentRequest, credentials) + if err != nil { + // Handle the error here if needed + return nil, cobra.ShellCompDirectiveError + } + + completions := make([]string, 0) + descriptions := make(map[string]string) + + for _, experiment := range experiments.Data.ListExperimentDetails.Experiments { + if strings.HasPrefix(experiment.ExperimentID, toComplete) { + completions = append(completions, experiment.ExperimentID) + descriptions[experiment.ExperimentID] = experiment.Infra.Name + "/" + experiment.Name + } + } + + var result []string + for _, c := range completions { + result = append(result, c+"\t"+descriptions[c]) + } + + return result, cobra.ShellCompDirectiveNoFileComp +} + +func ChaosInfraFlagCompletion(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + credentials, err := utils.GetCredentials(cmd) + if err != nil { + return nil, cobra.ShellCompDirectiveError + } + + pid := cmd.Flag("project-id").Value.String() + if pid == "" { + return nil, cobra.ShellCompDirectiveError + } + + var listExperimentRequest model.ListExperimentRequest + listExperimentRequest.Filter = &model.ExperimentFilterInput{} + + infras, err := infrastructure.GetInfraList(credentials, pid, model.ListInfraRequest{}) + if err != nil { + if strings.Contains(err.Error(), "permission_denied") { + return nil, cobra.ShellCompDirectiveError + + } else { + return nil, cobra.ShellCompDirectiveError + + } + } + + completions := make([]string, 0) + descriptions := make(map[string]string) + + for _, infra := range infras.Data.ListInfraDetails.Infras { + if strings.HasPrefix(infra.InfraID, toComplete) { + completions = append(completions, infra.InfraID) + descriptions[infra.InfraID] = infra.Name + } + } + + var result []string + for _, c := range completions { + result = append(result, c+"\t"+descriptions[c]) + } + return result, cobra.ShellCompDirectiveNoFileComp +} + +func OutputFlagCompletion(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + return []string{"json", "yaml"}, cobra.ShellCompDirectiveNoFileComp +} + +func InstallModeTypeFlagCompletion(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + return []string{"cluster", "namespace"}, cobra.ShellCompDirectiveNoFileComp +} + +func ChaosInfraTypeFlagCompletion(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + return []string{"external", "internal"}, cobra.ShellCompDirectiveNoFileComp +} + +func PlatformNameFlagCompletion(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + return []string{"AWS", "GKE", "Openshift", "Rancher", "Others"}, cobra.ShellCompDirectiveNoFileComp +} From eb3dff09d5c326ddbc5e90604eb6ba0cfd462b15 Mon Sep 17 00:00:00 2001 From: Deep Poharkar <91543514+deep-poharkar@users.noreply.github.com> Date: Mon, 11 Sep 2023 18:21:02 +0530 Subject: [PATCH 2/7] fixed the compatibility matrix (#151) Signed-off-by: deep-poharkar --- pkg/utils/compatibility.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/utils/compatibility.go b/pkg/utils/compatibility.go index 46903cb7..9294d2e6 100644 --- a/pkg/utils/compatibility.go +++ b/pkg/utils/compatibility.go @@ -19,6 +19,7 @@ var ( "0.19.0": {"2.9.0", "2.10.0", "2.11.0", "2.12.0", "2.13.0", "2.14.0", "3.0-beta1", "3.0.0-beta2", "3.0.0-beta3", "3.0.0-beta4", "3.0.0-beta5", "3.0.0-beta6", "3.0.0-beta7", "3.0.0-beta8"}, "0.20.0": {"2.9.0", "2.10.0", "2.11.0", "2.12.0", "2.13.0", "2.14.0", "3.0-beta1", "3.0.0-beta2", "3.0.0-beta3", "3.0.0-beta4", "3.0.0-beta5", "3.0.0-beta6", "3.0.0-beta7", "3.0.0-beta8"}, "0.21.0": {"2.9.0", "2.10.0", "2.11.0", "2.12.0", "2.13.0", "2.14.0", "3.0-beta1", "3.0.0-beta2", "3.0.0-beta3", "3.0.0-beta4", "3.0.0-beta5", "3.0.0-beta6", "3.0.0-beta7", "3.0.0-beta8"}, - "0.22.0": {"3.0.0-beta9", "3.0.0-beta10", "3.0.0-beta11"}, + "0.22.0": {"2.9.0", "2.10.0", "2.11.0", "2.12.0", "2.13.0", "2.14.0", "3.0-beta1", "3.0.0-beta2", "3.0.0-beta3", "3.0.0-beta4", "3.0.0-beta5", "3.0.0-beta6", "3.0.0-beta7", "3.0.0-beta8"}, + "0.23.0": {"3.0.0-beta9", "3.0.0-beta10", "3.0.0-beta11"}, } ) From 6a881833266097657be89cfa0c81962abe9b4926 Mon Sep 17 00:00:00 2001 From: Deep Poharkar <91543514+deep-poharkar@users.noreply.github.com> Date: Wed, 13 Sep 2023 15:24:09 +0530 Subject: [PATCH 3/7] fixed AuthResponse (#153) * fixed the compatibility matrix Signed-off-by: deep-poharkar * fixed AuthResponse snake case to camelCase Signed-off-by: deep-poharkar --------- Signed-off-by: deep-poharkar --- pkg/types/api_types.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/types/api_types.go b/pkg/types/api_types.go index 1f62a11e..8b5da688 100644 --- a/pkg/types/api_types.go +++ b/pkg/types/api_types.go @@ -23,8 +23,8 @@ const ( ) type AuthResponse struct { - AccessToken string `json:"access_token"` - ExpiresIn int64 `json:"expires_in"` + AccessToken string `json:"accessToken"` + ExpiresIn int64 `json:"expiresIn"` Type string `json:"type"` } From 278f868e97ab42a12714fa7a519cd40de4b685fa Mon Sep 17 00:00:00 2001 From: Jongwoo Han Date: Thu, 14 Sep 2023 13:56:31 +0900 Subject: [PATCH 4/7] Replace deprecated command with environment file (#142) Signed-off-by: jongwooo --- .github/workflows/push.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index b10bb0bd..65ae81c9 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -38,7 +38,7 @@ jobs: - name: Get tag shell: bash - run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF##*/})" + run: echo "branch=$(echo ${GITHUB_REF##*/})" >> $GITHUB_OUTPUT id: tag - name: Building litmusctl @@ -55,4 +55,4 @@ jobs: - name: Copy binaries to the litmusctl s3 bucket run: | - aws s3 sync platforms-${{ steps.tag.outputs.branch }} s3://${{ secrets.AWS_S3_BUCKET }} \ No newline at end of file + aws s3 sync platforms-${{ steps.tag.outputs.branch }} s3://${{ secrets.AWS_S3_BUCKET }} From d54699fca4345db3c41fba04ff8861ab50adf748 Mon Sep 17 00:00:00 2001 From: Nageshbansal <76246968+Nageshbansal@users.noreply.github.com> Date: Thu, 14 Sep 2023 10:32:23 +0530 Subject: [PATCH 5/7] Update Upgrade Command (#144) * Update Upgrade Command Signed-off-by: nagesh bansal * Rename ops/ and types/agent_types.go Signed-off-by: nagesh bansal * Add Usage_0.23.0.md link in Readme Signed-off-by: nagesh bansal --------- Signed-off-by: nagesh bansal --- README.md | 1 + pkg/apis/upgrade.go | 40 ++++++++++---------- pkg/cmd/connect/infra.go | 24 ++++++------ pkg/cmd/create/environment.go | 4 +- pkg/cmd/upgrade/{agent.go => infra.go} | 31 ++++++++------- pkg/cmd/upgrade/upgrade.go | 4 +- pkg/{ops => infra_ops}/ops.go | 2 +- pkg/{ops => infra_ops}/platform.go | 2 +- pkg/types/{agent_types.go => infra_types.go} | 0 9 files changed, 57 insertions(+), 51 deletions(-) rename pkg/cmd/upgrade/{agent.go => infra.go} (62%) rename pkg/{ops => infra_ops}/ops.go (99%) rename pkg/{ops => infra_ops}/platform.go (99%) rename pkg/types/{agent_types.go => infra_types.go} (100%) diff --git a/README.md b/README.md index 38530519..92ae697b 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ For more information including a complete list of litmusctl operations, see the * For v0.12.0 or latest: * Non-Interactive mode: Click here * Interactive mode: Click here + * For 0.23.0: Click here * For v0.2.0 or earlier && compatible with Litmus-2.0.0-Beta8 or earlier: Click here ## Requirements diff --git a/pkg/apis/upgrade.go b/pkg/apis/upgrade.go index f2b0af2f..912cd715 100644 --- a/pkg/apis/upgrade.go +++ b/pkg/apis/upgrade.go @@ -26,29 +26,29 @@ type manifestData struct { } type data struct { - GetManifest string `json:"getManifest"` + GetManifest string `json:"getInfraManifest"` } -type InfrasData struct { - Data GetInfraDetails `json:"data"` +type GetInfraResponse struct { + Data GetInfraData `json:"data"` Errors []struct { Message string `json:"message"` Path []string `json:"path"` } `json:"errors"` } -type GetInfraDetails struct { - GetInfraDetails InfrasDetails `json:"getAgentDetails"` +type GetInfraData struct { + GetInfraDetails InfraDetails `json:"getInfraDetails"` } -type InfrasDetails struct { +type InfraDetails struct { InfraID string `json:"infraID"` InfraNamespace *string `json:"infraNamespace"` } func UpgradeInfra(c context.Context, cred types.Credentials, projectID string, infraID string, kubeconfig string) (string, error) { - // Query to fetch agent details from server + // Query to fetch Infra details from server query := `{"query":"query {\n getInfraDetails(infraID : \"` + infraID + `\", \n projectID : \"` + projectID + `\"){\n infraNamespace infraID \n}}"}` resp, err := SendRequest(SendRequestParams{Endpoint: cred.Endpoint + utils.GQLAPIPath, Token: cred.Token}, []byte(query), string(types.Post)) if err != nil { @@ -61,7 +61,7 @@ func UpgradeInfra(c context.Context, cred types.Credentials, projectID string, i } defer resp.Body.Close() - var infra InfrasData + var infra GetInfraResponse if resp.StatusCode == http.StatusOK { err = json.Unmarshal(bodyBytes, &infra) @@ -102,13 +102,13 @@ func UpgradeInfra(c context.Context, cred types.Credentials, projectID string, i } // To write the manifest data into a temporary file - err = ioutil.WriteFile("chaos-delegate-manifest.yaml", []byte(manifest.Data.GetManifest), 0644) + err = ioutil.WriteFile("chaos-infra-manifest.yaml", []byte(manifest.Data.GetManifest), 0644) if err != nil { return "", err } - // Fetching agent-config from the subscriber - configData, err := k8s.GetConfigMap(c, "agent-config", *infra.Data.GetInfraDetails.InfraNamespace) + // Fetching subscriber-config from the subscriber + configData, err := k8s.GetConfigMap(c, "subscriber-config", *infra.Data.GetInfraDetails.InfraNamespace) if err != nil { return "", err } @@ -116,13 +116,13 @@ func UpgradeInfra(c context.Context, cred types.Credentials, projectID string, i metadata := new(bytes.Buffer) fmt.Fprintf(metadata, "\n%s: %s\n%s: %s\n%s: \n %s: %s\n %s: %s\n%s:\n", "apiVersion", "v1", - "kind", "ConfigMap", "metadata", "name", "agent-config", "namespace", *infra.Data.GetInfraDetails.InfraNamespace, "data") + "kind", "ConfigMap", "metadata", "name", "subscriber-config", "namespace", *infra.Data.GetInfraDetails.InfraNamespace, "data") for k, v := range configData { b := new(bytes.Buffer) if k == "COMPONENTS" { fmt.Fprintf(b, " %s: |\n %s", k, v) - } else if k == "START_TIME" || k == "IS_CLUSTER_CONFIRMED" { + } else if k == "START_TIME" || k == "IS_INFRA_CONFIRMED" { fmt.Fprintf(b, " %s: \"%s\"\n", k, v) } else { fmt.Fprintf(b, " %s: %s\n", k, v) @@ -134,7 +134,7 @@ func UpgradeInfra(c context.Context, cred types.Credentials, projectID string, i yamlOutput, err := k8s.ApplyYaml(k8s.ApplyYamlPrams{ Token: cred.Token, Endpoint: cred.Endpoint, - YamlPath: "chaos-delegate-manifest.yaml", + YamlPath: "chaos-infra-manifest.yaml", }, kubeconfig, true) if err != nil { @@ -142,22 +142,22 @@ func UpgradeInfra(c context.Context, cred types.Credentials, projectID string, i } utils.White.Print("\n", yamlOutput) - err = os.Remove("chaos-delegate-manifest.yaml") + err = os.Remove("chaos-infra-manifest.yaml") if err != nil { - return "Error removing Chaos Delegate manifest: ", err + return "Error removing Chaos Infrastructure manifest: ", err } - // Creating a backup for current agent-config in the SUBSCRIBER + // Creating a backup for current subscriber-config in the SUBSCRIBER home, err := homedir.Dir() cobra.CheckErr(err) configMapString = metadata.String() + configMapString - err = ioutil.WriteFile(home+"/backupAgentConfig.yaml", []byte(configMapString), 0644) + err = ioutil.WriteFile(home+"/backupSubscriberConfig.yaml", []byte(configMapString), 0644) if err != nil { - return "Error creating backup for agent config: ", err + return "Error creating backup for subscriber config: ", err } - utils.White_B.Print("\n ** A backup of agent-config configmap has been saved in your system's home directory as backupAgentConfig.yaml **\n") + utils.White_B.Print("\n ** A backup of subscriber-config configmap has been saved in your system's home directory as backupSubscriberConfig.yaml **\n") return "Manifest applied successfully", nil } else { diff --git a/pkg/cmd/connect/infra.go b/pkg/cmd/connect/infra.go index 0eae0bb5..697e31d3 100644 --- a/pkg/cmd/connect/infra.go +++ b/pkg/cmd/connect/infra.go @@ -22,8 +22,8 @@ import ( "os" "github.com/litmuschaos/litmusctl/pkg/apis" + "github.com/litmuschaos/litmusctl/pkg/infra_ops" "github.com/litmuschaos/litmusctl/pkg/k8s" - "github.com/litmuschaos/litmusctl/pkg/ops" "github.com/litmuschaos/litmusctl/pkg/types" "github.com/litmuschaos/litmusctl/pkg/utils" @@ -79,7 +79,7 @@ var infraCmd = &cobra.Command{ if !projectExists { utils.White_B.Print("Creating a random project...") - newInfra.ProjectId = ops.CreateRandomProject(credentials) + newInfra.ProjectId = infra_ops.CreateRandomProject(credentials) } } @@ -166,14 +166,14 @@ var infraCmd = &cobra.Command{ // Check if user has sufficient permissions based on mode utils.White_B.Print("\n🏃 Running prerequisites check....") - ops.ValidateSAPermissions(newInfra.Namespace, newInfra.Mode, &kubeconfig) + infra_ops.ValidateSAPermissions(newInfra.Namespace, newInfra.Mode, &kubeconfig) // Check if infra already exists - isInfraExist, err, infraList := ops.ValidateInfraNameExists(newInfra.InfraName, newInfra.ProjectId, credentials) + isInfraExist, err, infraList := infra_ops.ValidateInfraNameExists(newInfra.InfraName, newInfra.ProjectId, credentials) utils.PrintError(err) if isInfraExist { - ops.PrintExistingInfra(infraList) + infra_ops.PrintExistingInfra(infraList) os.Exit(1) } envIDs, err := environment.GetEnvironmentList(newInfra.ProjectId, credentials) @@ -190,7 +190,7 @@ var infraCmd = &cobra.Command{ } if !isEnvExist { utils.Red.Println("\nChaos Environment with the given ID doesn't exists.") - ops.PrintExistingEnvironments(envIDs) + infra_ops.PrintExistingEnvironments(envIDs) utils.White_B.Println("\n❗ Please enter a name from the List or Create a new environment using `litmusctl create chaos-environment`") os.Exit(1) } @@ -201,25 +201,25 @@ var infraCmd = &cobra.Command{ if newInfra.ProjectId == "" { // Fetch project id - newInfra.ProjectId = ops.GetProjectID(userDetails) + newInfra.ProjectId = infra_ops.GetProjectID(userDetails) } - modeType := ops.GetModeType() + modeType := infra_ops.GetModeType() // Check if user has sufficient permissions based on mode utils.White_B.Print("\n🏃 Running prerequisites check....") - ops.ValidateSAPermissions(newInfra.Namespace, modeType, &kubeconfig) - newInfra, err = ops.GetInfraDetails(modeType, newInfra.ProjectId, credentials, &kubeconfig) + infra_ops.ValidateSAPermissions(newInfra.Namespace, modeType, &kubeconfig) + newInfra, err = infra_ops.GetInfraDetails(modeType, newInfra.ProjectId, credentials, &kubeconfig) utils.PrintError(err) newInfra.ServiceAccount, newInfra.SAExists = k8s.ValidSA(newInfra.Namespace, &kubeconfig) newInfra.Mode = modeType } - ops.Summary(newInfra, &kubeconfig) + infra_ops.Summary(newInfra, &kubeconfig) if !nonInteractive { - ops.ConfirmInstallation() + infra_ops.ConfirmInstallation() } infra, err := infrastructure.ConnectInfra(newInfra, credentials) diff --git a/pkg/cmd/create/environment.go b/pkg/cmd/create/environment.go index 23e4aad2..e2a346ff 100644 --- a/pkg/cmd/create/environment.go +++ b/pkg/cmd/create/environment.go @@ -20,7 +20,7 @@ import ( 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/ops" + "github.com/litmuschaos/litmusctl/pkg/infra_ops" "github.com/litmuschaos/litmusctl/pkg/utils" "github.com/spf13/cobra" "os" @@ -109,7 +109,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 62% rename from pkg/cmd/upgrade/agent.go rename to pkg/cmd/upgrade/infra.go index 7de68ca7..ff22faa6 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/utils" @@ -26,9 +27,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) @@ -41,20 +42,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) @@ -62,8 +67,8 @@ 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") + 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") } diff --git a/pkg/cmd/upgrade/upgrade.go b/pkg/cmd/upgrade/upgrade.go index deb5d5ea..88a66bfe 100644 --- a/pkg/cmd/upgrade/upgrade.go +++ b/pkg/cmd/upgrade/upgrade.go @@ -23,8 +23,8 @@ import ( var UpgradeCmd = &cobra.Command{ Use: "upgrade", Short: `Examples: - #upgrade version of your Chaos Delegate - litmusctl upgrade chaos-delegate --chaos-delegate-id="4cc25543-36c8-4373-897b-2e5dbbe87bcf" --project-id="d861b650-1549-4574-b2ba-ab754058dd04" --non-interactive + #upgrade version of your Chaos Infrastructure + litmusctl upgrade chaos-infra --chaos-infra-id="4cc25543-36c8-4373-897b-2e5dbbe87bcf" --project-id="d861b650-1549-4574-b2ba-ab754058dd04" --non-interactive Note: The default location of the config file is $HOME/.litmusconfig, and can be overridden by a --config flag `, diff --git a/pkg/ops/ops.go b/pkg/infra_ops/ops.go similarity index 99% rename from pkg/ops/ops.go rename to pkg/infra_ops/ops.go index 129cff47..b4a2119b 100644 --- a/pkg/ops/ops.go +++ b/pkg/infra_ops/ops.go @@ -13,7 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ -package ops +package infra_ops import ( "fmt" diff --git a/pkg/ops/platform.go b/pkg/infra_ops/platform.go similarity index 99% rename from pkg/ops/platform.go rename to pkg/infra_ops/platform.go index 3952c71c..dbd636f8 100644 --- a/pkg/ops/platform.go +++ b/pkg/infra_ops/platform.go @@ -13,7 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ -package ops +package infra_ops import ( "context" diff --git a/pkg/types/agent_types.go b/pkg/types/infra_types.go similarity index 100% rename from pkg/types/agent_types.go rename to pkg/types/infra_types.go From 7da3f417df858945660468cb0873135a3975e0ad Mon Sep 17 00:00:00 2001 From: Sarthak Jain Date: Fri, 15 Sep 2023 17:53:26 +0530 Subject: [PATCH 6/7] Added changes for 0.24 release (#154) * Added changes for 0.24 release Signed-off-by: Sarthak Jain * minor changes Signed-off-by: Sarthak Jain --------- Signed-off-by: Sarthak Jain --- README.md | 25 +++++++++++++++---------- pkg/utils/compatibility.go | 3 ++- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 92ae697b..a904d8a5 100644 --- a/README.md +++ b/README.md @@ -109,7 +109,12 @@ To check compatibility of litmusctl with Chaos Center 0.23.0 3.0.0-beta9 - 3.0.0-beta11 + 3.0.0-beta12 + + + 0.24.0 + 3.0.0-beta9 + 3.0.0-beta12 @@ -119,6 +124,7 @@ To install the latest version of litmusctl follow the below steps: + @@ -126,10 +132,10 @@ To install the latest version of litmusctl follow the below steps: - + @@ -137,11 +143,11 @@ To install the latest version of litmusctl follow the below steps: - + @@ -149,11 +155,11 @@ To install the latest version of litmusctl follow the below steps: - + @@ -161,11 +167,11 @@ To install the latest version of litmusctl follow the below steps: - + @@ -173,11 +179,11 @@ To install the latest version of litmusctl follow the below steps: - + @@ -185,11 +191,11 @@ To install the latest version of litmusctl follow the below steps: - + @@ -197,11 +203,11 @@ To install the latest version of litmusctl follow the below steps: - + @@ -209,11 +215,11 @@ To install the latest version of litmusctl follow the below steps: - + @@ -221,7 +227,6 @@ To install the latest version of litmusctl follow the below steps: -
Platforms0.24.0 0.23.0 0.22.0 0.21.00.19.0 0.18.0 0.17.00.16.0 master(Unreleased)
litmusctl-darwin-amd64 (MacOS)Click here Click here Click here Click hereClick here Click here Click hereClick here Click here
litmusctl-linux-386Click here Click here Click here Click hereClick here Click here Click hereClick here Click here
litmusctl-linux-amd64Click here Click here Click here Click hereClick here Click here Click hereClick here Click here
litmusctl-linux-armClick here Click here Click here Click hereClick here Click here Click hereClick here Click here
litmusctl-linux-arm64Click here Click here Click here Click hereClick here Click here Click hereClick here Click here
litmusctl-windows-386Click here Click here Click here Click hereClick here Click here Click hereClick here Click here
litmusctl-windows-amd64Click here Click here Click here Click hereClick here Click here Click hereClick here Click here
litmusctl-windows-armClick here Click here Click here Click hereClick here Click here Click hereClick here Click here
diff --git a/pkg/utils/compatibility.go b/pkg/utils/compatibility.go index 9294d2e6..671919f7 100644 --- a/pkg/utils/compatibility.go +++ b/pkg/utils/compatibility.go @@ -20,6 +20,7 @@ var ( "0.20.0": {"2.9.0", "2.10.0", "2.11.0", "2.12.0", "2.13.0", "2.14.0", "3.0-beta1", "3.0.0-beta2", "3.0.0-beta3", "3.0.0-beta4", "3.0.0-beta5", "3.0.0-beta6", "3.0.0-beta7", "3.0.0-beta8"}, "0.21.0": {"2.9.0", "2.10.0", "2.11.0", "2.12.0", "2.13.0", "2.14.0", "3.0-beta1", "3.0.0-beta2", "3.0.0-beta3", "3.0.0-beta4", "3.0.0-beta5", "3.0.0-beta6", "3.0.0-beta7", "3.0.0-beta8"}, "0.22.0": {"2.9.0", "2.10.0", "2.11.0", "2.12.0", "2.13.0", "2.14.0", "3.0-beta1", "3.0.0-beta2", "3.0.0-beta3", "3.0.0-beta4", "3.0.0-beta5", "3.0.0-beta6", "3.0.0-beta7", "3.0.0-beta8"}, - "0.23.0": {"3.0.0-beta9", "3.0.0-beta10", "3.0.0-beta11"}, + "0.23.0": {"3.0.0-beta9", "3.0.0-beta10", "3.0.0-beta11", "3.0.0-beta12"}, + "0.24.0": {"3.0.0-beta9", "3.0.0-beta10", "3.0.0-beta11", "3.0.0-beta12"}, } ) From 85aa42659c1ea94379748cd355ee795a307b3a16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20ZIOLKOWSKI?= Date: Tue, 17 Oct 2023 13:43:13 +0200 Subject: [PATCH 7/7] Fix merge conflicts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rémi ZIOLKOWSKI --- pkg/cmd/create/environment.go | 5 ++-- pkg/cmd/upgrade/{agent.go => infra.go} | 35 +++++++++++++++----------- 2 files changed, 23 insertions(+), 17 deletions(-) rename pkg/cmd/upgrade/{agent.go => infra.go} (59%) 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) }