Skip to content

Commit 8cd107d

Browse files
committed
Add Helm chart for Google Cloud Pub/Sub connector
Signed-off-by: Han Verstraete (OpenFaaS Ltd) <[email protected]>
1 parent 5b75fd7 commit 8cd107d

File tree

7 files changed

+384
-4
lines changed

7 files changed

+384
-4
lines changed

Diff for: Makefile

+8-4
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ verify-charts:
8686
arkade chart verify --verbose=$(VERBOSE) -f ./chart/postgres-connector/values.yaml && \
8787
arkade chart verify --verbose=$(VERBOSE) -f ./chart/queue-worker/values.yaml && \
8888
arkade chart verify --verbose=$(VERBOSE) -f ./chart/sns-connector/values.yaml && \
89-
arkade chart verify --verbose=$(VERBOSE) -f ./chart/rabbitmq-connector/values.yaml
89+
arkade chart verify --verbose=$(VERBOSE) -f ./chart/rabbitmq-connector/values.yaml && \
90+
arkade chart verify --verbose=$(VERBOSE) -f ./chart/gcp-pubsub-connector/values.yaml
9091

9192
verify-chart:
9293
@echo Verifying helm chart images in remote registries && \
@@ -109,7 +110,8 @@ upgrade-charts:
109110
arkade chart upgrade --verbose=$(VERBOSE) -w -f ./chart/postgres-connector/values.yaml && \
110111
arkade chart upgrade --verbose=$(VERBOSE) -w -f ./chart/queue-worker/values.yaml && \
111112
arkade chart upgrade --verbose=$(VERBOSE) -w -f ./chart/sns-connector/values.yaml && \
112-
arkade chart upgrade --verbose=$(VERBOSE) -w -f ./chart/rabbitmq-connector/values.yaml
113+
arkade chart upgrade --verbose=$(VERBOSE) -w -f ./chart/rabbitmq-connector/values.yaml && \
114+
arkade chart upgrade --verbose=$(VERBOSE) -w -f ./chart/gcp-pubsub-connector/values.yaml
113115

114116
bump-charts:
115117
arkade chart bump --file ./chart/openfaas/Chart.yaml -w && \
@@ -122,7 +124,8 @@ bump-charts:
122124
arkade chart bump --file ./chart/postgres-connector/Chart.yaml -w && \
123125
arkade chart bump --file ./chart/queue-worker/Chart.yaml -w && \
124126
arkade chart bump --file ./chart/sns-connector/Chart.yaml -w && \
125-
arkade chart bump --file ./chart/rabbitmq-connector/Chart.yaml -w
127+
arkade chart bump --file ./chart/rabbitmq-connector/Chart.yaml -w && \
128+
arkade chart bump --file ./chart/gcp-pubsub-connector/Chart.yaml -w
126129

