From 7ea4b7775369ae5012909a053f6a2493addc2e13 Mon Sep 17 00:00:00 2001 From: Saranya Jena Date: Thu, 12 May 2022 15:00:24 +0530 Subject: [PATCH] Updated APIs as per new schema changes in litmus (#67) * Fixed API naming, updated LitmusPortal -> ChaosCenter Signed-off-by: Vansh Bhatia * Fixed some schema changes in projects and agents side Signed-off-by: Saranya-jena * Changed Chaos Center to ChaosCenter Signed-off-by: Saranya-jena Co-authored-by: Vansh Bhatia --- Usage_interactive.md | 2 +- Usage_v0.2.0.md | 19 ++++++++++--------- pkg/apis/agent.go | 26 +++++++++++++------------- pkg/apis/upgrade.go | 10 +++++----- pkg/cmd/config/config.go | 2 +- pkg/cmd/create/agent.go | 1 - pkg/k8s/operations.go | 2 +- pkg/types/agent_types.go | 10 +++++----- 8 files changed, 36 insertions(+), 36 deletions(-) diff --git a/Usage_interactive.md b/Usage_interactive.md index 4a428500..c18d49a1 100644 --- a/Usage_interactive.md +++ b/Usage_interactive.md @@ -172,7 +172,7 @@ Installation Mode: cluster Applying YAML: https://preview.litmuschaos.io/api/file/eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjbHVzdGVyX2lkIjoiMDUyZmFlN2UtZGM0MS00YmU4LWJiYTgtMmM4ZTYyNDFkN2I0In0.i31QQDG92X5nD6P_-7TfeAAarZqLvUTFfnAghJYXPiM.yaml -šŸ’” Connecting agent to Litmus Portal. +šŸ’” Connecting agent to ChaosCenter. šŸƒ Agents are running!! šŸš€ Agent Connection Successful!! šŸŽ‰ diff --git a/Usage_v0.2.0.md b/Usage_v0.2.0.md index fe5dc38f..7fb089c6 100644 --- a/Usage_v0.2.0.md +++ b/Usage_v0.2.0.md @@ -1,8 +1,9 @@ # Usage: Litmusctl v0.2.0 > Notes: -> * For litmusctl v0.3.0 or earlier -> * Compatible with Litmus 2.0.0-Beta8 or earlier +> +> - For litmusctl v0.3.0 or earlier +> - Compatible with Litmus 2.0.0-Beta8 or earlier ### Connecting an agent @@ -12,13 +13,13 @@ To connect Litmus Chaos agent: litmusctl agent connect ``` -Next, you need to enter LitmusPortal details to login into your LitmusPortal account. Fields to be filled in: +Next, you need to enter ChaosCenter details to login into your ChaosCenter account. Fields to be filled in: -**LimtusPortal UI URL:** Enter the URL used to access the Litmus Portal UI. +**ChaosCenter UI URL:** Enter the URL used to access the ChaosCenter UI. Example, http://172.17.0.2:31696/ -**Username:** Enter your LitmusPortal username. -**Password:** Enter your LitmusPortal password. +**Username:** Enter your ChaosCenter username. +**Password:** Enter your ChaosCenter password. ```shell šŸ”„ Connecting LitmusChaos agent @@ -64,7 +65,7 @@ Fields to filled in: **Platform Name:** Enter the platform name on which this agent is hosted. For example, AWS, GCP, Rancher etc. -**Enter the namespace:** You can either enter an existing namespace or enter a new namespace. In cases where the namespace does not exist, LimtusPortal creates it for you. +**Enter the namespace:** You can either enter an existing namespace or enter a new namespace. In cases where the namespace does not exist, ChaosCenter creates it for you. **Enter service account:** Enter a name for your service account. @@ -100,10 +101,10 @@ Installation Mode: cluster šŸ¤· Do you want to continue with the above details? [Y/N]: Y -šŸ’” Connecting agent to Litmus Portal. +šŸ’” Connecting agent to ChaosCenter. šŸƒ Agents running!! šŸš€ Agent Connection Successful!! šŸŽ‰ šŸ‘‰ Litmus agents can be accessed here: http://172.17.0.2:31696/targets ``` -To verify, if the connection process was successful you can view the list of connected agents from the Targets section on your LitmusPortal and ensure that the connected agent is in Active State. +To verify, if the connection process was successful you can view the list of connected agents from the Targets section on your ChaosCenter and ensure that the connected agent is in Active State. diff --git a/pkg/apis/agent.go b/pkg/apis/agent.go index edc100c2..d7825ac9 100644 --- a/pkg/apis/agent.go +++ b/pkg/apis/agent.go @@ -36,19 +36,19 @@ type AgentData struct { } type AgentDetails struct { - AgentName string `json:"cluster_name"` - IsActive bool `json:"is_active"` - IsRegistered bool `json:"is_registered"` - ClusterID string `json:"cluster_id"` + AgentName string `json:"clusterName"` + IsActive bool `json:"isActive"` + IsRegistered bool `json:"isRegistered"` + ClusterID string `json:"clusterID"` } type AgentList struct { - GetAgent []AgentDetails `json:"getCluster"` + GetAgent []AgentDetails `json:"listClusters"` } // GetAgentList lists the agent connected to the specified project func GetAgentList(c types.Credentials, pid string) (AgentData, error) { - query := `{"query":"query{\n getCluster(project_id: \"` + pid + `\"){\n cluster_id cluster_name is_active \n }\n}"}` + query := `{"query":"query{\n listClusters(projectID: \"` + pid + `\"){\n clusterID clusterName isActive \n }\n}"}` resp, err := SendRequest(SendRequestParams{Endpoint: c.Endpoint + utils.GQLAPIPath, Token: c.Token}, []byte(query), string(types.Post)) if err != nil { return AgentData{}, err @@ -91,29 +91,29 @@ type Errors struct { } type AgentConnect struct { - UserAgentReg UserAgentReg `json:"userClusterReg"` + UserAgentReg UserAgentReg `json:"registerCluster"` } type UserAgentReg struct { - ClusterID string `json:"cluster_id"` - ClusterName string `json:"cluster_name"` + ClusterID string `json:"clusterID"` + ClusterName string `json:"clusterName"` Token string `json:"token"` } // ConnectAgent connects the agent with the given details func ConnectAgent(agent types.Agent, cred types.Credentials) (AgentConnectionData, error) { - query := `{"query":"mutation {\n userClusterReg(clusterInput: \n { \n cluster_name: \"` + agent.AgentName + `\", \n description: \"` + agent.Description + `\",\n \tplatform_name: \"` + agent.PlatformName + `\",\n project_id: \"` + agent.ProjectId + `\",\n cluster_type: \"` + agent.ClusterType + `\",\n agent_scope: \"` + agent.Mode + `\",\n agent_namespace: \"` + agent.Namespace + `\",\n serviceaccount: \"` + agent.ServiceAccount + `\",\n skip_ssl: ` + fmt.Sprintf("%t", agent.SkipSSL) + `,\n agent_ns_exists: ` + fmt.Sprintf("%t", agent.NsExists) + `,\n agent_sa_exists: ` + fmt.Sprintf("%t", agent.SAExists) + `,\n }){\n cluster_id\n cluster_name\n token\n }\n}"}` + query := `{"query":"mutation {\n registerCluster(request: \n { \n clusterName: \"` + agent.AgentName + `\", \n description: \"` + agent.Description + `\",\n \tplatformName: \"` + agent.PlatformName + `\",\n projectID: \"` + agent.ProjectId + `\",\n clusterType: \"` + agent.ClusterType + `\",\n agentScope: \"` + agent.Mode + `\",\n agentNamespace: \"` + agent.Namespace + `\",\n serviceAccount: \"` + agent.ServiceAccount + `\",\n skipSsl: ` + fmt.Sprintf("%t", agent.SkipSSL) + `,\n agentNsExists: ` + fmt.Sprintf("%t", agent.NsExists) + `,\n agentSaExists: ` + fmt.Sprintf("%t", agent.SAExists) + `,\n }){\n clusterID\n clusterName\n token\n }\n}"}` if agent.NodeSelector != "" { - query = `{"query":"mutation {\n userClusterReg(clusterInput: \n { \n cluster_name: \"` + agent.AgentName + `\", \n description: \"` + agent.Description + `\",\n node_selector: \"` + agent.NodeSelector + `\",\n \tplatform_name: \"` + agent.PlatformName + `\",\n project_id: \"` + agent.ProjectId + `\",\n cluster_type: \"` + agent.ClusterType + `\",\n agent_scope: \"` + agent.Mode + `\",\n agent_namespace: \"` + agent.Namespace + `\",\n skip_ssl: ` + fmt.Sprintf("%t", agent.SkipSSL) + `,\n serviceaccount: \"` + agent.ServiceAccount + `\",\n agent_ns_exists: ` + fmt.Sprintf("%t", agent.NsExists) + `,\n agent_sa_exists: ` + fmt.Sprintf("%t", agent.SAExists) + `,\n }){\n cluster_id\n cluster_name\n token\n }\n}"}` + query = `{"query":"mutation {\n registerCluster(request: \n { \n clusterName: \"` + agent.AgentName + `\", \n description: \"` + agent.Description + `\",\n nodeSelector: \"` + agent.NodeSelector + `\",\n \tplatformName: \"` + agent.PlatformName + `\",\n projectID: \"` + agent.ProjectId + `\",\n clusterType: \"` + agent.ClusterType + `\",\n agentScope: \"` + agent.Mode + `\",\n agentNamespace: \"` + agent.Namespace + `\",\n skipSsl: ` + fmt.Sprintf("%t", agent.SkipSSL) + `,\n serviceAccount: \"` + agent.ServiceAccount + `\",\n agentNsExists: ` + fmt.Sprintf("%t", agent.NsExists) + `,\n agentSaExists: ` + fmt.Sprintf("%t", agent.SAExists) + `,\n }){\n clusterID\n clusterName\n token\n }\n}"}` } if agent.Tolerations != "" { - query = `{"query":"mutation {\n userClusterReg(clusterInput: \n { \n cluster_name: \"` + agent.AgentName + `\", \n description: \"` + agent.Description + `\",\n \tplatform_name: \"` + agent.PlatformName + `\",\n project_id: \"` + agent.ProjectId + `\",\n cluster_type: \"` + agent.ClusterType + `\",\n agent_scope: \"` + agent.Mode + `\",\n agent_namespace: \"` + agent.Namespace + `\",\n serviceaccount: \"` + agent.ServiceAccount + `\",\n skip_ssl: ` + fmt.Sprintf("%t", agent.SkipSSL) + `,\n agent_ns_exists: ` + fmt.Sprintf("%t", agent.NsExists) + `,\n agent_sa_exists: ` + fmt.Sprintf("%t", agent.SAExists) + `,\n tolerations: ` + agent.Tolerations + ` }){\n cluster_id\n cluster_name\n token\n }\n}"}` + query = `{"query":"mutation {\n registerCluster(request: \n { \n clusterName: \"` + agent.AgentName + `\", \n description: \"` + agent.Description + `\",\n \tplatformName: \"` + agent.PlatformName + `\",\n projectID: \"` + agent.ProjectId + `\",\n clusterType: \"` + agent.ClusterType + `\",\n agentScope: \"` + agent.Mode + `\",\n agentNamespace: \"` + agent.Namespace + `\",\n serviceAccount: \"` + agent.ServiceAccount + `\",\n skipSsl: ` + fmt.Sprintf("%t", agent.SkipSSL) + `,\n agentNsExists: ` + fmt.Sprintf("%t", agent.NsExists) + `,\n agentSaExists: ` + fmt.Sprintf("%t", agent.SAExists) + `,\n tolerations: ` + agent.Tolerations + ` }){\n clusterID\n clusterName\n token\n }\n}"}` } if agent.NodeSelector != "" && agent.Tolerations != "" { - query = `{"query":"mutation {\n userClusterReg(clusterInput: \n { \n cluster_name: \"` + agent.AgentName + `\", \n description: \"` + agent.Description + `\",\n node_selector: \"` + agent.NodeSelector + `\",\n \tplatform_name: \"` + agent.PlatformName + `\",\n project_id: \"` + agent.ProjectId + `\",\n cluster_type: \"` + agent.ClusterType + `\",\n agent_scope: \"` + agent.Mode + `\",\n agent_namespace: \"` + agent.Namespace + `\",\n skip_ssl: ` + fmt.Sprintf("%t", agent.SkipSSL) + `,\n serviceaccount: \"` + agent.ServiceAccount + `\",\n agent_ns_exists: ` + fmt.Sprintf("%t", agent.NsExists) + `,\n agent_sa_exists: ` + fmt.Sprintf("%t", agent.SAExists) + `,\n tolerations: ` + agent.Tolerations + ` }){\n cluster_id\n cluster_name\n token\n }\n}"}` + query = `{"query":"mutation {\n registerCluster(request: \n { \n clusterName: \"` + agent.AgentName + `\", \n description: \"` + agent.Description + `\",\n nodeSelector: \"` + agent.NodeSelector + `\",\n \tplatformName: \"` + agent.PlatformName + `\",\n projectID: \"` + agent.ProjectId + `\",\n clusterType: \"` + agent.ClusterType + `\",\n agentScope: \"` + agent.Mode + `\",\n agentNamespace: \"` + agent.Namespace + `\",\n skipSsl: ` + fmt.Sprintf("%t", agent.SkipSSL) + `,\n serviceAccount: \"` + agent.ServiceAccount + `\",\n agentNsExists: ` + fmt.Sprintf("%t", agent.NsExists) + `,\n agentSaExists: ` + fmt.Sprintf("%t", agent.SAExists) + `,\n tolerations: ` + agent.Tolerations + ` }){\n clusterID\n clusterName\n token\n }\n}"}` } resp, err := SendRequest(SendRequestParams{Endpoint: cred.Endpoint + utils.GQLAPIPath, Token: cred.Token}, []byte(query), string(types.Post)) diff --git a/pkg/apis/upgrade.go b/pkg/apis/upgrade.go index 3f0cbd5c..529a0f33 100644 --- a/pkg/apis/upgrade.go +++ b/pkg/apis/upgrade.go @@ -34,15 +34,15 @@ type GetAgentDetails struct { } type ClusterDetails struct { - ClusterID string `json:"cluster_id"` - AccessKey string `json:"access_key"` - AgentNamespace *string `json:"agent_namespace"` + ClusterID string `json:"clusterID"` + AccessKey string `json:"accessKey"` + AgentNamespace *string `json:"agentNamespace"` } -func UpgradeAgent(c context.Context, cred types.Credentials, projectID string, cluster_id string) (string, error) { +func UpgradeAgent(c context.Context, cred types.Credentials, projectID string, clusterID string) (string, error) { // Query to fetch agent details from server - query := `{"query":"query {\n getAgentDetails(cluster_id : \"` + cluster_id + `\", \n projectID : \"` + projectID + `\"){\n agent_namespace access_key cluster_id \n}}"}` + query := `{"query":"query {\n getAgentDetails(clusterID : \"` + clusterID + `\", \n projectID : \"` + projectID + `\"){\n agentNamespace accessKey clusterID \n}}"}` resp, err := SendRequest(SendRequestParams{Endpoint: cred.Endpoint + utils.GQLAPIPath, Token: cred.Token}, []byte(query), string(types.Post)) if err != nil { return "", err diff --git a/pkg/cmd/config/config.go b/pkg/cmd/config/config.go index 8db28e77..f1569e61 100644 --- a/pkg/cmd/config/config.go +++ b/pkg/cmd/config/config.go @@ -22,7 +22,7 @@ import ( // configCmd represents the config command var ConfigCmd = &cobra.Command{ Use: "config", - Short: `It manages multiple litmusportal accounts within a system. + Short: `It manages multiple ChaosCenter accounts within a system. Examples(s) #set a new account litmusctl config set-account --endpoint "" --password "" --username "" diff --git a/pkg/cmd/create/agent.go b/pkg/cmd/create/agent.go index 8a5de4da..d6e579a6 100644 --- a/pkg/cmd/create/agent.go +++ b/pkg/cmd/create/agent.go @@ -239,7 +239,6 @@ var agentCmd = &cobra.Command{ utils.Red.Println("\nāŒ Agent connection failed: " + err.Error() + "\n") os.Exit(1) } - path := fmt.Sprintf("%s/%s/%s.yaml", credentials.Endpoint, utils.ChaosYamlPath, agent.Data.UserAgentReg.Token) utils.White_B.Print("Applying YAML:\n", path) diff --git a/pkg/k8s/operations.go b/pkg/k8s/operations.go index d7786a54..e6aecc43 100644 --- a/pkg/k8s/operations.go +++ b/pkg/k8s/operations.go @@ -192,7 +192,7 @@ func WatchPod(params WatchPodParams, kubeconfig *string) { if !ok { log.Fatal("unexpected type") } - utils.White_B.Println("šŸ’” Connecting agent to Litmus Portal.") + utils.White_B.Println("šŸ’” Connecting agent to ChaosCenter.") if p.Status.Phase == "Running" { utils.White_B.Println("šŸƒ Agents are running!!") watch.Stop() diff --git a/pkg/types/agent_types.go b/pkg/types/agent_types.go index 31d9a983..423ed25b 100644 --- a/pkg/types/agent_types.go +++ b/pkg/types/agent_types.go @@ -16,13 +16,13 @@ limitations under the License. package types type Agent struct { - AgentName string `json:"cluster_name"` + AgentName string `json:"clusterName"` Mode string Description string `json:"description,omitempty"` - PlatformName string `json:"platform_name"` - ProjectId string `json:"project_id"` - ClusterType string `json:"cluster_type"` - NodeSelector string `json:"node_selector"` + PlatformName string `json:"platformName"` + ProjectId string `json:"projectID"` + ClusterType string `json:"clusterType"` + NodeSelector string `json:"nodeSelector"` Tolerations string Namespace string ServiceAccount string