Skip to Content
Tenancy and limits

Namespaces and resource groups

Delete the resources of a resource group as one, set the defaults of a namespace with a Namespace, and reach a namespace at its own host.

Usage

A namespace keeps its resources apart from other namespaces', and a resource group gathers the resources that belong together, such as one application's.

The first example deletes the log-burst Function through its group rg1. Install the dev build of funcdctl, Git and curl, and put Node.js on the PATH. Clone both repositories into one folder and start the example:

$ git clone https://github.com/pyvvo/funcd-typescript
$ git clone https://github.com/pyvvo/funcd
$ cd funcd-typescript
$ funcdctl dev examples/log-burst --gport 8080 --cport 8081

In another terminal, from the folder that holds both clones, call the Function:

$ curl -s -X POST -H 'content-type: application/json' -d '{}' http://127.0.0.1:8080/function/log-burst
{"emitted":115}

Each resource names its group in metadata.resourceGroup. Naming a group creates no ResourceGroup, but funcd deletes a group only through one of its name:

apiVersion: funcd.io/v1alpha1
kind: ResourceGroup
metadata:
  name: rg1
  namespace: default
  resourceGroup: rg1
spec:
  description: The resources of the guide's examples
$ funcdctl --server http://127.0.0.1:8081 --token funcd-dev-token apply -f funcd/api/types/v1alpha1/examples/namespaces/resourcegroup.yaml
applied ResourceGroup/rg1

funcd refuses to delete a group that has a member, a resource that names the group and that no other resource owns:

$ funcdctl --server http://127.0.0.1:8081 --token funcd-dev-token delete resourcegroup rg1 -n default
funcdctl: sdk: admission.resourcegroup-deletion-protection: ResourceGroup "rg1" still has 1 member(s): Function/log-burst; delete them first, or delete with force

--force deletes the members first; the Function's revision is no member, since the Function owns it:

$ funcdctl --server http://127.0.0.1:8081 --token funcd-dev-token delete resourcegroup rg1 -n default --force
deleted ResourceGroup/rg1

The Function is gone:

$ funcdctl --server http://127.0.0.1:8081 --token funcd-dev-token get function log-burst -n default
funcdctl: sdk: store.Get: Function "log-burst" not found
$ curl -s -X POST -H 'content-type: application/json' -d '{}' http://127.0.0.1:8080/function/log-burst
{"type":"urn:funcd:problem:not-found","title":"Not Found","status":404,"detail":"dataplane.ServeHTTP: function default/log-burst is not exposed by name"}

funcdctl dev applies the folder again when a file changes or it restarts. Press Ctrl-C in the first terminal to stop.

Set a namespace's defaults

A Namespace holds the settings of the namespace of its name: whether its Functions and Sites answer at their own addresses, whether its edge asks callers to authenticate, and its volume budget. It belongs to no namespace.

Only an admin acts on a Namespace, so these tasks need a funcd server on Linux with an admin entry in auth.credentials, a tokenFile with role: admin. auth.credentials replaces auth.token: funcd refuses to start with both, and every other credential needs its own entry listing its namespaces.

Each task applies a file of funcd's repository from a clone's root, with the admin token in ADMIN_TOKEN, to a server whose API listens at 127.0.0.1:8080. Replace each registry.example.com image with an artifact that the server can pull, as funcdctl push prints. Calls go to the edge at server.dataPlaneAddr, which takes a free port by default, so set one, such as 127.0.0.1:8081, and name the namespace's host in the Host header, such as -H 'Host: shop.localhost'.

Turn off the Functions' own addresses

A Function answers at /function/<name>, and a Site at /site/<name>, or at its spec.ingress host and path. A Namespace whose defaultExposure is explicit turns these addresses off for each Function and Site that does not set spec.ingress.enabled:

apiVersion: funcd.io/v1alpha1
kind: Namespace
metadata:
  name: shop
spec:
  defaultExposure: explicit

The complete file also holds catalog, which turns its address on again with spec.ingress.enabled:

apiVersion: funcd.io/v1alpha1
kind: Function
metadata:
  name: catalog
  namespace: shop
  resourceGroup: rg1
spec:
  runtime: nodejs22
  handler: handle
  image: registry.example.com/catalog:1.0.0
  ingress:
    enabled: true

and the Route orders, which serves the Function orders at /orders:

apiVersion: funcd.io/v1alpha1
kind: Route
metadata:
  name: orders
  namespace: shop
  resourceGroup: rg1
spec:
  rules:
    - path: /orders
      backend:
        function: orders

Apply it with funcdctl --server http://127.0.0.1:8080 --token "$ADMIN_TOKEN" apply -f api/types/v1alpha1/examples/namespaces/namespace.yaml. On shop.localhost:

  • /function/orders gets 404, function shop/orders is not exposed by name, and starts no worker; /function/catalog answers.
  • /orders answers through the Route: a Route that no Function or Site owns stays on.
  • A Route that a Site or a Function owns turns off too, with the reason Disabled, unless spec.ingress.enabled.
  • A call over a link still reaches orders.

In the namespace default, which has no host, explicit also turns off each Route without a host, with HostRequired.

Set the default authentication of a namespace

A Namespace whose edgeDefaults.auth.mode is authenticated asks for a token on every address of the namespace that sets no mode of its own; a mode set by a Function, a Route or a rule wins:

apiVersion: funcd.io/v1alpha1
kind: Namespace
metadata:
  name: billing
spec:
  edgeDefaults:
    auth:
      mode: authenticated

The complete file also holds status, which keeps its address open:

apiVersion: funcd.io/v1alpha1
kind: Function
metadata:
  name: status
  namespace: billing
  resourceGroup: rg1