127130
charts-only:
128131
@cd chart && \
@@ -136,7 +139,8 @@ charts-only:
136139
helm package postgres-connector/ && \
137140
helm package queue-worker/ && \
138141
helm package sns-connector/ && \
139-
helm package rabbitmq-connector/
142+
helm package rabbitmq-connector/ && \
143+
helm package gcp-pubsub-connector/
140144
mv chart/*.tgz docs/
141145
helm repo index docs --url https://openfaas.github.io/faas-netes/ --merge ./docs/index.yaml
142146

Diff for: chart/gcp-pubsub-connector/.helmignore

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Patterns to ignore when building packages.
2+
# This supports shell glob matching, relative path matching, and
3+
# negation (prefixed with !). Only one pattern per line.
4+
.DS_Store
5+
# Common VCS dirs
6+
.git/
7+
.gitignore
8+
.bzr/
9+
.bzrignore
10+
.hg/
11+
.hgignore
12+
.svn/
13+
# Common backup files
14+
*.swp
15+
*.bak
16+
*.tmp
17+
*~
18+
# Various IDEs
19+
.project
20+
.idea/
21+
*.tmproj
22+
.vscode/

Diff for: chart/gcp-pubsub-connector/Chart.yaml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
apiVersion: v1
2+
description: Invoke OpenFaaS functions from Google Cloud Pub/Sub messages.
3+
name: gcp-pubsub-connector
4+
version: 0.0.1
5+
sources:
6+
- https://github.com/openfaas/faas-netes
7+
home: https://www.openfaas.com
8+
icon: https://raw.githubusercontent.com/openfaas/media/master/OpenFaaS_logo_stacked_opaque.png
9+
keywords:
10+
- openfaas
11+
- faas
12+
- serverless
13+
- pubsub
14+
- gcp
15+
- events
16+
maintainers:
17+
- name: alexellis
18+
19+
- name: welteki
20+

Diff for: chart/gcp-pubsub-connector/README.md

+107
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# OpenFaaS Pro Google Cloud Pub/Sub Connector
2+
3+
Trigger OpenFaaS functions from Google Cloud Pub/Sub messages.
4+
5+
## Prerequisites
6+
7+
- Purchase a license
8+
9+
You will need an OpenFaaS License
10+
11+
Contact us to find out more [openfaas.com/pricing](https://www.openfaas.com/pricing)
12+
13+
- Install OpenFaaS
14+
15+
You must have a working OpenFaaS installed.
16+
17+
## Configure secrets
18+
19+
- Create the required secret with your OpenFaaS Pro license code:
20+
21+
```bash
22+
$ kubectl create secret generic \
23+
-n openfaas \
24+
openfaas-license \
25+
--from-file license=$HOME/.openfaas/LICENSE
26+
```
27+
28+
- Create a secret for the Google Cloud Application Default Credentials (ADC).
29+
30+
```bash
31+
$ kubectl create secret generic -n openfaas \
32+
gcp-pubsub-credentials --from-file gcp-pubsub-credentials=$HOME/gcp-pubsub-credentials.json
33+
```
34+
35+
Ensure you application has the correct [IAM permission to consume messages from Pub/Sub subscriptions](https://cloud.google.com/pubsub/docs/access-control).
36+
37+
## Configure values.yaml
38+
39+
```yaml
40+
# Google cloud project ID
41+
projectID: "openfaas"
42+
43+
# List if Pub/Sub subscriptions the connector should subscribe to.
44+
subscriptions:
45+
- sub1
46+
- sub2
47+
```
48+
49+
Use the `subscriptions` parameter to configure a list of Pub/Sub subscriptions to which the connector should subscribe. When the subscriber receives a message, the connector will attempt to invoke any function that has the subscription name listed in its `topic` annotation.
50+
51+
## Install the chart
52+
53+
- Add the OpenFaaS chart repo and deploy the `gcp-pubsub-connector` chart. We recommend installing it in the same namespace as the rest of OpenFaaS
54+
55+
```sh
56+
$ helm repo add openfaas https://openfaas.github.io/faas-netes/
57+
$ helm repo update && \
58+
helm upgrade gcp-pubsub-connector openfaas/gcp-pubsub-connector \
59+
--install \
60+
--namespace openfaas \
61+
-f values.yaml
62+
```
63+
64+
> The above command will also update your helm repo to pull in any new releases.
65+
66+
## Configuration
67+
68+
Additional gcp-pubsub-connector options in `values.yaml`.
69+
70+
| Parameter | Description | Default |
71+
| ---------------------- | ------------------------------------------------------------------------------------------------------------------ | ------------------------------ |
72+
| `replicas` | The number of replicas of this connector. Pub/Sub messages will be load balanced between the connector replicas. | `1` |
73+
| `projectID` | Google Cloud project Id | `""` |
74+
| `subscriptions` | List if Pub/Sub subscriptions the connector should subscribe to. | `[]` |
75+
| `gcpCredentialsSecret` | Kubernetes secret for the Google Cloud Application Default Credentials (ADC) | `gcp-pubsub-credentials` |
76+
| `asyncInvocation` | For long running or slow functions, offload to asychronous function invocations and carry on processing the stream | `false` |
77+
| `upstreamTimeout` | Maximum timeout for upstream function call, must be a Go formatted duration string. | `2m` |
78+
| `rebuildInterval` | Interval for rebuilding function to topic map, must be a Go formatted duration string. | `30s` |
79+
| `gatewayURL` | The URL for the OpenFaaS gateway. | `http://gateway.openfaas:8080` |
80+
| `printResponse` | Output the response of calling a function in the logs. | `true` |
81+
| `printResponseBody` | Output to the logs the response body when calling a function. | `false` |
82+
| `printRequestBody` | Output to the logs the request body when calling a function. | `false` |
83+
| `fullnameOverride` | Override the name value used for the Connector Deployment object. | `""` |
84+
| `contentType` | Set a HTTP Content Type during function invocation. | `text/plain` |
85+
| `logs.debug` | Print debug logs | `false` |
86+
| `logs.format` | The log encoding format. Supported values: `json` or `console` | `console` |
87+
88+
Specify each parameter using the `--set key=value[,key=value]` argument to `helm install`. See `values.yaml` for the default configuration.
89+
90+
## Install a development version of the chart
91+
92+
When developing on the chart locally, just specify the path to the chart where you've cloned it:
93+
94+
```sh
95+
$ helm upgrade gcp-pubsub-connector ./chart/gcp-pubsub-connector \
96+
--install \
97+
--namespace openfaas \
98+
-f values.yaml
99+
```
100+
101+
## Removing the gcp-pubsub-connector
102+
103+
All control plane components can be cleaned up with helm:
104+
105+
```sh
106+
$ helm uninstall -n openfaas gcp-pubsub-connector
107+
```

Diff for: chart/gcp-pubsub-connector/templates/_helpers.tpl

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{{/* vim: set filetype=mustache: */}}
2+
{{/*
3+
Expand the name of the chart.
4+
*/}}
5+
{{- define "connector.name" -}}
6+
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
7+
{{- end -}}
8+
9+
{{/*
10+
Create a default fully qualified app name.
11+
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
12+
If release name contains chart name it will be used as a full name.
13+
*/}}
14+
{{- define "connector.fullname" -}}
15+
{{- if .Values.fullnameOverride -}}
16+
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
17+
{{- else -}}
18+
{{- $name := default .Chart.Name .Values.nameOverride -}}
19+
{{- if contains $name .Release.Name -}}
20+
{{- .Release.Name | trunc 63 | trimSuffix "-" -}}
21+
{{- else -}}
22+
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
23+
{{- end -}}
24+
{{- end -}}
25+
{{- end -}}
26+
27+
{{/*
28+
Create chart name and version as used by the chart label.
29+
*/}}
30+
{{- define "connector.chart" -}}
31+
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
32+
{{- end -}}
33+

