diff --git a/README.md b/README.md index 930b0462..03c6ae53 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