Skip to content

Commit

Permalink
Updated Error message formats in agent connection and project creation (
Browse files Browse the repository at this point in the history
#8)

* updated error message format

Signed-off-by: Saranya-jena <[email protected]>

* minor updations

Signed-off-by: Saranya-jena <[email protected]>

* updated log messages

Signed-off-by: Saranya-jena <[email protected]>

* minor change

Signed-off-by: Saranya-jena <[email protected]>

* minor route updation

Signed-off-by: Saranya-jena <[email protected]>
  • Loading branch information
Saranya Jena committed Apr 19, 2022
1 parent 7f8ed36 commit 83d2ab2
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 40 deletions.
24 changes: 12 additions & 12 deletions Usage_interactive.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ Next, you need to enter CLC/CLE details to login into your account. Fields to be
**AccessKey:** What's the AccessKey?:

```
? What's the product name?:
? What's the product name?:
▸ ChaosNative Cloud
ChaosNative Enterprise
What's the AccessID?: Raj60163RjxQE
What's the AccessKey?: ***************
Expand All @@ -58,7 +58,7 @@ chaosctl create agent
There will be a list of existing projects displayed on the terminal. Select the desired project by entering the sequence number indicated against it.

```
? Select a project from the list:
? Select a project from the list:
▸ Raj60163's project
```

Expand All @@ -73,7 +73,7 @@ It can install an agent in two different modes.
Note: With namespace mode, the user needs to create the namespace to install the agent as a prerequisite.

```
? What's the installation mode?:
? What's the installation mode?:
▸ Cluster
Namespace
Expand Down Expand Up @@ -123,15 +123,15 @@ Enter the details of the agent
✔ Add your agent description: new-agent█
? Do you want NodeSelectors added to the agent deployments?:
? Do you want NodeSelectors added to the agent deployments?:
Yes
▸ No
? Do you want Tolerations added in the agent deployments??:
? Do you want Tolerations added in the agent deployments??:
Yes
▸ No
? What's your Kubernetes Platform?:
? What's your Kubernetes Platform?:
▸ Others
AWS Elastic Kubernetes Service
Google Kubernetes Service
Expand All @@ -157,19 +157,19 @@ Namespace: litmus
Service Account: litmus (new)
Installation Mode: cluster
? Do you want to continue with the above details?:
? Do you want to continue with the above details?:
▸ Yes
No
👍 Continuing agent connection!!
Applying YAML:
https://preview.litmuschaos.io/api/file/eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjbHVzdGVyX2lkIjoiMDUyZmFlN2UtZGM0MS00YmU4LWJiYTgtMmM4ZTYyNDFkN2I0In0.i31QQDG92X5nD6P_-7TfeAAarZqLvUTFfnAghJYXPiM.yaml
💡 Connecting agent to Litmus Portal.
💡 Connecting agent to Chaos Center.
🏃 Agents are running!!
🚀 Agent Connection Successful!! 🎉
👉 Litmus agents can be accessed here: https://preview.litmuschaos.io/targets
👉 Litmus agents can be accessed here: https://cloud.chaosnative.com/agents
```

#### Verify the new Agent Connection\*\*
Expand Down Expand Up @@ -223,10 +223,10 @@ CURRENT ENDPOINT ACCESSID EXPIRESIN
```shell
chaosctl config use-account

? What's the product name?:
? What's the product name?:
▸ ChaosNative Cloud
ChaosNative Enterprise
What's the AccessID?: Raj60163RjxQE
```

Expand Down
10 changes: 0 additions & 10 deletions pkg/apis/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,6 @@ func GetAgentList(c types.Credentials, pid string) (AgentData, error) {
utils.Red.Println("Error in getting agent list: ", err)
os.Exit(1)
}

if len(agent.Errors) > 0 {
return AgentData{}, errors.New(agent.Errors[0].Message)
}

return agent, nil
} else {
return AgentData{}, err
Expand Down Expand Up @@ -124,7 +119,6 @@ func ConnectAgent(agent types.Agent, cred types.Credentials) (AgentConnectionDat
if err != nil {
return AgentConnectionData{}, errors.New("Error in registering agent: " + err.Error())
}

bodyBytes, err := ioutil.ReadAll(resp.Body)
defer resp.Body.Close()
if err != nil {
Expand All @@ -137,10 +131,6 @@ func ConnectAgent(agent types.Agent, cred types.Credentials) (AgentConnectionDat
if err != nil {
return AgentConnectionData{}, errors.New("Error in registering agent: " + err.Error())
}

if len(connectAgent.Errors) > 0 {
return AgentConnectionData{}, errors.New(connectAgent.Errors[0].Message)
}
return connectAgent, nil
} else {
return AgentConnectionData{}, err
Expand Down
15 changes: 3 additions & 12 deletions pkg/apis/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ import (
)

type createProjectResponse struct {
Data struct {
Message string `json:"message"`
Data struct {
Name string `json:"name"`
ID string `json:"id"`
} `json:"data"`
Errors []struct {
Message string `json:"message"`
Path []string `json:"path"`
Path []string `json:"path"`
} `json:"errors"`
}

Expand Down Expand Up @@ -72,10 +72,6 @@ func CreateProjectRequest(userID string, projectName string, cred types.Credenti
return createProjectResponse{}, err
}

if len(project.Errors) > 0 {
return createProjectResponse{}, errors.New(project.Errors[0].Message)
}

utils.White_B.Println("project/" + project.Data.Name + " created")
return project, nil
} else {
Expand Down Expand Up @@ -115,11 +111,6 @@ func ListProject(cred types.Credentials) (listProjectResponse, error) {
if err != nil {
return listProjectResponse{}, err
}

if len(data.Errors) > 0 {
return listProjectResponse{}, errors.New(data.Errors[0].Message)
}

return data, nil
} else {
return listProjectResponse{}, errors.New("Unmatched status code:" + string(bodyBytes))
Expand Down
4 changes: 1 addition & 3 deletions pkg/cmd/create/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,18 +224,16 @@ var agentCmd = &cobra.Command{
if !nonInteractive {
agent.ConfirmInstallation()
}

agent, err := apis.ConnectAgent(newAgent, credentials)
if err != nil {
utils.Red.Println("\n❌ Agent connection failed: " + err.Error() + "\n")
os.Exit(1)
}

if agent.Data.UserAgentReg.Token != "" {
path := fmt.Sprintf("%s/%s/%s.yaml", credentials.Endpoint, utils.ChaosYamlPath, agent.Data.UserAgentReg.Token)
utils.White_B.Print("Applying YAML:\n", path)
} else {
utils.Red.Print("\n🚫 Token Generation failed, Agent installation failed: " + agent.Errors[0].Message + "\n")
utils.Red.Print("\n🚫 Token Generation failed, Agent installation failed\n")
os.Exit(1)
}

Expand Down
5 changes: 3 additions & 2 deletions pkg/k8s/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ import (
"errors"
"flag"
"fmt"
"github.com/manifoldco/promptui"
"log"
"os"
"os/exec"
"path/filepath"

"github.com/manifoldco/promptui"

"k8s.io/client-go/util/homedir"

"github.com/chaosnative/chaosctl/pkg/utils"
Expand Down Expand Up @@ -207,7 +208,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 Chaos Center.")
if p.Status.Phase == "Running" {
utils.White_B.Println("🏃 Agents are running!!")
watch.Stop()
Expand Down
2 changes: 1 addition & 1 deletion pkg/utils/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const (
// Chaos agent connection yaml path
ChaosYamlPath = "api/file"

ChaosAgentPath = "targets"
ChaosAgentPath = "agents"

// Graphql server api path
GQLAPIPath = "/api/query"
Expand Down

0 comments on commit 83d2ab2

Please sign in to comment.