Skip to content

Commit

Permalink
Updated commands (#15)
Browse files Browse the repository at this point in the history
* Update create agent to connect chaos-delegate and get agents to get chaos-delegates

Signed-off-by: Sarthak Jain <[email protected]>

* Fixed typos

Signed-off-by: Sarthak Jain <[email protected]>
  • Loading branch information
SarthakJain26 authored Jul 27, 2022
1 parent 6664540 commit afe2780
Show file tree
Hide file tree
Showing 13 changed files with 131 additions and 99 deletions.
64 changes: 32 additions & 32 deletions Usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
chaosctl [command] [TYPE] [flags]
```

- Command: refers to what you do want to perform (create, get and config)
- Type: refers to the feature type you are performing a command against (agent, project etc.)
- Command: refers to what you do want to perform (connect, create, get and config)
- Type: refers to the feature type you are performing a command against (chaos-delegate, project etc.)
- Flags: It takes some additional information for resource operations. For example, `--installation-mode` allows you to specify an installation mode.

chaosctl is using the `.chaosconfig` config file to manage multiple accounts
Expand All @@ -19,21 +19,21 @@ chaosctl is using the `.chaosconfig` config file to manage multiple accounts

chaosctl supports both interactive and non-interactive(flag based) modes.

> Only `chaosctl create agent` command needs --non-interactive flag, other commands don't need this flag to be in non-interactive mode. If mandatory flags aren't passed, then chaosctl takes input in an interactive mode.
> Only `chaosctl connect chaos-delegate` command needs --non-interactive flag, other commands don't need this flag to be in non-interactive mode. If mandatory flags aren't passed, then chaosctl takes input in an interactive mode.
### Installation modes

chaosctl can install an agent in two different modes.
chaosctl can install a chaos delegate in two different modes.

- cluster mode: With this mode, the agent can run the chaos in any namespace. It installs appropriate cluster roles and cluster role bindings to achieve this mode. It can be enabled by passing a flag `--installation-mode=cluster`
- cluster mode: With this mode, the chaos delegate can run the chaos in any namespace. It installs appropriate cluster roles and cluster role bindings to achieve this mode. It can be enabled by passing a flag `--installation-mode=cluster`

- namespace mode: With this mode, the agent can run the chaos in its namespace. It installs appropriate roles and role bindings to achieve this mode. It can be enabled by passing a flag `--installation-mode=namespace`
- namespace mode: With this mode, the chaos delegate can run the chaos in its namespace. It installs appropriate roles and role bindings to achieve this mode. It can be enabled by passing a flag `--installation-mode=namespace`

Note: With namespace mode, the user needs to create the namespace to install the agent and user must have the admin privileges to setup [CRDs](https://github.com/chaosnative/hce-charts/blob/main/k8s-manifests/ci/hce-crds.yaml) as a prerequisite.
Note: With namespace mode, the user needs to create the namespace to install the chaos delegate and user must have the admin privileges to setup [CRDs](https://github.com/chaosnative/hce-charts/blob/main/k8s-manifests/ci/hce-crds.yaml) as a prerequisite.

#### Prerequisite steps(For namespace mode)

- Create namespace to install the agnet
- Create namespace to install the chaos delegate

```shell
kubectl create ns <namespace_name>
Expand All @@ -45,31 +45,31 @@ kubectl create ns <namespace_name>
kubectl apply -f https://raw.githubusercontent.com/litmuschaos/litmus/master/litmus-portal/litmus-portal-crds.yml
```

### Minimal steps to create an agent
### Minimal steps to connect a chaos delegate

- To setup an account with chaosctl

```shell
chaosctl config set-account --endpoint="" --access_id="" --access_key=""
```

- To create an agent without a project
> Note: If the user doesn't have any project, it will create a random project and add the agent in that random project.
- To connect a chaos delegate without a project
> Note: If the user doesn't have any project, it will create a random project and add the chaos delegate in that random project.
```shell
chaosctl create agent --agent-name="" --non-interactive
chaosctl connect chaos-delegate --name="" --non-interactive
```

### Or,

- To create an agent with an existing project
- To connect a chaos delegate with an existing project
> Note: To get `project-id`. Apply `chaosctl get projects`
```shell
chaosctl create agent --agent-name="" --project-id="" --non-interactive
chaosctl connect chaos-delegate --name="" --project-id="" --non-interactive
```

### Flags for `create agent` command
### Flags for `connect chaos-delegate` command

<table>
<tr>
Expand All @@ -78,34 +78,34 @@ chaosctl create agent --agent-name="" --project-id="" --non-interactive
<th>Type</th>
<th>Description</th>
<tr>
<td>--agent-description</td>
<td>--description</td>
<td></td>
<td>String</td>
<td>Set the agent description (default "---")</td>
<td>Set the chaos delegate description (default "---")</td>
</tr>
<tr>
<td>--agent-name</td>
<td>--name</td>
<td></td>
<td>String</td>
<td>Set the cluster-type to external for external agents | Supported=external/internal (default "external")</td>
<td>Set the chaos-delegate-type to external for external chaos delegates | Supported=external/internal (default "external")</td>
</tr>
<tr>
<td>--skip-agent-ssl</td>
<td>--skip-ssl</td>
<td></td>
<td>Boolean</td>
<td>Set whether agent will skip ssl/tls check (can be used for self-signed certs, if cert is not provided in portal) (default false)</td>
<td>Set whether chaos delegate will skip ssl/tls check (can be used for self-signed certs, if cert is not provided in portal) (default false)</td>
</tr>
<tr>
<td>--cluster-type</td>
<td>--chaos-delegate-type</td>
<td></td>
<td>String</td>
<td>Set the cluster-type to external for external agents | Supported=external/internal (default "external")</td>
<td>Set the chaos-delegate-type to external for external chaos delegates | Supported=external/internal (default "external")</td>
</tr>
<tr>
<td>--installation-mode</td>
<td></td>
<td>String</td>
<td>Set the installation mode for the kind of agent | Supported=cluster/namespace (default "cluster")</td>
<td>Set the installation mode for the kind of chaos delegate | Supported=cluster/namespace (default "cluster")</td>
</tr>
<tr>
<td>--kubeconfig</td>
Expand All @@ -117,13 +117,13 @@ chaosctl create agent --agent-name="" --project-id="" --non-interactive
<td>--namespace</td>
<td></td>
<td>String</td>
<td>Set the namespace for the agent installation (default "litmus")</td>
<td>Set the namespace for the chaos delegate installation (default "litmus")</td>
</tr>
<tr>
<td>--node-selector</td>
<td></td>
<td>String</td>
<td>Set the node-selector for agent components | Format: key1=value1,key2=value2)
<td>Set the node-selector for chaos delegate components | Format: key1=value1,key2=value2)
</tr>
<tr>
<td>--non-interactive</td>
Expand Down Expand Up @@ -153,7 +153,7 @@ chaosctl create agent --agent-name="" --project-id="" --non-interactive
<td>--service-account</td>
<td></td>
<td>String</td>
<td>Set the service account to be used by the agent (default "litmus")</td>
<td>Set the service account to be used by the chaos delegate (default "litmus")</td>
</tr>
<tr>
<td>--config</td>
Expand Down Expand Up @@ -229,18 +229,18 @@ PROJECT ID PROJECT NAME CREATEDAT
7a4a259a-1ae5-4204-ae83-89a8838eaec3 DevOps Project 2021-07-21 14:39:14 +0530 IST
```

- To get an overview of the agents available within a project, issue the following command.
- To get an overview of the chaos delegates available within a project, issue the following command.

```shell
chaosctl get agents --project-id=""
chaosctl get chaos-delegates --project-id=""
```

**Output:**

```
AGENTID AGENTNAME STATUS
55ecc7f2-2754-43aa-8e12-6903e4c6183a agent-1 ACTIVE
13dsf3d1-5324-54af-4g23-5331g5v2364f agent-2 INACTIVE
CHAOS DELEGATE ID CHAOS DELEGATE NAME STATUS
55ecc7f2-2754-43aa-8e12-6903e4c6183a chaos-delegate-1 ACTIVE
13dsf3d1-5324-54af-4g23-5331g5v2364f chaos-delegate-2 INACTIVE
```

For more information related to flags, Use `chaosctl --help`.
Expand Down
34 changes: 17 additions & 17 deletions Usage_interactive.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
chaosctl [command] [TYPE] [flags]
```

- Command: refers to what you do want to perform (create, get and config)
- Command: refers to what you do want to perform (connect, create, get and config)
- Type: refers to the feature type you are performing a command against (chaos-delegate, project etc.)
- Flags: It takes some additional information for resource operations. For example, `--installation-mode` allows you to specify an installation mode.

Expand All @@ -19,17 +19,17 @@ chaosctl is using the `.chaosconfig` config file to manage multiple accounts

chaosctl supports both interactive and non-interactive(flag based) modes.

> Only `chaosctl create agent` command needs --non-interactive flag, other commands don't need this flag to be in non-interactive mode. If mandatory flags aren't passed, then chaosctl takes input in an interactive mode.
> Only `chaosctl connect chaos-delegate` command needs --non-interactive flag, other commands don't need this flag to be in non-interactive mode. If mandatory flags aren't passed, then chaosctl takes input in an interactive mode.
### Steps to connect to an chaos delegate
### Steps to connect to a chaos delegate

- To setup an account with chaosctl

```shell
chaosctl config set-account
```

Next, you need to enter CLC/CLE details to login into your account. Fields to be filled in:
Next, you need to enter Harness Chaos Engineering Cloud/Harness Chaos Engineering Enterprise details to login into your account. Fields to be filled in:

**What's the product name:** Select the product name .

Expand All @@ -40,19 +40,19 @@ Next, you need to enter CLC/CLE details to login into your account. Fields to be

```
? What's the product name?:
ChaosNative Cloud
ChaosNative Enterprise
Harness Chaos Engineering Cloud
Harness Chaos Engineering Enterprise
What's the AccessID?: Raj60163RjxQE
What's the AccessKey?: ***************
account.accessID/admin configured
```

- To connect an chaos delegate in a cluster mode
- To connect a chaos delegate in a cluster mode

```shell
chaosctl create agent
chaosctl connect chaos-delegate
```

There will be a list of existing projects displayed on the terminal. Select the desired project by entering the sequence number indicated against it.
Expand All @@ -64,7 +64,7 @@ There will be a list of existing projects displayed on the terminal. Select the

Next, select the installation mode based on your requirement by entering the sequence number indicated against it.

It can install an chaos delegate in two different modes.
It can install a chaos delegate in two different modes.

- cluster mode: With this mode, the chaos delegate can run the chaos in any namespace. It installs appropriate cluster roles and cluster role bindings to achieve this mode.

Expand Down Expand Up @@ -92,11 +92,11 @@ Fields to be filled in <br />
<th>Field</th>
<th>Description</th>
<tr>
<td>Chaos Delegate Name:</td>
<td>Name:</td>
<td>Enter a name of the chaos delegate which needs to be unique across the project</td>
</tr>
<tr>
<td>Chaos Delegate Description:</td>
<td>Description:</td>
<td>Fill in details about the chaos delegate</td>
</tr>
<tr>
Expand Down Expand Up @@ -230,8 +230,8 @@ CURRENT ENDPOINT ACCESSID EXPIRESIN
chaosctl config use-account

? What's the product name?:
ChaosNative Cloud
ChaosNative Enterprise
Harness Chaos Engineering Cloud
Harness Chaos Engineering Enterprise
What's the AccessID?: Raj60163RjxQE
```
Expand Down Expand Up @@ -261,17 +261,17 @@ PROJECT ID PROJECT NAME CREATEDAT
- To get an overview of the chaos delegates available within a project, issue the following command.

```shell
chaosctl get agents
chaosctl get chaos-delegates

Enter the Project ID: 50addd40-8767-448c-a91a-5071543a2d8e
```

**Output:**

```
AGENTID AGENTNAME STATUS
55ecc7f2-2754-43aa-8e12-6903e4c6183a agent-1 ACTIVE
13dsf3d1-5324-54af-4g23-5331g5v2364f agent-2 INACTIVE
CHAOS DELEGATE ID CHAOS DELEGATE NAME STATUS
55ecc7f2-2754-43aa-8e12-6903e4c6183a chaos-delegate-1 ACTIVE
13dsf3d1-5324-54af-4g23-5331g5v2364f chaos-delegate-2 INACTIVE
```

For more information related to flags, Use `chaosctl --help`.
8 changes: 4 additions & 4 deletions pkg/agent/ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"github.com/manifoldco/promptui"
)

