postgres-connector

by Helm

Helm chartv0.1.2

Trigger OpenFaaS functions from PostgreSQL

About this chart

OpenFaaS Pro Postgres Connector

The Postgres connector can be used to invoke functions from PostgreSQL database events.

See also: Trigger functions from Postgres

Pre-requisites

  • Purchase a license

    You will need an OpenFaaS License

    Contact us to find out more openfaas.com/pricing

  • Install OpenFaaS

    You must have a working OpenFaaS installed.

  • Configure PostgreSQL

    You must have a working PostgreSQL database installed and configured for logical replication, get the specific settings here: Trigger functions from Postgres

Configure your secrets

  • Create the required secret with your OpenFaaS Pro license code:
$ kubectl create secret generic \
    -n openfaas \
    openfaas-license \
    --from-file license=$HOME/.openfaas/LICENSE
  • Create a secret with your PostgreSQL connection string:
$ kubectl create secret generic -n openfaas \
  postgresql-connection --from-file postgresql-connection=$HOME/postgresql-connection.txt

Configure values.yaml

Create a pgconnector.yaml file with the following custom contents:

connectionSecret: "postgresql-connection"

publication: "ofltd"

# filter which tables and events to be notified about
filters: "customer:insert,customer:update"

wal: true

Install the chart

  • Add the OpenFaaS chart repo and deploy the postgres-connector Pro chart. We recommend installing it in the same namespace as the rest of OpenFaaS
$ helm repo add openfaas https://openfaas.github.io/faas-netes/
$ helm repo update
$ helm upgrade postgres-connector openfaas/postgres-connector \
    --install \
    --namespace openfaas \
    -f pgconnector.yaml

The above command will also update your helm repo to pull in any new releases.

Install a development version

$ helm upgrade postgres-connector ./chart/postgres-connector \
    --install \
    --namespace openfaas \
    -f ./pgconnector.yaml

Configuration

Additional postgres-connector options in values.yaml.

ParameterDescriptionDefault
walStart the connector in WAL mode or trigger mode. Set to false for trigger mode.true
connectionSecretThe name of the secret containing the connection stringpostgresql-connection
publicationThe name of the publication to be created in Postgres, we do not recommend changing this value.ofltd
filtersA comma separated list of filters to apply to the stream i.e. TABLENAME:ACTION, action can be: insert, delete or update, multiple items can be comma separated such as T1:insert,T2:delete,T3:insert""
upstreamTimeoutMaximum timeout for upstream function call, must be a Go formatted duration string.2m
rebuildIntervalInterval for rebuilding function to topic map, must be a Go formatted duration string.30s
asyncInvocationFor long running or slow functions, offload to asychronous function invocations and carry on processing the streamfalse
gatewayURLThe URL for the API gateway.http://gateway.openfaas:8080
fullnameOverrideOverride the name value used for the Connector Deployment object.``
contentTypeSet a HTTP Content Type during function invocation.""
replicasNumber of replicas for the Connector Deployment object, we recommend setting this to 11
resourcesResources requests and limits configurationrequests.memory: "64Mi"
logs.debugPrint debug logsfalse
logs.formatThe log encoding format. Supported values: json or consoleconsole

Specify each parameter using the --set key=value[,key=value] argument to helm install. See values.yaml for the default configuration.

Removing the postgres-connector

All components can be cleaned up with helm:

$ helm uninstall -n openfaas postgres-connector

Deploy postgres-connector with OpenTenant

Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has postgres-connector on a Hetzner server. Change the host, add apps from the marketplace, then copy the generated files. Providers and prices are samples, and nothing here is sent anywhere.

  1. Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
  2. Place the chartpostgres-connector is pinned at v0.1.2 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
  3. ApplySave opentenant.yaml and main.tf from the console, then run the commands below.
# opentenant.yaml, main.tf and dns.tf come from the builder below
opentenant validate opentenant.yaml
terraform init && terraform apply