From 1992bcb49c77c99e0c0eebfb9bc2624e061f2f60 Mon Sep 17 00:00:00 2001 From: Michael Gasch Date: Wed, 18 Dec 2019 11:40:57 +0100 Subject: [PATCH] Add helm chart for vcenter-connector This commit adds a helm chart for the OpenFaaS [vcenter-connector](https://github.com/openfaas-incubator/vcenter-connector). The chart is a modified version of the `kafka-connector` helm chart provided in this repo. This commit includes: - [x] A README how to use the chart - [x] A chart following the ones provided in the OpenFaaS `faas-netes` repository - [x] vcenter-connector uses flags so `values.yaml` was modified to support flags (`extraArgs`) - [x] Resource requests to guarantee compute resources for the connector - [x] Updates to the Makefile to include this chart in the Helm chart index Signed-off-by: Michael Gasch --- Makefile | 2 +- chart/vcenter-connector/.helmignore | 22 ++++ chart/vcenter-connector/Chart.yaml | 18 +++ chart/vcenter-connector/README.md | 74 ++++++++++++ chart/vcenter-connector/templates/NOTES.txt | 7 ++ .../vcenter-connector/templates/_helpers.tpl | 33 ++++++ .../templates/deployment.yml | 106 ++++++++++++++++++ chart/vcenter-connector/values.yaml | 21 ++++ 8 files changed, 282 insertions(+), 1 deletion(-) create mode 100644 chart/vcenter-connector/.helmignore create mode 100644 chart/vcenter-connector/Chart.yaml create mode 100644 chart/vcenter-connector/README.md create mode 100644 chart/vcenter-connector/templates/NOTES.txt create mode 100644 chart/vcenter-connector/templates/_helpers.tpl create mode 100644 chart/vcenter-connector/templates/deployment.yml create mode 100644 chart/vcenter-connector/values.yaml diff --git a/Makefile b/Makefile index 4551b2a6b0..7395b4cbad 100644 --- a/Makefile +++ b/Makefile @@ -28,7 +28,7 @@ install-armhf: namespaces kubectl apply -f yaml_armhf/ charts: - cd chart && helm package openfaas/ && helm package kafka-connector/ && helm package cron-connector/ + cd chart && helm package openfaas/ && helm package kafka-connector/ && helm package cron-connector/ && helm package vcenter-connector/ mv chart/*.tgz docs/ helm repo index docs --url https://openfaas.github.io/faas-netes/ --merge ./docs/index.yaml ./contrib/create-static-manifest.sh diff --git a/chart/vcenter-connector/.helmignore b/chart/vcenter-connector/.helmignore new file mode 100644 index 0000000000..50af031725 --- /dev/null +++ b/chart/vcenter-connector/.helmignore @@ -0,0 +1,22 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ diff --git a/chart/vcenter-connector/Chart.yaml b/chart/vcenter-connector/Chart.yaml new file mode 100644 index 0000000000..cff0901649 --- /dev/null +++ b/chart/vcenter-connector/Chart.yaml @@ -0,0 +1,18 @@ +apiVersion: v1 +description: Connect OpenFaaS functions to vCenter events +name: vcenter-connector +version: 0.4.0 +sources: +- https://github.com/openfaas-incubator/openfaas-vcenter-connector +home: https://www.openfaas.com +icon: https://raw.githubusercontent.com/openfaas/media/master/OpenFaaS_logo_stacked_opaque.png +keywords: +- functions +- service +- vCenter +- vmware +maintainers: +- name: alexellis + email: alex@openfaas.com +- name: embano1 + email: mgasch@vmware.com diff --git a/chart/vcenter-connector/README.md b/chart/vcenter-connector/README.md new file mode 100644 index 0000000000..29030c9df7 --- /dev/null +++ b/chart/vcenter-connector/README.md @@ -0,0 +1,74 @@ +# OpenFaaS vCenter Connector + +The [OpenFaaS vCenter connector](https://github.com/openfaas-incubator/openfaas-vcenter-connector) brings vCenter events to OpenFaaS by invoking functions based on vCenter event(s) topic annotations. + +## Prerequisites + +- Install OpenFaaS + + You must have a working OpenFaaS installation. You can find [instructions in the docs](https://docs.openfaas.com/deployment/kubernetes/#pick-helm-or-yaml-files-for-deployment-a-or-b), including instructions to also install OpenFaaS via Helm. + +- Have a working VMware vCenter environment (dev/testing) that you can connect to + +## Install the Chart + +- Create a Kubernetes secret holding the vCenter credentials to be used by the vcenter-connector + +``` +kubectl create secret generic vcenter-secrets \ + -n openfaas \ + --from-literal vcenter-username=user \ + --from-literal vcenter-password=pass +``` + +> **Note:** Replace "user" and "pass" with the actual values. It is a good practice to use a dedicated vCenter service account instead of an administrator role for the vcenter-connector. + +- Add the OpenFaaS chart repo and deploy the `vcenter-connector` chart. We recommend installing it in the same namespace as the rest of OpenFaaS + +```sh +$ helm repo add openfaas https://openfaas.github.io/faas-netes/ +$ helm upgrade vcenter-connector openfaas/vcenter-connector \ + --install \ + --namespace openfaas +``` + +> **Note:** The above command will also update your helm repo to pull in any new releases. + +After you have [verified](#verify-the-installationtroubleshooting) that the installation succeeded you might want to run through an actual [function example](https://github.com/openfaas-incubator/openfaas-vcenter-connector#examples--community). + +### Verify the installation/Troubleshooting + +1) Check that the `vcenter-connector` deployment in the given Kubernetes namespace (default: "openfaas") is ready, i.e. shows `1/1` pods in running state +2) If you see error messages or `0/1` (note: it might take some time to pull the container image) verify that + 1) you have followed the [installation](#install-the-chart) steps as outlined above (vCenter secret deployed?) + 2) the status of the corresponding `ReplicaSet` with `kubectl -n openfaas get rs` + 3) the logs of the container don't show any errors with `kubectl -n openfaas logs deploy/vcenter-connector` + +## Customizing the Helm Chart + +Additional vcenter-connector options in `values.yaml`: + +| Parameter | Description | Default | +|----------------------|-----------------------------------------------------------------------------------|--------------------------------| +| `resources.requests` | Compute resources Kubernetes will guarantee to this pod | `100m (CPU), 120Mi (Memory)` | +| `vc_k8s_secret` | vCenter secrets name as stored in Kubernetes | `vcenter-secrets` | +| `basic_auth` | Use basic authentication against OpenFaaS gateway | `true` | +| `extraArgs.gateway` | The URL of the OpenFaaS API gateway | `http://gateway.openfaas:8080` | +| `extraArgs.vcenter` | The URL of the vCenter server | `http://vcsim.openfaas:8989` | +| `extraArgs.insecure` | Don't verify vCenter server certificate (remove this parameter to force checking) | `insecure` | + +Specify each parameter you want to change using the `--set key=value[,key=value]` argument to `helm install`, e.g.: + +``` +helm install vcenter-connector ./vcenter-connector --namespace openfaas --set extraArgs.vcenter=https://10.160.94.63/sdk +``` + +See `values.yaml` for detailed configuration. + +## Removing the vCenter Connector + +The vCenter connector can be cleaned up with the following helm command: + +```sh +helm uninstall vcenter-connector --namespace openfaas +``` diff --git a/chart/vcenter-connector/templates/NOTES.txt b/chart/vcenter-connector/templates/NOTES.txt new file mode 100644 index 0000000000..f843f6e557 --- /dev/null +++ b/chart/vcenter-connector/templates/NOTES.txt @@ -0,0 +1,7 @@ +Thank you for installing vcenter-connector. Please follow the instructions below to retrieve the status of the connector. +If you experience problems please also refer to the troubleshooting instructions in the README provided with this chart. + +You can watch the Connector logs to see incoming vCenter events and invoked functions based on topic annotations (if any): + +$ kubectl logs -n {{ .Release.Namespace }} deploy/{{ template "connector.fullname" . }} -f + diff --git a/chart/vcenter-connector/templates/_helpers.tpl b/chart/vcenter-connector/templates/_helpers.tpl new file mode 100644 index 0000000000..f0df50a579 --- /dev/null +++ b/chart/vcenter-connector/templates/_helpers.tpl @@ -0,0 +1,33 @@ +{{/* vim: set filetype=mustache: */}} +{{/* +Expand the name of the chart. +*/}} +{{- define "connector.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} +{{- end -}} + +{{/* +Create a default fully qualified app name. +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +If release name contains chart name it will be used as a full name. +*/}} +{{- define "connector.fullname" -}} +{{- if .Values.fullnameOverride -}} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}} +{{- else -}} +{{- $name := default .Chart.Name .Values.nameOverride -}} +{{- if contains $name .Release.Name -}} +{{- .Release.Name | trunc 63 | trimSuffix "-" -}} +{{- else -}} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}} +{{- end -}} +{{- end -}} +{{- end -}} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "connector.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} +{{- end -}} + diff --git a/chart/vcenter-connector/templates/deployment.yml b/chart/vcenter-connector/templates/deployment.yml new file mode 100644 index 0000000000..5a33886a7f --- /dev/null +++ b/chart/vcenter-connector/templates/deployment.yml @@ -0,0 +1,106 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + # Original Helm labels v + app: {{ template "connector.name" . }} + component: vcenter-connector + chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }} + heritage: {{ .Release.Service }} + release: {{ .Release.Name }} + # Helm/k8s recommended label names v + app.kubernetes.io/name: {{ template "connector.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + app.kubernetes.io/version: {{ .Chart.Version }} + app.kubernetes.io/component: vcenter-connector + app.kubernetes.io/part-of: openfaas + app.kubernetes.io/managed-by: {{ .Release.Service }} + helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }} + name: {{ template "connector.fullname" . }} + namespace: {{ .Release.Namespace | quote }} +spec: + replicas: {{ .Values.replicas }} + selector: + matchLabels: + app: {{ template "connector.name" . }} + component: vcenter-connector + template: + metadata: + annotations: + prometheus.io.scrape: "false" + labels: + app: {{ template "connector.name" . }} + component: vcenter-connector + spec: + volumes: + - name: auth-secrets-projected + projected: + defaultMode: 420 + sources: + {{- if .Values.basic_auth }} + - secret: + items: + - key: basic-auth-user + path: basic-auth-user + - key: basic-auth-password + path: basic-auth-password + name: basic-auth + {{- end }} + - secret: + items: + - key: vcenter-username + path: vcenter-username + - key: vcenter-password + path: vcenter-password + name: {{ .Values.vc_k8s_secret | quote }} + containers: + - name: vcenter + image: {{ .Values.image }} + resources: + {{- .Values.resources | toYaml | nindent 12 }} + command: ["./connector"] + args: + {{- range $key, $value := .Values.extraArgs }} + {{- if $value }} + - --{{ $key }}={{ $value }} + {{- else }} + - --{{ $key }} + {{- end }} + {{- end }} + env: + - name: gateway_url + value: {{ .Values.extraArgs.gateway | quote }} + - name: print_response + value: {{ .Values.print_response | quote }} + - name: print_response_body + value: {{ .Values.print_response_body | quote }} + - name: secret_mount_path + value: {{ .Values.secret_mount | quote }} + {{- if .Values.basic_auth }} + - name: basic_auth + value: "true" + {{- end }} + {{- if .Values.upstream_timeout }} + - name: upstream_timeout + value: {{ .Values.upstream_timeout | quote }} + {{- end }} + {{- if .Values.rebuild_interval }} + - name: rebuild_interval + value: {{ .Values.rebuild_interval | quote }} + {{- end }} + volumeMounts: + - name: auth-secrets-projected + readOnly: true + mountPath: "/var/openfaas/secrets/" + {{- with .Values.nodeSelector }} + nodeSelector: +{{ toYaml . | indent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: +{{ toYaml . | indent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: +{{ toYaml . | indent 8 }} + {{- end }} diff --git a/chart/vcenter-connector/values.yaml b/chart/vcenter-connector/values.yaml new file mode 100644 index 0000000000..d524c62af1 --- /dev/null +++ b/chart/vcenter-connector/values.yaml @@ -0,0 +1,21 @@ +image: openfaas/vcenter-connector:0.4.0 +replicas: 1 +resources: + requests: + memory: "120Mi" + cpu: "100m" +vc_k8s_secret: vcenter-secrets +secret_mount: /var/openfaas/secrets/ +basic_auth: true +extraArgs: + gateway: http://gateway.openfaas:8080 + vcenter: http://vcsim.openfaas:8989 + vc-user-secret-name: vcenter-username + vc-pass-secret-name: vcenter-password + insecure: + +nodeSelector: {} + +tolerations: [] + +affinity: {}