Diff for: chart/gcp-pubsub-connector/templates/deployment.yml

+126
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
labels:
5+
app: {{ template "connector.name" . }}
6+
component: gcp-pubsub-connector
7+
chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
8+
heritage: {{ .Release.Service }}
9+
release: {{ .Release.Name }}
10+
app.kubernetes.io/name: {{ template "connector.name" . }}
11+
app.kubernetes.io/instance: {{ .Release.Name }}
12+
app.kubernetes.io/version: {{ .Chart.Version }}
13+
app.kubernetes.io/component: gcp-pubsub-connector
14+
app.kubernetes.io/part-of: openfaas
15+
app.kubernetes.io/managed-by: {{ .Release.Service }}
16+
helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
17+
name: {{ template "connector.fullname" . }}
18+
namespace: {{ .Release.Namespace | quote }}
19+
spec:
20+
replicas: {{ .Values.replicas }}
21+
selector:
22+
matchLabels:
23+
app: {{ template "connector.name" . }}
24+
component: gcp-pubsub-connector
25+
26+
template:
27+
metadata:
28+
annotations:
29+
prometheus.io/scrape: "false"
30+
labels:
31+
app: {{ template "connector.name" . }}
32+
component: gcp-pubsub-connector
33+
spec:
34+
volumes:
35+
- name: openfaas-license
36+
secret:
37+
secretName: openfaas-license
38+
{{- if .Values.basic_auth }}
39+
- name: auth
40+
secret:
41+
secretName: basic-auth
42+
{{- end }}
43+
{{- if .Values.gcpCredentialsSecret }}
44+
- name: gcp-pubsub-credentials
45+
secret:
46+
secretName: {{ .Values.gcpCredentialsSecret }}
47+
{{- end }}
48+
containers:
49+
- name: connector
50+
image: {{ .Values.image }}
51+
command:
52+
- "/usr/bin/connector"
53+
- "-license-file=/var/secrets/license/license"
54+
env:
55+
- name: gateway_url
56+
value: {{ .Values.gatewayURL | quote }}
57+
- name: print_response
58+
value: {{ .Values.printResponse | quote }}
59+
- name: print_response_body
60+
value: {{ .Values.printResponseBody | quote }}
61+
- name: print_request_body
62+
value: {{ .Values.printRequestBody | quote }}
63+
- name: asynchronous_invocation
64+
value: {{ .Values.asyncInvocation | quote }}
65+
- name: project_id
66+
value: {{ .Values.projectID | quote }}
67+
- name: subscriptions
68+
value: {{ .Values.subscriptions | toJson | quote }}
69+
{{- if .Values.basic_auth }}
70+
- name: basic_auth
71+
value: "true"
72+
- name: secret_mount_path
73+
value: "/var/secrets"
74+
{{- end }}
75+
{{- if .Values.upstreamTimeout }}
76+
- name: upstream_timeout
77+
value: {{ .Values.upstreamTimeout | quote }}
78+
{{- end }}
79+
{{- if .Values.rebuildInterval }}
80+
- name: rebuild_interval
81+
value: {{ .Values.rebuildInterval | quote }}
82+
{{- end }}
83+
- name: content_type
84+
value: {{ .Values.contentType | quote }}
85+
- name: "debug"
86+
value: "{{ .Values.logs.debug }}"
87+
- name: "log_encoding"
88+
value: "{{ .Values.logs.format }}"
89+
{{- if .Values.gcpCredentialsSecret }}
90+
- name: GOOGLE_APPLICATION_CREDENTIALS
91+
value: /var/secrets/gcp-pubsub-credentials/gcp-pubsub-credentials
92+
{{- end}}
93+
resources:
94+
{{- .Values.resources | toYaml | nindent 12 }}
95+
96+
{{- if .Values.securityContext }}
97+
securityContext:
98+
{{- toYaml .Values.securityContext | nindent 12 }}
99+
{{- end }}
100+
volumeMounts:
101+
- name: openfaas-license
102+
readOnly: true
103+
mountPath: "/var/secrets/license"
104+
{{- if .Values.basic_auth }}
105+
- name: auth
106+
readOnly: true
107+
mountPath: "/var/secrets"
108+
{{- end }}
109+
{{- if .Values.gcpCredentialsSecret }}
110+
- name: gcp-pubsub-credentials
111+
readOnly: true
112+
mountPath: "/var/secrets/gcp-pubsub-credentials"
113+
{{- end }}
114+
115+
{{- with .Values.nodeSelector }}
116+
nodeSelector:
117+
{{ toYaml . | indent 8 }}
118+
{{- end }}
119+
{{- with .Values.affinity }}
120+
affinity:
121+
{{ toYaml . | indent 8 }}
122+
{{- end }}
123+
{{- with .Values.tolerations }}
124+
tolerations:
125+
{{ toYaml . | indent 8 }}
126+
{{- end }}

0 commit comments

Comments
 (0)