Documentation
¶
Overview ¶
Package functions turns an app's function description (what an SDK's runtime prints for MAXCLOUD_DESCRIBE=1 or --describe) into the manifests Flux deploys: a Knative service per HTTP function, a CronJob per schedule, a KEDA-scaled Deployment per queue, and the database queues need.
Index ¶
- Constants
- func ConnectionsWarning(d *Description) string
- func Manifests(d *Description, o Options) ([]byte, error)
- func NeedsDatabaseHint(app string) string
- func Objects(d *Description, o Options) []map[string]any
- func WriteDir(dir string, d *Description, o Options) ([]string, error)
- type Description
- type Function
- type Options
- type Volume
Constants ¶
const ( PoolSize = 4 ConnectionBudget = 80 )
What an app's functions can hold on its database at once. Each instance keeps a pool of its own: the SDKs' db() pool has up to PoolSize connections, and a queue worker another one per job it works on, plus one. Postgres takes 100 connections (CloudNativePG's default max_connections); ConnectionBudget leaves room for its own (the superuser's reserve, the instance manager, a replica, KEDA's backlog query, mcloud db psql).
const ( // DatabaseName is the CloudNativePG cluster queues use; its Secret is db-app. DatabaseName = "db" // StorageSecret is where the maxcloud controller puts the app's S3 // credentials once the app has a bucket: AWS_* variables every AWS SDK // reads, and MAXCLOUD_APP. StorageSecret = "maxcloud-s3" // AppSecrets holds the app's own secrets (mcloud secrets set). AppSecrets = "app-secrets" // AppEnv holds the app's plain variables set with mcloud env set (those // in maxcloud.yaml are in the manifests). AppEnv = "app-env" )
const DescribeTag = "maxcloud:describe:"
DescribeTag starts the description line an image prints when run with MAXCLOUD_DESCRIBE=1.
const LegacyDatabaseFile = "database.yaml"
LegacyDatabaseFile is the database mcloud used to write for queue apps.
Variables ¶
This section is empty.
Functions ¶
func ConnectionsWarning ¶ added in v0.17.0
func ConnectionsWarning(d *Description) string
ConnectionsWarning says so when the functions could together hold more connections than the database has to give ("" if they can't). It can only warn: which functions use the database isn't in the description.
func Manifests ¶
func Manifests(d *Description, o Options) ([]byte, error)
Manifests returns functions.yaml.
func NeedsDatabaseHint ¶ added in v0.5.0
NeedsDatabaseHint is what to tell someone whose app has queue functions and no database.yaml: the queue lives in the app's database, which the registry provides.
Types ¶
type Description ¶
type Description struct {
SDK string `json:"sdk"`
Version string `json:"version"`
Functions []Function `json:"functions"`
// Migrations are the SQL migrations the image applies when it starts
// (their file names). nil: an SDK from before migrations.
Migrations []string `json:"migrations"`
}
func Parse ¶
func Parse(data []byte) (*Description, error)
Parse reads a description: plain JSON (--describe), or output with a tagged line in it (MAXCLOUD_DESCRIBE=1).
func (*Description) DatabaseConnections ¶ added in v0.17.0
func (d *Description) DatabaseConnections() int
DatabaseConnections is the most connections the app's functions can hold at once, every function scaled all the way out and every pool full.
func (*Description) NeedsDatabase ¶
func (d *Description) NeedsDatabase() bool
NeedsDatabase reports whether any function uses a queue.
type Function ¶
type Function struct {
Name string `json:"name"`
Export string `json:"export"`
Kind string `json:"kind"` // http, schedule, queue
Memory *string `json:"memory"`
CPU *string `json:"cpu"`
TimeoutSeconds float64 `json:"timeoutSeconds"`
// The container, every kind:
// MemoryLimit above Memory (the request), for spikes.
MemoryLimit *string `json:"memoryLimit"`
// User the container runs as (and its group), for an image that
// doesn't set a non-root USER.
User *int64 `json:"user"`
// ReadOnlyRootFilesystem: write only to Volumes.
ReadOnlyRootFilesystem bool `json:"readOnlyRootFilesystem"`
// Volumes are scratch directories (emptyDir), gone with the pod.
Volumes []Volume `json:"volumes"`
// http
Public bool `json:"public"`
MinInstances int `json:"minInstances"`
MaxInstances int `json:"maxInstances"`
Concurrency int `json:"concurrency"`
// Proxied: the public hostname's DNS record is proxied by Cloudflare.
Proxied bool `json:"proxied"`
// HealthPath answers 2xx when the instance can take requests: Knative's
// readiness probe, and a liveness probe that restarts it when it stops.
HealthPath string `json:"healthPath"`
// schedule
Schedule string `json:"schedule"`
TimeZone string `json:"timeZone"`
Retries int `json:"retries"`
// queue (also MaxInstances, Concurrency)
Queue string `json:"queue"`
MaxAttempts int `json:"maxAttempts"`
BackoffSeconds float64 `json:"backoffSeconds"`
BacklogQuery string `json:"backlogQuery"`
}
type Options ¶
type Options struct {
// Image is the name the manifests use for the app's image, which the
// deploy workflow replaces with the built one. Default "app".
Image string
// LegacyDatabase: the app's deploy/k8s has a database.yaml, as mcloud
// wrote before the maxcloud controller ran databases. That file defines
// the Cluster db and KEDA's TriggerAuthentication db, and DATABASE_URL
// is required. Otherwise the database is the registry's (mcloud apps
// set --db): DATABASE_URL is optional, and queue functions get the
// TriggerAuthentication here.
LegacyDatabase bool
// Labels are added to every object (direct deploys mark theirs).
Labels map[string]string
// App is the app's name: every function gets it as MAXCLOUD_APP (a
// literal: Knative refuses the downward API unless a flag allows it).
App string
// Env is maxcloud.yaml's env: plain variables every function gets, in
// the manifests themselves (a change is a new revision). They win over
// the app's ConfigMap app-env and Secret app-secrets.
Env map[string]string
// Environment is the app's environment or preview these are for
// (staging, pr-42): every function gets it as MAXCLOUD_ENVIRONMENT. App
// is then the environment's own name, <app>--<env>, which bucket
// names are made from (mc-<app>--<env>--<bucket>).
Environment string
// Preview: a short-lived deploy that mustn't take room. HTTP functions
// scale from zero to one instance, queue workers to one, and scheduled
// functions don't run on their schedule (suspended; mcloud run still
// runs one).
Preview bool
}