Skip to content

Commit

Permalink
Updated APIs as per new schema changes in litmus (#67)
Browse files Browse the repository at this point in the history
* Fixed API naming, updated LitmusPortal -> ChaosCenter

Signed-off-by: Vansh Bhatia <vansh.bhatia@harness.io>

* Fixed some schema changes in projects and agents side

Signed-off-by: Saranya-jena <saranya.jena@harness.io>

* Changed Chaos Center to ChaosCenter

Signed-off-by: Saranya-jena <saranya.jena@harness.io>

Co-authored-by: Vansh Bhatia <vansh.bhatia@harness.io>
  • Loading branch information
Saranya-jena and vanshBhatia-A4k9 committed May 12, 2022
1 parent bc205aa commit 7ea4b77
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 36 deletions.
2 changes: 1 addition & 1 deletion Usage_interactive.md
Original file line number Diff line number Diff line change
Expand Up @@ -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!! 🎉
Expand Down
19 changes: 10 additions & 9 deletions Usage_v0.2.0.md
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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.
26 changes: 13 additions & 13 deletions pkg/apis/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down
10 changes: 5 additions & 5 deletions pkg/apis/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
Expand Down
1 change: 0 additions & 1 deletion pkg/cmd/create/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion pkg/k8s/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
10 changes: 5 additions & 5 deletions pkg/types/agent_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7ea4b77

Please sign in to comment.