> For the complete documentation index, see [llms.txt](https://greymatter.gitbook.io/grey-matter-documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://greymatter.gitbook.io/grey-matter-documentation/setup/fabric/gm-control/load_from_static_resources.md).

# Static Resources

* [Loading GM-Control From Static Resources](/grey-matter-documentation/setup/fabric/gm-control/load_from_static_resources.md#loading-gm-control-from-static-resources)
  * [Static File](/grey-matter-documentation/setup/fabric/gm-control/load_from_static_resources.md#static-file)
    * [Configuration](/grey-matter-documentation/setup/fabric/gm-control/load_from_static_resources.md#configuration)
    * [API](/grey-matter-documentation/setup/fabric/gm-control/load_from_static_resources.md#api)
    * [Cluster Templates](/grey-matter-documentation/setup/fabric/gm-control/load_from_static_resources.md#cluster-templates)
  * [Local Clusters](/grey-matter-documentation/setup/fabric/gm-control/load_from_static_resources.md#local-clusters)
    * [Examples](/grey-matter-documentation/setup/fabric/gm-control/load_from_static_resources.md#examples)

## Static File

GM-Control has the ability to read in raw envoy clusters and listeners from a static file on startup. This is different from file discovery, which continually reads and writes to the file dynamically during runtime has has a [different api](https://github.com/greymatter-io/gm-control/blob/release-1.2/plugins/file/file.go#L34-L71). Static configs can be combined with discovery (see `--xds.static-resources.conflict-behavior`), but are themselves read only, and read in once at configuration time.

### Configuration

Static file configs are read in from the following configuration values:

| **Command Line Flag**                      | Environment Variable                                | Meaning                                                | Values                                                                                                                                                       |
| ------------------------------------------ | --------------------------------------------------- | ------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `--xds.static-resources.filename`          | `GM_CONTROL_XDS_STATIC_RESOURCES_FILENAME`          | The path of the filename to read in as a static config | `/path/to/file.type`                                                                                                                                         |
| `--xds.static-resources.format`            | `GM_CONTROL_XDS_STATIC_RESOURCES_FORMAT`            | Type of file                                           | `json` or `yaml` (default)                                                                                                                                   |
| `--xds.static-resources.conflict-behavior` | `GM_CONTROL_XDS_STATIC_RESOURCES_CONFLICT_BEHAVIOR` | How to handle conflicts with cluster discovery         | `overwrite` (static config overwrites all other configuration on startup) or `merge` (use static configuration when a config collision is detected, default) |

### API

The static resource configuration has the following API:

| **Name**          | Type                                                                                                              | Meaning                                   |
| ----------------- | ----------------------------------------------------------------------------------------------------------------- | ----------------------------------------- |
| `clusters`        | Array of [envoy cluster](https://www.envoyproxy.io/docs/envoy/v1.12.0/api-v2/api/v2/cds.proto)                    | list of upstream clusters.                |
| `clusterTemplate` | [envoy cluster](https://www.envoyproxy.io/docs/envoy/v1.12.0/api-v2/api/v2/eds.proto#clusterloadassignment)       |                                           |
| `listeners`       | Array of [envoy listener](https://www.envoyproxy.io/docs/envoy/v1.12.0/api-v2/api/v2/lds.proto)                   | list of listeners to apply to proxies.    |
| `loadAssignments` | Array of [envoy load assignment](https://godoc.org/github.com/cilium/proxy/go/envoy/api/v2#ClusterLoadAssignment) | List of endpoints to match to a `cluster` |

### Cluster Templates

Instead of defining a large number of clusters statically, specifying a `clusterTemplate` attribute provides a base structure which is filled in by each cluster definition in `clusters`. A full example of this is available in the [`static_resources_test.go` file](https://github.com/greymatter-io/gm-control/blob/release-1.2/xds/adapter/static_resources_test.go#L202-L322).

## Local Clusters

GM-Control provides a quick and easy utility to specify [envoy clusters](https://www.envoyproxy.io/docs/envoy/v1.12.0/api-v2/api/v2/cds.proto) and [load assignments](https://godoc.org/github.com/cilium/proxy/go/envoy/api/v2#ClusterLoadAssignment) for hosts running on the same host as control (i.e. running on localhost). It This can be useful for testing locally when running everything in a development environment on the same machine. This should not be used for a production environment.

### Examples

To enable loading of local clusters, set the environment variable `GM_CONTROL_LOCAL_CLUSTERS` to a comma delimited string of `cluster_name:port`. Here is an example:

```bash
GM_CONTROL_LOCAL_CLUSTERS=gm-proxy:8080
```

This will create a pre-canned config for the `gm-proxy` cluster and import it into gm-control with the host `127.0.0.1:8080`. The whole cluster config is listed below:

```javascript
{
  "clusters": [
    {
      "name": "gm-proxy",
      "type": "EDS",
      "edsClusterConfig": {
        "edsConfig": {
          "apiConfigSource": {
            "apiType": "GRPC",
            "grpcServices": [
              {
                "envoyGrpc": {
                  "clusterName": "tbn-xds"
                }
              }
            ],
            "refreshDelay": "30s"
          }
        },
        "serviceName": "gm-proxy"
      },
      "connectTimeout": "10s",
      "lbPolicy": "LEAST_REQUEST",
      "lbSubsetConfig": {
        "fallbackPolicy": "ANY_ENDPOINT"
      }
    }
  ],
  "loadAssignments": [
    {
      "clusterName": "gm-proxy",
      "endpoints": [
        {
          "lbEndpoints": [
            {
              "endpoint": {
                "address": {
                  "socketAddress": {
                    "address": "127.0.0.1",
                    "portValue": 8080
                  }
                }
              },
              "healthStatus": "HEALTHY"
            }
          ]
        }
      ]
    }
  ]
}
```
