> ## Documentation Index
> Fetch the complete documentation index at: https://docs.streamnative.io/llms.txt
> Use this file to discover all available pages before exploring further.

# snctl Quick Reference

This page contains a list of commonly used `snctl` commands and flags.

## `snctl` autocomplete

### BASH

```bash theme={null}
source <(snctl completion bash) # set up autocomplete in bash into the current shell, bash-completion package should be installed first.
echo "source <(snctl completion bash)" >> ~/.bashrc # add autocomplete permanently to your bash shell.
```

You can also use a shorthand alias for snctl that also works with completion:

```bash theme={null}
alias sn=snctl
complete -o default -F \_\_start_snctl sn
```

### ZSH

```zsh theme={null}
source <(snctl completion zsh)  # set up autocomplete in zsh into the current shell
echo '[[ $commands[snctl] ]] && source <(snctl completion zsh)' >> ~/.zshrc # add autocomplete permanently to your zsh shell
```

## `snctl` apply

`apply` manages resources through files defining StreamNative Cloud resources. It creates and updates StreamNative Cloud resources through running `snctl apply`. This is recommended way of managing StreamNative Cloud resources in production.

## Creating and updating resources

The manifests of StreamNative Cloud resources can be defined in YAML or JSON. The file extension `.yaml`, `.yml`, and `.json` can be used.

```bash theme={null}
snctl apply -f ./my-manifest.yaml         # create resource(s)
snctl apply -f ./my1.yaml -f ./my2.yaml   # create from multiple files
snctl apply -f ./dir                      # create resource(s) in all manifest files in dir

# Create multiple resource(s) from stdin
snctl apply -f - <<EOF
apiVersion: cloud.streamnative.io/v1alpha1
kind: User
metadata:
  name: john.doe@test.local
  namespace: myorg
spec:
  email: john.doe@test.local
  name:
    first: John
    last: Doe
  type: external

---

apiVersion: cloud.streamnative.io/v1alpha1
kind: RoleBinding
metadata:
  name: john.doe@test.local
  namespace: myorg
spec:
  roleRef:
    apiGroup: cloud.streamnative.io
    kind: ClusterRole
    name: admin
  subjects:
    - apiGroup: cloud.streamnative.io
      kind: User
      name: john.doe@test.local
EOF
```

## Viewing and finding resources

```bash theme={null}
snctl get pulsarclusters                      # List all pulsar clusters in the organization
snctl get pulsarclusters mycluster            # List a particular pulsar cluster
snctl get puslarclusters mycluster -o yaml    # Get the manifest of a pulsar cluster

# Describe commands with verbose output
snctl describe pulsarcluster mycluster

# List Pulsar Clusters Sorted by Creation Time
snctl get pulsarclusters --sort-by=.metadata.creationTimestamp

# Show labels for all clusters (or any other StreamNative Cloud object that supports labelling)
snctl get pulsarclusters --show-labels

# Get the Pulsar Clusters with label app=myapp
snctl get pulsarclusters --selector=app=myapp

# Check which Pulsar Clusters are ready and their locations with custom-columns
snctl get pulsarclusters -o custom-columns='CLUSTER NAME:.metadata.name,LOCATION:.spec.location,STATUS:.status.conditions[?(@.type=="Ready")].status'
```

## Deleting resources

```bash theme={null}
snctl delete -f ./sa.yaml                     # Delete a service account using the type and name specified in sa.yaml
snctl delete pulsarcluster unwanted --now     # Delete a pulsar cluster with no grace period
snctl delete user,rolebinding baz foo         # Delete user and rolebinding with same names "baz" and "foo"
snctl delete user,rolebinding -l name=myLabel # Delete usersand rolebindings with label name=myLabel
```

## Resource types

List all supported resource types along with their shortnames, API group, whether they are namespaced (organizational scoped), and kind.

```bash theme={null}
snctl api-resources
```

## Service Context Management

Manage and use service contexts to interact with Pulsar and Kafka clusters via `snctl`. The active context determines the target cluster for `pulsar` and `kafka` commands.

```bash theme={null}
# Context Switching & Viewing
snctl context use <cluster-name>          # Set the active Service Context (typically the Pulsar cluster name)
snctl context current                     # Show the currently active Service Context

# Interacting with the Active Context's Cluster
snctl pulsar client ...   # Act as pulsar client on the active cluster
snctl pulsar admin ...            # Run pulsar admin commands on the active cluster
snctl kafka client ...    # Act as kafka client on the active cluster
snctl kafka admin ...             # Run kafka admin commands on the active cluster

# Running Commands as a Service Account (Overrides context's user auth)
snctl pulsar admin namespaces list --as-service-account <sa-name> # Run command as specific SA
snctl kafka admin groups list --use-service-account              # Interactively select an SA to run as
```
