# Lake spec and handler API

URL: /docs/develop/services/lake/spec

Every field of Lake, then the methods a handler calls on ctx.lake.

This page lists the spec and status fields of Lake, each with its type, its limits and its description. The [Platform page](/docs/platform/services/lake.md) explains the concept, and the `metadata` of every kind is [the same](/docs/develop/common-definitions.md#objectmeta).

## Lake [#lake]

```yaml
apiVersion: funcd.io/v1alpha1
kind: Lake
metadata:
  name: analytics
  namespace: default
  resourceGroup: rg1
spec:
  buckets:
    - name: warehouse
      prefixes:
        - name: tables
  secrets:
    - name: lake-token
      keys:
        - QUACK_TOKEN
  bindings:
    blob:
      - alias: tables
        bucket: warehouse
        prefix: tables
    secret:
      - lake-token
  location:
    bucket: warehouse
    prefix: tables
```

| apiVersion | kind |
| --- | --- |
| `funcd.io/v1alpha1` | `Lake` |

### `Lake.spec` [#lakespec]

| Field | Type and limits | Description |
| --- | --- | --- |
| `bindings` | object, [`Lake.spec.bindings`](#lakespecbindings), required | What the Lake's engine uses: Bucket prefixes, and the ConfigMaps and Secrets of its environment. |
| `buckets` | array of [`Lake.spec.buckets[]`](#lakespecbuckets) | The Buckets that a Lake applied on its own declares: by name the Lake creates the Bucket, an omitted prefix owner being the Lake, and a Bucket of that name that is not the Lake's holds it in Pending with StoreNotOwned; by ref it binds an existing one. Each Bucket that the Lake's bindings.blob names must be declared here. A lake that another resource declares sets none. |
| `configMaps` | array of [`Lake.spec.configMaps[]`](#lakespecconfigmaps) | The ConfigMaps that a Lake applied on its own declares: by name the Lake defines one, and a ConfigMap of its stored name that is not the Lake's holds it in Pending with StoreNotOwned; by ref it binds an existing one. Each ConfigMap that the Lake's bindings.config names must be declared here. A lake that another resource declares sets none. |
| `ingress` | object, [`Lake.spec.ingress`](#lakespecingress) | Exposes the Lake gateway at the edge, only when enabled is true and while the Lake is Ready. The path defaults to /lake/&lt;name&gt;, or / with a host. Setting auth is refused, since the Lake gateway checks each caller itself. |
| `location` | object, [`Lake.spec.location`](#lakespeclocation), required | The Bucket prefix that holds the Lake's files, one of the Lake's bindings.blob. The Lake waits in Pending, with the reason PrefixNotOwned, until the prefix's owner is this Lake. The Lake's catalog is kept outside the Bucket, under the same location, so a Lake located where another was finds that Lake's files and catalog. |
| `resources` | object, [`Lake.spec.resources`](#lakespecresources) | The cpu and memory of the Lake's engine. An empty cpu or memory sets no limit on it, and a change replaces the running engine. |
| `secrets` | array of [`Lake.spec.secrets[]`](#lakespecsecrets) | The Secrets that a Lake applied on its own declares, with the keys its engine reads. Each Secret that the Lake's bindings.secret names must be declared here, and the Lake waits in Pending, with SecretNotFound or SecretKeyMissing, while one is missing or lacks a key. A lake that another resource declares sets none. |

### `Lake.spec.bindings` [#lakespecbindings]

| Field | Type and limits | Description |
| --- | --- | --- |
| `blob` | array of [`Lake.spec.bindings.blob[]`](#lakespecbindingsblob), required | The Bucket prefixes the engine may read, each under an alias. It writes only a prefix whose owner is this Lake, and the Lake's location must be one of them. |
| `config` | array of string values, each a DNS-1123 label | ConfigMaps whose data the engine gets as environment variables. Only QUACK_TOKEN and the DUCKDB\_ keys pass, DUCKDB_EXTENSION_DIRECTORY excepted, and a bound Secret's value wins over a ConfigMap's for the same key. A missing ConfigMap holds the Lake in Pending, with the reason BindingResolveFailed. |
| `secret` | array of string values, each a DNS-1123 label | Secrets whose data the engine gets as environment variables, such as its QUACK_TOKEN; the same keys pass as for config. funcd asks Cedar, as the Lake, for secret::read on each: a forbidden Secret holds the Lake in Pending, with the reason BindingResolveFailed, as does a missing one in a lake that another resource declares. A changed value replaces the engine. |

### `Lake.spec.bindings.blob[]` [#lakespecbindingsblob]

| Field | Type and limits | Description |
| --- | --- | --- |
| `alias` | string, required, a DNS-1123 label | The binding's name, unique in the list; code that reaches the prefix through ctx.blob passes it. |
| `bucket` | string, required, a DNS-1123 label | The Bucket, in the same namespace, that holds the prefix. |
| `prefix` | string, required, a DNS-1123 label | The prefix, by its name in the Bucket's prefixes. |

### `Lake.spec.buckets[]` [#lakespecbuckets]

| Field | Type and limits | Description |
| --- | --- | --- |
| `deletion` | string, one of `retain`, `delete` | retain (the default) keeps the store and its data when the resource that declares it is deleted, and delete removes them. An App applies the same choice when it drops the entry. |
| `name` | string, a DNS-1123 label | The object's name. It takes the namespace and resource group of the resource that declares it. |
| `prefixes` | array of [`Lake.spec.buckets[].prefixes[]`](#lakespecbucketsprefixes) | The Bucket's prefixes, each a key space with its own owner and cap. Prefix names are unique within the Bucket. A Function or a Lake that binds a prefix the Bucket does not list waits, with the reason BucketNotFound. |
| `quota` | object, [`Lake.spec.buckets[].quota`](#lakespecbucketsquota) | Caps on the Bucket's total size and on each object. While the Bucket has a size cap, funcd refuses to sign a presigned PUT URL for it, with 403. |
| `ref` | string, a DNS-1123 label | The name of an existing object of this kind in the namespace of the resource that declares it. A ref entry sets no other field. |

### `Lake.spec.buckets[].prefixes[]` [#lakespecbucketsprefixes]

| Field | Type and limits | Description |
| --- | --- | --- |
| `name` | string, required, a DNS-1123 label | The prefix's name, unique within the Bucket. Over S3, it is the first segment of each object's key. |
| `owner` | object, [`Lake.spec.buckets[].prefixes[].owner`](#lakespecbucketsprefixesowner) | The one Function, Lake or Job that may write the prefix, named with its kind, besides the writers that a RolesAssignment names. In a Bucket that a Function, a Lake or a Job declares by name, an omitted owner is that workload. In a Workflow's buckets, a Function owner names a step and a Lake owner a lake that the Workflow declares. The prefix that a Site serves its bundle from must have no owner, since the Site writes its builds there; the prefixes of a Site's ingress rules may have one. |
| `quota` | object, [`Lake.spec.buckets[].prefixes[].quota`](#lakespecbucketsprefixesquota) | A cap on the prefix's total size: a write into the prefix must fit both this cap and the Bucket's, and while it is set funcd refuses to sign a presigned PUT URL into the prefix, with 403. It also caps a Lake's files under the prefix, though not the Lake's catalog. |

### `Lake.spec.buckets[].prefixes[].owner` [#lakespecbucketsprefixesowner]

| Field | Type and limits | Description |
| --- | --- | --- |
| `kind` | string, required, one of `Function`, `Lake`, `Job` | The workload's kind. A Function, a Lake and a Job may share a name, so the kind says which one it is; each field names the kinds it accepts. |
| `name` | string, required, a DNS-1123 label | The workload's name, in the object's namespace. |

### `Lake.spec.buckets[].prefixes[].quota` [#lakespecbucketsprefixesquota]

| Field | Type and limits | Description |
| --- | --- | --- |
| `maxBytes` | integer, at least 0 | The same cap as a number of bytes. Set maxSize or maxBytes, not both. |
| `maxSize` | string, a size: 1 to 15 digits and an optional binary unit, Ki, Mi, Gi or Ti, with or without a B (512Ki, 2GiB) | The cap on the total size held, above zero. Set maxSize or maxBytes, not both; neither means no cap. A write that would pass the cap gets 507 in a KV store or a Bucket; a SQL execute call gets 507 once the database holds the cap. |

### `Lake.spec.buckets[].quota` [#lakespecbucketsquota]

| Field | Type and limits | Description |
| --- | --- | --- |
| `maxBytes` | integer, at least 0 | The same cap as a number of bytes. Set maxSize or maxBytes, not both. |
| `maxObjectBytes` | integer, at least 0 | The largest object a write may store, in bytes. A larger write gets 413, or EntityTooLarge over S3, and while it is set funcd refuses to sign a presigned PUT URL for the Bucket, with 403. 0 sets no cap of the Bucket's own, so only funcd's upload limits apply, such as s3gateway.maxUploadBytes. |
| `maxSize` | string, a size: 1 to 15 digits and an optional binary unit, Ki, Mi, Gi or Ti, with or without a B (512Ki, 2GiB) | The cap on the total size held, above zero. Set maxSize or maxBytes, not both; neither means no cap. A write that would pass the cap gets 507 in a KV store or a Bucket; a SQL execute call gets 507 once the database holds the cap. |

### `Lake.spec.configMaps[]` [#lakespecconfigmaps]

| Field | Type and limits | Description |
| --- | --- | --- |
| `data` | map of string to string | Keys and their string values, for settings that are not secret. Each key is an environment variable name: ASCII letters, digits and \_, not starting with a digit. Each value must be UTF-8 text with no NUL byte: a Function or a Lake that binds a ConfigMap holding another value does not start. Each worker of a Function that lists the ConfigMap in bindings.config gets each key as an environment variable when it starts, except a key that starts with FUNCD\_ or that a bound Secret also holds; and while the S3 gateway is on, a Function that binds a Bucket gets the AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY that funcd issues it, in place of the ConfigMap's. A Lake that lists it gives its engine only the keys that the Lake's bindings.config lets through. |
| `name` | string, a DNS-1123 label | The ConfigMap's name, at most 52 characters. It is stored as &lt;name&gt;-&lt;hash of data&gt;, and the config of each part that names it is set to that stored name. |
| `ref` | string, a DNS-1123 label | The name of an existing object of this kind in the namespace of the resource that declares it. A ref entry sets no other field. |

### `Lake.spec.ingress` [#lakespecingress]

| Field | Type and limits | Description |
| --- | --- | --- |
| `auth` | object, [`Lake.spec.ingress.auth`](#lakespecingressauth) | How the edge checks callers at the resource's own address; unset, the namespace's spec.edgeDefaults.auth decides, else open. A Lake refuses it, since the Lake gateway checks each caller. |
| `enabled` | boolean | Turns the resource's own address on or off. Unset, it is on unless the namespace's spec.defaultExposure is explicit; a Lake's address is on only when this is true. |
| `host` | string | The exact host of the resource's own address. Empty is the namespace's host, &lt;namespace&gt;.&lt;server.baseDomain&gt;, or, in the default namespace, any host that no other namespace reserves. |
| `path` | string | The edge path of the resource's own address, which begins with / and does not end with / unless it is /. Empty is / when host is set, else /function/&lt;name&gt;, /site/&lt;name&gt; or /lake/&lt;name&gt; by kind. |

### `Lake.spec.ingress.auth` [#lakespecingressauth]

| Field | Type and limits | Description |
| --- | --- | --- |
| `mode` | string, one of `""`, `authenticated`, `open`, `oidc` | How the edge checks callers. authenticated requires a bearer token, or an X-Api-Key header, of an identity that RBAC lets get Functions in the namespace: 401 without a valid one, 403 when it may not; while server.auth.edge is off, every caller gets 401. open lets anonymous callers in. oidc signs callers in with the OIDCProvider that provider names, and passes the signed-in user to the code behind it in the X-Funcd-Principal headers. Empty takes the enclosing stance, if any, else the namespace's spec.edgeDefaults.auth.mode, else open. |
| `provider` | string, a DNS-1123 label | With mode oidc, the OIDCProvider of the namespace that signs callers in; required with oidc and refused with another mode. |
| `unauthenticated` | string, one of `""`, `redirect`, `401`, `allow` | With mode oidc, what a call that is not signed in gets: redirect, the default, sends a GET or HEAD navigation to the provider with 302 and gives any other call 401; 401 gives every such call 401; allow passes every call, with no principal. Refused with another mode. |

### `Lake.spec.location` [#lakespeclocation]

| Field | Type and limits | Description |
| --- | --- | --- |
| `bucket` | string, required, a DNS-1123 label | A Bucket of the same namespace. |
| `prefix` | string, required, a DNS-1123 label | A prefix of that Bucket. |

### `Lake.spec.resources` [#lakespecresources]

| Field | Type and limits | Description |
| --- | --- | --- |
| `cpu` | string | The CPU cap of the worker or engine it sizes, as a number of cores of at least 0.01, such as 0.5 or 2. Empty takes the default of the resource that declares it, or no cap when there is none. Only the containerd runtime enforces it. |
| `memory` | string | The memory cap of the worker or engine it sizes, such as 256Mi or 4GiB: 1 to 15 digits and an optional binary unit, Ki, Mi, Gi or Ti, with or without a B, above zero. Empty takes the default of the resource that declares it, or no cap when there is none. Only the containerd runtime enforces it, and there a worker that uses more memory than the cap is killed. |

### `Lake.spec.secrets[]` [#lakespecsecrets]

| Field | Type and limits | Description |
| --- | --- | --- |
| `description` | string | What the Secret is for, for the installer who provides it. |
| `keys` | array of string values, required, each matching `^[A-Za-z_][A-Za-z0-9_]*$` | The keys read from the Secret: its data must hold each of them. |
| `name` | string, required, a DNS-1123 label | The name of a Secret in the namespace of the resource that declares it. funcd holds its value; the resource never writes it. |

### `Lake.status` [#lakestatus]

| Field | Type and limits | Description |
| --- | --- | --- |
| `conditions` | array of [Condition](/docs/develop/common-definitions.md#condition) | The conditions that explain the phase. |
| `endpoint` | string | While the Lake is Ready, the host and port of its Lake gateway, which a Function that binds the Lake gets as FUNCD_LAKE\_&lt;ALIAS&gt;\_URL. In any other phase it is empty or holds the engine's own address. |
| `function` | string, a DNS-1123 label | funcd sets it to &lt;name&gt;-duckdb, after the Lake's name. funcd makes no object of that name and does not read it. |
| `observedGeneration` | integer | The generation of the spec that funcd last acted on. |
| `phase` | string, one of `Pending`, `Deploying`, `Ready`, `Idle`, `Degraded`, `Failed`, `Terminating` | Where the object is in its lifecycle. |
| `proxyPort` | integer | The port of the Lake gateway. funcd binds it again after a restart, so the address that Functions binding the Lake hold keeps working; when the port is taken, funcd binds a new one, and their address changes. |

## Handler API [#handler-api]

The methods a handler calls on its context's clients, in each language funcd ships a shim for.

### `ctx.lake` [#ctxlake]

#### TypeScript [#typescript]

The Lakes that the function binds, by alias: the address of each Lake's gateway, and the token that the gateway accepts from the function.

| Method | What it does |
| --- | --- |
| `get(alias: string): LakeEndpoint` | The gateway of the Lake bound as alias: url, its address as host:port, and token, the token that it accepts from the function. Throws an Error naming the alias when the function binds no Lake with that alias. |

#### Python [#python]

The Lakes that the function binds, by alias: the address of each Lake's gateway, and the token that the gateway accepts from the function.

| Method | What it does |
| --- | --- |
| `get(alias: str) -> LakeEndpoint` | The gateway of the Lake bound as ``alias``: ``url``, its address as ``host:port``, and ``token``, the token that it accepts from the function. Raises ``KeyError`` naming the alias when the function binds no Lake with that alias. |

## HTTP API [#http-api]

The table lists each described operation of these kinds, with its method and path. The operation's page in the API reference gives its parameters, its body, its authentication and every answer, with when it happens and what to do.

| Method | Path | Operation |
| --- | --- | --- |
| `GET` | `/apis/funcd.io/v1alpha1/namespaces/{namespace}/lakes` | [List the Lakes of a namespace](/docs/api/services/lake/list.md) |
| `POST` | `/apis/funcd.io/v1alpha1/namespaces/{namespace}/lakes` | [Create a Lake](/docs/api/services/lake/create.md) |
| `GET` | `/apis/funcd.io/v1alpha1/namespaces/{namespace}/lakes/{name}` | [Read a Lake](/docs/api/services/lake/get.md) |
| `PUT` | `/apis/funcd.io/v1alpha1/namespaces/{namespace}/lakes/{name}` | [Replace a Lake](/docs/api/services/lake/replace.md) |
| `DELETE` | `/apis/funcd.io/v1alpha1/namespaces/{namespace}/lakes/{name}` | [Delete a Lake](/docs/api/services/lake/delete.md) |
| `GET` | `/apis/funcd.io/v1alpha1/namespaces/{namespace}/lakes/{name}/logs` | [Read the logs of a Lake's engine](/docs/api/services/lake/get-logs.md) |
