|
| 1 | +--- |
| 2 | +id: litmusctl-syntax |
| 3 | +title: Litmusctl Syntax |
| 4 | +sidebar_label: Litmusctl Syntax |
| 5 | +--- |
| 6 | + |
| 7 | +# Litmusctl Syntax |
| 8 | + |
| 9 | +## Overview |
| 10 | + |
| 11 | +`litmusctl` is a command-line tool for managing LitmusChaos infrastructure plane. It follows a structured syntax pattern that makes it intuitive to use for various chaos engineering operations. |
| 12 | + |
| 13 | +## Basic Syntax |
| 14 | + |
| 15 | +```bash |
| 16 | +litmusctl [command] [TYPE] [flags] |
| 17 | +``` |
| 18 | + |
| 19 | +### Components |
| 20 | + |
| 21 | +- **Command**: Specifies the operation you want to perform (e.g., `connect`, `create`, `get`, `config`, `disconnect`, `run`, `update`) |
| 22 | +- **Type**: Refers to the resource type you're operating on (e.g., `chaos-infra`, `project`, `chaos-experiment`, `chaos-environment`) |
| 23 | +- **Flags**: Additional parameters that provide specific information for the operation (e.g., `--project-id`, `--non-interactive`, `--config`) |
| 24 | + |
| 25 | +## Available Commands |
| 26 | + |
| 27 | +### 1. `config` - Configuration Management |
| 28 | + |
| 29 | +Manage litmusctl accounts and configuration settings. |
| 30 | + |
| 31 | +#### Subcommands |
| 32 | + |
| 33 | +**Set Account** |
| 34 | +```bash |
| 35 | +litmusctl config set-account |
| 36 | +``` |
| 37 | +Configure a new ChaosCenter account with endpoint, username, and password. |
| 38 | + |
| 39 | +**Use Account** |
| 40 | +```bash |
| 41 | +litmusctl config use-account --endpoint="<endpoint-url>" --username="<username>" |
| 42 | +``` |
| 43 | +Switch between multiple configured accounts. |
| 44 | + |
| 45 | +**Get Accounts** |
| 46 | +```bash |
| 47 | +litmusctl config get-accounts |
| 48 | +``` |
| 49 | +List all configured accounts in `.litmusconfig`. |
| 50 | + |
| 51 | +**View Configuration** |
| 52 | +```bash |
| 53 | +litmusctl config view |
| 54 | +``` |
| 55 | +Display current `.litmusconfig` settings. |
| 56 | + |
| 57 | +--- |
| 58 | + |
| 59 | +### 2. `connect` - Connect Resources |
| 60 | + |
| 61 | +Establish connections to chaos resources. |
| 62 | + |
| 63 | +**Connect Chaos Infrastructure** |
| 64 | +```bash |
| 65 | +litmusctl connect chaos-infra |
| 66 | +``` |
| 67 | + |
| 68 | +**Flags:** |
| 69 | +- `--project-id`: Specify the project ID |
| 70 | +- `--environment-id`: Specify the environment ID |
| 71 | +- `--non-interactive`: Enable non-interactive mode (all required information must be provided via flags) |
| 72 | +- `--installation-mode`: Installation mode (`cluster` or `namespace`) |
| 73 | +- `--chaos-infra-name`: Name for the chaos infrastructure |
| 74 | +- `--chaos-infra-description`: Description for the chaos infrastructure |
| 75 | +- `--platform-name`: Platform name (AWS, GKE, Openshift, Rancher, Others) |
| 76 | +- `--namespace`: Kubernetes namespace for installation |
| 77 | +- `--service-account`: Service account name |
| 78 | +- `--skip-ssl`: Skip SSL/TLS verification (true/false) |
| 79 | +- `--node-selector`: Node selector for deployments |
| 80 | + |
| 81 | +**Example (Non-interactive mode):** |
| 82 | +```bash |
| 83 | +litmusctl connect chaos-infra \ |
| 84 | + --project-id="<project-id>" \ |
| 85 | + --environment-id="<environment-id>" \ |
| 86 | + --chaos-infra-name="my-chaos-infra" \ |
| 87 | + --installation-mode="cluster" \ |
| 88 | + --non-interactive |
| 89 | +``` |
| 90 | + |
| 91 | +--- |
| 92 | + |
| 93 | +### 3. `disconnect` - Disconnect Resources |
| 94 | + |
| 95 | +Disconnect chaos resources from ChaosCenter. |
| 96 | + |
| 97 | +**Disconnect Chaos Infrastructure** |
| 98 | +```bash |
| 99 | +litmusctl disconnect chaos-infra <chaos-infra-id> --project-id="<project-id>" |
| 100 | +``` |
| 101 | + |
| 102 | +**Example:** |
| 103 | +```bash |
| 104 | +litmusctl disconnect chaos-infra 13dsf3d1-5324-54af-4g23-5331g5v2364f --project-id="50addd40-8767-448c-a91a-5071543a2d8e" |
| 105 | +``` |
| 106 | + |
| 107 | +--- |
| 108 | + |
| 109 | +### 4. `create` - Create Resources |
| 110 | + |
| 111 | +Create new projects, experiments, and environments. |
| 112 | + |
| 113 | +**Create Project** |
| 114 | +```bash |
| 115 | +litmusctl create project --name="<project-name>" |
| 116 | +``` |
| 117 | + |
| 118 | +**Create Chaos Environment** |
| 119 | +```bash |
| 120 | +litmusctl create chaos-environment |
| 121 | +``` |
| 122 | +You will be prompted for: |
| 123 | +- Project ID |
| 124 | +- Environment Name |
| 125 | +- Environment Type (Production/Non-Production) |
| 126 | + |
| 127 | +**Create Chaos Experiment** |
| 128 | +```bash |
| 129 | +litmusctl create chaos-experiment -f <experiment-manifest.yml> --project-id="<project-id>" --chaos-infra-id="<chaos-infra-id>" |
| 130 | +``` |
| 131 | + |
| 132 | +**Flags:** |
| 133 | +- `-f`: Path to experiment manifest file |
| 134 | +- `--project-id`: Target project ID |
| 135 | +- `--chaos-infra-id`: Target chaos infrastructure ID |
| 136 | + |
| 137 | +**Example:** |
| 138 | +```bash |
| 139 | +litmusctl create chaos-experiment \ |
| 140 | + -f custom-chaos-experiment.yml \ |
| 141 | + --project-id="eb7fc0a0-5878-4454-a9db-b67d283713bc" \ |
| 142 | + --chaos-infra-id="e7eb0386-085c-49c2-b550-8d85b58fd" |
| 143 | +``` |
| 144 | + |
| 145 | +--- |
| 146 | + |
| 147 | +### 5. `get` - Retrieve Information |
| 148 | + |
| 149 | +Query and list various resources. |
| 150 | + |
| 151 | +**Get Projects** |
| 152 | +```bash |
| 153 | +litmusctl get projects |
| 154 | +``` |
| 155 | +Lists all projects accessible to the user with their IDs, names, and creation timestamps. |
| 156 | + |
| 157 | +**Get Chaos Infrastructures** |
| 158 | +```bash |
| 159 | +litmusctl get chaos-infra |
| 160 | +``` |
| 161 | +You will be prompted for the Project ID. Returns infrastructure ID, name, and status. |
| 162 | + |
| 163 | +**Get Chaos Environments** |
| 164 | +```bash |
| 165 | +litmusctl get chaos-environment |
| 166 | +``` |
| 167 | +Lists chaos environments with their IDs, names, types, and timestamps. |
| 168 | + |
| 169 | +**Get Chaos Experiments** |
| 170 | +```bash |
| 171 | +litmusctl get chaos-experiments |
| 172 | +``` |
| 173 | +Lists chaos experiments within a project. |
| 174 | + |
| 175 | +--- |
| 176 | + |
| 177 | +### 6. `run` - Execute Operations |
| 178 | + |
| 179 | +Execute chaos experiments and other operations. |
| 180 | + |
| 181 | +**Run Chaos Experiment** |
| 182 | +```bash |
| 183 | +litmusctl run chaos-experiment |
| 184 | +``` |
| 185 | +You will be prompted for: |
| 186 | +- Project ID |
| 187 | +- Chaos Experiment ID |
| 188 | + |
| 189 | +**Example:** |
| 190 | +```bash |
| 191 | +litmusctl run chaos-experiment |
| 192 | +# Enter the Project ID: eb7fc0a0-5878-4454-a9db-b67d283713bc |
| 193 | +# Enter the Chaos Experiment ID: test_exp |
| 194 | +``` |
| 195 | + |
| 196 | +--- |
| 197 | + |
| 198 | +### 7. `update` - Update Resources |
| 199 | + |
| 200 | +Modify existing resources and settings. |
| 201 | + |
| 202 | +**Update Password** |
| 203 | +```bash |
| 204 | +litmusctl update password |
| 205 | +``` |
| 206 | +Change the password for your ChaosCenter account. You will be prompted for: |
| 207 | +- Username |
| 208 | +- Old Password |
| 209 | +- New Password |
| 210 | +- Confirm Password |
| 211 | + |
| 212 | +--- |
| 213 | + |
| 214 | +### 8. `version` - Version Information |
| 215 | + |
| 216 | +**Check Version** |
| 217 | +```bash |
| 218 | +litmusctl version |
| 219 | +``` |
| 220 | +Display the current version of litmusctl. |
| 221 | + |
| 222 | +--- |
| 223 | + |
| 224 | +## Global Flags |
| 225 | + |
| 226 | +These flags can be used with most commands: |
| 227 | + |
| 228 | +- `--config`: Specify a custom config file path (default: `${HOME}/.litmusconfig`) |
| 229 | +- `--help` or `-h`: Display help information for any command |
| 230 | + |
| 231 | +--- |
| 232 | + |
| 233 | +## Interactive vs Non-Interactive Mode |
| 234 | + |
| 235 | +### Interactive Mode |
| 236 | +By default, litmusctl operates in interactive mode where it prompts you for required information. |
| 237 | + |
| 238 | +```bash |
| 239 | +litmusctl connect chaos-infra |
| 240 | +# Will prompt for all required details |
| 241 | +``` |
| 242 | + |
| 243 | +### Non-Interactive Mode |
| 244 | +Use the `--non-interactive` flag along with all required flags to run commands without prompts. |
| 245 | + |
| 246 | +```bash |
| 247 | +litmusctl connect chaos-infra \ |
| 248 | + --project-id="<project-id>" \ |
| 249 | + --environment-id="<environment-id>" \ |
| 250 | + --chaos-infra-name="my-infra" \ |
| 251 | + --non-interactive |
| 252 | +``` |
| 253 | + |
| 254 | +**Note:** Only `litmusctl connect chaos-infra` requires the `--non-interactive` flag. Other commands automatically use non-interactive mode when all required flags are provided. |
| 255 | + |
| 256 | +--- |
| 257 | + |
| 258 | +## Configuration File |
| 259 | + |
| 260 | +litmusctl uses the `.litmusconfig` file to manage multiple accounts: |
| 261 | + |
| 262 | +- **Default Location:** `${HOME}/.litmusconfig` |
| 263 | +- **Custom Location:** Use `--config` flag to specify a different location |
| 264 | +- **No Merging:** If `--config` is specified, only that file is loaded (no merging with default config) |
| 265 | + |
| 266 | +--- |
| 267 | + |
| 268 | +## Common Workflows |
| 269 | + |
| 270 | +### Initial Setup |
| 271 | +```bash |
| 272 | +# 1. Configure your account |
| 273 | +litmusctl config set-account |
| 274 | + |
| 275 | +# 2. View configured accounts |
| 276 | +litmusctl config get-accounts |
| 277 | + |
| 278 | +# 3. Create or select a project |
| 279 | +litmusctl create project --name="my-project" |
| 280 | +litmusctl get projects |
| 281 | +``` |
| 282 | + |
| 283 | +### Connecting Infrastructure |
| 284 | +```bash |
| 285 | +# 1. Create an environment (if needed) |
| 286 | +litmusctl create chaos-environment |
| 287 | + |
| 288 | +# 2. Connect chaos infrastructure |
| 289 | +litmusctl connect chaos-infra |
| 290 | + |
| 291 | +# 3. Verify connection |
| 292 | +litmusctl get chaos-infra |
| 293 | +``` |
| 294 | + |
| 295 | +### Running Experiments |
| 296 | +```bash |
| 297 | +# 1. Create experiment |
| 298 | +litmusctl create chaos-experiment -f experiment.yml --project-id="<id>" --chaos-infra-id="<id>" |
| 299 | + |
| 300 | +# 2. Run experiment |
| 301 | +litmusctl run chaos-experiment |
| 302 | + |
| 303 | +# 3. List experiments |
| 304 | +litmusctl get chaos-experiments |
| 305 | +``` |
| 306 | + |
| 307 | +--- |
| 308 | + |
| 309 | +## Examples |
| 310 | + |
| 311 | +### Example 1: Complete Setup in Non-Interactive Mode |
| 312 | +```bash |
| 313 | +# Set account |
| 314 | +litmusctl config set-account \ |
| 315 | + --endpoint="https://chaos.example.com" \ |
| 316 | + --username="admin" \ |
| 317 | + --password="password" |
| 318 | + |
| 319 | +# Create project |
| 320 | +litmusctl create project --name="production-chaos" |
| 321 | + |
| 322 | +# Get project ID |
| 323 | +litmusctl get projects |
| 324 | + |
| 325 | +# Connect infrastructure |
| 326 | +litmusctl connect chaos-infra \ |
| 327 | + --project-id="50addd40-8767-448c-a91a-5071543a2d8e" \ |
| 328 | + --environment-id="prod-env" \ |
| 329 | + --chaos-infra-name="prod-cluster-1" \ |
| 330 | + --installation-mode="cluster" \ |
| 331 | + --platform-name="GKE" \ |
| 332 | + --namespace="litmus" \ |
| 333 | + --non-interactive |
| 334 | +``` |
| 335 | + |
| 336 | +### Example 2: Interactive Workflow |
| 337 | +```bash |
| 338 | +# Configure account interactively |
| 339 | +litmusctl config set-account |
| 340 | +# Follow prompts for endpoint, username, password |
| 341 | + |
| 342 | +# Connect infrastructure interactively |
| 343 | +litmusctl connect chaos-infra |
| 344 | +# Follow prompts for all required details |
| 345 | + |
| 346 | +# Create and run experiment interactively |
| 347 | +litmusctl create chaos-experiment -f my-experiment.yml |
| 348 | +# Follow prompts for project-id and chaos-infra-id |
| 349 | + |
| 350 | +litmusctl run chaos-experiment |
| 351 | +# Follow prompts for project-id and experiment-id |
| 352 | +``` |
| 353 | + |
| 354 | +--- |
| 355 | + |
| 356 | +## Additional Resources |
| 357 | + |
| 358 | +- For detailed usage examples, refer to the [litmusctl usage documentation](/docs/next/litmusctl/litmusctl-usage) |
| 359 | +- For installation instructions, see the [litmusctl installation guide](/docs/next/litmusctl/installation) |
| 360 | +- [Contribute to litmusctl](https://github.com/litmuschaos/litmusctl) |
0 commit comments