> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/argoproj/argo-cd/llms.txt
> Use this file to discover all available pages before exploring further.

# Cluster Service

> gRPC API reference for ClusterService - CRUD operations for Argo CD cluster configurations

# Cluster Service

Cluster Service API performs CRUD actions against cluster resources.

## Service Definition

**Package:** `cluster`

**Service:** `ClusterService`

The ClusterService manages Kubernetes cluster configurations that Argo CD uses to deploy applications.

## RPC Methods

### List

Returns list of clusters.

**Request:** `ClusterQuery`

<ParamField path="server" type="string">
  The cluster server URL
</ParamField>

<ParamField path="name" type="string">
  The cluster name
</ParamField>

<ParamField path="id" type="ClusterID">
  The cluster identifier (type and value)
</ParamField>

**Response:** `ClusterList`

**REST Endpoint:** `GET /api/v1/clusters`

***

### Get

Returns a cluster by server address or name.

**Request:** `ClusterQuery`

<ParamField path="server" type="string">
  The cluster server URL
</ParamField>

<ParamField path="name" type="string">
  The cluster name
</ParamField>

<ParamField path="id" type="ClusterID">
  The cluster identifier
</ParamField>

**ClusterID Fields:**

<ParamField path="id.type" type="string">
  The type of the specified cluster identifier ("server" - default, "name")
</ParamField>

<ParamField path="id.value" type="string">
  The cluster server URL or cluster name
</ParamField>

**Response:** `Cluster`

**REST Endpoint:** `GET /api/v1/clusters/{id.value}`

***

### Create

Creates a cluster.

**Request:** `ClusterCreateRequest`

<ParamField path="cluster" type="Cluster" required>
  The cluster configuration to create
</ParamField>

<ParamField path="upsert" type="bool">
  Whether to create or update the cluster if it already exists
</ParamField>

**Response:** `Cluster`

**REST Endpoint:** `POST /api/v1/clusters`

***

### Update

Updates a cluster.

**Request:** `ClusterUpdateRequest`

<ParamField path="cluster" type="Cluster" required>
  The cluster configuration to update
</ParamField>

<ParamField path="updatedFields" type="string[]">
  List of fields to update (allows partial updates)
</ParamField>

<ParamField path="id" type="ClusterID">
  The cluster identifier
</ParamField>

**Response:** `Cluster`

**REST Endpoint:** `PUT /api/v1/clusters/{id.value}`

***

### Delete

Deletes a cluster.

**Request:** `ClusterQuery`

<ParamField path="server" type="string">
  The cluster server URL
</ParamField>

<ParamField path="name" type="string">
  The cluster name
</ParamField>

<ParamField path="id" type="ClusterID" required>
  The cluster identifier
</ParamField>

**Response:** `ClusterResponse`

**REST Endpoint:** `DELETE /api/v1/clusters/{id.value}`

***

### RotateAuth

Rotates the bearer token used for a cluster.

**Request:** `ClusterQuery`

<ParamField path="id" type="ClusterID" required>
  The cluster identifier
</ParamField>

**Response:** `ClusterResponse`

**REST Endpoint:** `POST /api/v1/clusters/{id.value}/rotate-auth`

***

### InvalidateCache

Invalidates cluster cache.

**Request:** `ClusterQuery`

<ParamField path="id" type="ClusterID" required>
  The cluster identifier
</ParamField>

**Response:** `Cluster`

**REST Endpoint:** `POST /api/v1/clusters/{id.value}/invalidate-cache`

***

## gRPC Example

```go theme={null}
import (
    "context"
    "google.golang.org/grpc"
    clusterpkg "github.com/argoproj/argo-cd/v3/pkg/apiclient/cluster"
    "github.com/argoproj/argo-cd/v3/pkg/apis/application/v1alpha1"
)

// Create a gRPC connection
conn, err := grpc.Dial("argocd-server:443", grpc.WithInsecure())
if err != nil {
    log.Fatal(err)
}
defer conn.Close()

// Create cluster service client
client := clusterpkg.NewClusterServiceClient(conn)

// List clusters
clusters, err := client.List(context.Background(), &clusterpkg.ClusterQuery{})
if err != nil {
    log.Fatal(err)
}

// Get a specific cluster by name
cluster, err := client.Get(context.Background(), &clusterpkg.ClusterQuery{
    Id: &clusterpkg.ClusterID{
        Type:  "name",
        Value: "my-cluster",
    },
})
if err != nil {
    log.Fatal(err)
}

// Create a new cluster
newCluster := &v1alpha1.Cluster{
    Server: "https://kubernetes.default.svc",
    Name:   "in-cluster",
    Config: v1alpha1.ClusterConfig{
        TLSClientConfig: v1alpha1.TLSClientConfig{
            Insecure: false,
        },
    },
}

createdCluster, err := client.Create(context.Background(), &clusterpkg.ClusterCreateRequest{
    Cluster: newCluster,
    Upsert:  false,
})
if err != nil {
    log.Fatal(err)
}

// Invalidate cluster cache
_, err = client.InvalidateCache(context.Background(), &clusterpkg.ClusterQuery{
    Id: &clusterpkg.ClusterID{
        Type:  "name",
        Value: "my-cluster",
    },
})
if err != nil {
    log.Fatal(err)
}
```
