# Introduction

Cluster-agent is the agent for cluster management, deployed in dataplane alongside with the corresponding TC and running
on admin nodes.

# Howto

## Development

1. optional Change [API definition](./api/v1/services.proto) and run `make generate-proto` to regenerate
2. Make changes in [Service implement](./service)
3. Run cluster-agent on your laptop or within docker

```bash
# directly run on laptop
make local-run

# or run cluster-agent within docker
make docker-run

# or run cluster-agent in KinD
make e2e && kind export kubeconfig --name=kind
```

4. Make requests to cluster-agent

```bash
# install httpie CLI tool: https://httpie.io/docs/cli/installation
# ping healthz endpoint
http localhost:8080/healthz
```

```bash
# run tikv-ctl command
http localhost:8080/api/v1/clusters/3841732:executeCommand command='tikv-ctl help'

http localhost:8080/api/v1/clusters/3841732:executeCommand command='tikv-ctl --host db-tikv-0.db-tikv-peer.tidb3841732:20160 cluster'
```

```bash
# run pd-ctl command
http localhost:8080/api/v1/clusters/3841732:executeCommand command='pd-ctl help'

http localhost:8080/api/v1/clusters/3841732:executeCommand command='pd-ctl -u https://db-pd-0.db-pd-peer.tidb3841732:2379 cluster'
```

## Deployment

After finished code and debug locally, you would want to deploy it in a real env.

1. Build and push cluster-agent image, run `make local-build-and-push`
2. Replace the image of cluster-agent
   in [root-config-eks-dev.yaml](../cluster-controller/examples/eks-provider/root-config-eks-dev.yaml)
   or [root-config-gke-dev.yaml](../cluster-controller/examples/eks-provider/root-config-gke-dev.yaml), depending on
   which one you are using.
3. Run eks/gke-provider locally and wait the ClusterAgent task to be finished
4. See whether the cluster-agent Deployment in your dataplane namespace updated