spec:
  runtime: nodejs22
  handler: handle
  image: registry.example.com/status:1.0.0
  ingress:
    auth:
      mode: open

Apply it with funcdctl --server http://127.0.0.1:8080 --token "$ADMIN_TOKEN" apply -f api/types/v1alpha1/examples/namespaces/edge-defaults.yaml. A call to /function/invoices on billing.localhost gets:

CallAnswerAction
Any call while server.auth.edge is false, its default, with a token or without one401, authentication required but no authenticator is configuredSet server.auth.edge to true.
A call without a token401, missing bearer token or API keySend a token in the Authorization: Bearer or the X-Api-Key header.
A call whose token funcd does not know401, invalid credentialSend a token that funcd's configuration sets.
A call with the token of a credential that does not act in billing, such as a developer of default403, not authorized to invoke billing/invoices: developer not scoped to namespace "billing"List billing in the namespaces of the credential's entry of auth.credentials.
A call with an admin's token, or with the token of a developer or a viewer whose entry lists billing in its namespacesThe Function's answer: the Function receives the call without its Authorization and X-Api-Key headersNone.

/function/status answers with no token. A missing or turned-off address gets the same 401 before its 404, so a caller without a token cannot learn which names exist. See also Ask callers to authenticate.

Reach a namespace at its own host

This needs a funcd server with a credential that acts in the namespace, but no Namespace. Every namespace other than default has the host <namespace>.<server.baseDomain>, such as shop.localhost with the default server.baseDomain. On it:

  • A Route of the namespace with no host answers on that host alone, and its status.host names it.
  • /function/<name> reaches the namespace's Function, on the host and every name under it.
  • A Route whose host is a name under it, such as api.shop.localhost, answers there.

On a host that names no namespace, such as localhost, /function/<name> goes to the namespace of the X-Funcd-Namespace header, else to default. Choose the host of a Route gives the other rules.

Limit the volume space of a namespace

A Namespace's volumeBudget, or volumeBudgetBytes, limits the volume space that its Functions reserve: each local volume from its apply until its removal, and each emptyDir while its worker exists. Volumes need runtime.mode: containerd and a volumes.capacity:

apiVersion: funcd.io/v1alpha1
kind: Namespace
metadata:
  name: media
spec:
  volumeBudget: 4Gi

Apply it with funcdctl --server http://127.0.0.1:8080 --token "$ADMIN_TOKEN" apply -f api/types/v1alpha1/examples/namespaces/volume-budget.yaml. A local volume that does not fit is refused with 409 and a message ending in VolumeBudget; a worker whose emptyDir does not fit does not start, with VolumeBudget on the Function's Ready condition.

Access

The credential's role decides, as for every object of the API:

  • An admin acts everywhere, and is the only role that acts on a Namespace.
  • A developer manages ResourceGroups, as every object, in its credential's namespaces. funcd-dev-token, which funcdctl dev uses, and the token of auth.token are developers of auth.namespaces, default by default.
  • A viewer reads ResourceGroups in its namespaces.

Elsewhere, a request gets 403, such as list Function in "shop" denied: developer not scoped to namespace "shop". A forced delete deletes each member with the caller's credential. What a Function or an Identity may do inside a namespace is on the Security page.

Limits and quotas

  • A namespace holds at most 100 KVStores, 100 Buckets and 20 SQL databases; kvstore.maxStoresPerNamespace and sql.maxDatabasesPerNamespace change two of them. A create past a cap gets 400.
  • A refused group delete names at most five members, and counts the rest.

Changes and deletion

  • funcd reads a Namespace's defaultExposure and edgeDefaults at each call; the Routes that Functions and Sites own follow within controller.routeResyncInterval, 10 seconds by default. It reads volumeBudget at each reservation.
  • Deleting a Namespace only resets its settings; the namespace's resources keep running.
  • --force deletes a group's members pass by pass, Sensors first, each under its own kind's checks, records such as a Sensor's WorkflowRuns included. A member that funcd refuses, such as a link's target, stops it; the members already deleted stay deleted, and a new delete continues.
  • A group without a ResourceGroup cannot be deleted: the delete gets 404.

CLI errors

These errors stop a command before any server answers:

ErrorAction
no node interpreter found for the node handlerfuncdctl dev found no Node.js for the example's Function. Put Node.js on the PATH, or set FUNCD_NODE to the path of node.
<file>: <kind> "<name>" is in namespace "<namespace>"; funcdctl dev runs namespace default onlyRemove metadata.namespace from the object, set it to default, or apply the file to a funcd server.
manifest is invalid (<kind> "<name>"), followed by resourceGroup is required for kind "<kind>"funcdctl apply checks each document before it sends it. Set metadata.resourceGroup on every object of a namespace.
manifest is invalid (Namespace "<name>"), followed by a value that must be implicit or explicit or must be authenticated or openSet defaultExposure or edgeDefaults.auth.mode to a value that the Spec tab lists.
manifest is invalid (Namespace "<name>"), followed by spec.volumeBudget and spec.volumeBudgetBytes are both set: want at most oneKeep one of the two budgets.
manifest is invalid (Namespace "<name>"), followed by spec.volumeBudget and the reason the size does not parseWrite spec.volumeBudget as a size that the Spec tab describes.

Run it locally

  • funcdctl dev runs the namespace default only, and stops on another.
  • Its token is a developer's, so a Namespace in its folder stops it; default keeps its defaults there.
  • It gives the group dev to each object that names none, without a ResourceGroup, so deleting dev gets 404.
  • Its state stays in memory unless --persist keeps it in .funcd-dev.

Examples

On this page