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 8081In 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/rg1funcd 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/rg1The 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: explicitThe 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: trueand 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: ordersApply 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/ordersgets 404,function shop/orders is not exposed by name, and starts no worker;/function/cataloganswers./ordersanswers 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, unlessspec.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: authenticatedThe 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: openApply 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:
| Call | Answer | Action |
|---|---|---|
Any call while server.auth.edge is false, its default, with a token or without one | 401, authentication required but no authenticator is configured | Set server.auth.edge to true. |
| A call without a token | 401, missing bearer token or API key | Send a token in the Authorization: Bearer or the X-Api-Key header. |
| A call whose token funcd does not know | 401, invalid credential | Send 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 default | 403, 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 namespaces | The Function's answer: the Function receives the call without its Authorization and X-Api-Key headers | None. |
/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.hostnames 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: 4GiApply 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
adminacts everywhere, and is the only role that acts on a Namespace. - A
developermanages ResourceGroups, as every object, in its credential's namespaces.funcd-dev-token, whichfuncdctl devuses, and the token ofauth.tokenare developers ofauth.namespaces,defaultby default. - A
viewerreads 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.maxStoresPerNamespaceandsql.maxDatabasesPerNamespacechange 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
defaultExposureandedgeDefaultsat each call; the Routes that Functions and Sites own follow withincontroller.routeResyncInterval, 10 seconds by default. It readsvolumeBudgetat each reservation. - Deleting a Namespace only resets its settings; the namespace's resources keep running.
--forcedeletes 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:
| Error | Action |
|---|---|
no node interpreter found for the node handler | funcdctl 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 only | Remove 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 open | Set 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 one | Keep one of the two budgets. |
manifest is invalid (Namespace "<name>"), followed by spec.volumeBudget and the reason the size does not parse | Write spec.volumeBudget as a size that the Spec tab describes. |
Run it locally
funcdctl devruns the namespacedefaultonly, and stops on another.- Its token is a developer's, so a Namespace in its folder stops it;
defaultkeeps its defaults there. - It gives the group
devto each object that names none, without a ResourceGroup, so deletingdevgets 404. - Its state stays in memory unless
--persistkeeps it in.funcd-dev.
Examples
- log-burst in TypeScript: the Function that the first example deletes through its group.
Networking
Serve a Function at a path and a host of its own with a Route, ask its callers to authenticate, and allow a Function's outbound connections with an EgressPolicy.
Disaster recovery
Back up the stores of a namespace to an S3 bucket on a schedule, and restore a Backup into other stores or into the stores that it came from.