// GetProject display list of projects and returns the project id based on input
// GetProjectID display list of projects and returns the project id based on input
func GetProjectID(u apis.ProjectDetails) string {
var projectNames []string
for _, v := range u.Data.Projects {
Expand All @@ -49,7 +49,7 @@ func GetProjectID(u apis.ProjectDetails) string {
return u.Data.Projects[counter].ID
}

// GetMode gets mode of chaos delegate installation as input
// GetModeType gets mode of chaos delegate installation as input
func GetModeType() string {
prompt := promptui.Select{
Label: "What's the installation mode?",
Expand Down Expand Up @@ -80,11 +80,11 @@ func GetAgentDetails(mode string, pid string, c types.Credentials, kubeconfig *s
)
// Get chaos delegate name as input
utils.White_B.Println("\nEnter the details of the chaos delegate")
// Label for goto statement in case of invalid agent name
// Label for goto statement in case of invalid chaos delegate name

AGENT_NAME:
prompt := promptui.Prompt{
Label: "What's the Chaos Delegate Name?",
Label: "What's the chaos delegate name?",
}

newAgent.AgentName, err = prompt.Run()
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,14 @@ func ConnectAgent(agent types.Agent, cred types.Credentials) (AgentConnectionDat
bodyBytes, err := ioutil.ReadAll(resp.Body)
defer resp.Body.Close()
if err != nil {
return AgentConnectionData{}, errors.New("Error in registering Chaos Delegate: " + err.Error())
return AgentConnectionData{}, errors.New("Error in registering chaos delegate: " + err.Error())
}

if resp.StatusCode == http.StatusOK {
var connectAgent AgentConnectionData
err = json.Unmarshal(bodyBytes, &connectAgent)
if err != nil {
return AgentConnectionData{}, errors.New("Error in registering Chaos Delegate: " + err.Error())
return AgentConnectionData{}, errors.New("Error in registering chaos delegate: " + err.Error())
}

if len(connectAgent.Errors) > 0 {
Expand Down
Loading

0 comments on commit afe2780

Please sign in to comment.