diff --git a/teslamate/.helmignore b/teslamate/.helmignore new file mode 100644 index 00000000..e559de0a --- /dev/null +++ b/teslamate/.helmignore @@ -0,0 +1,24 @@ +# 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/ +# OWNERS file for Kubernetes +OWNERS diff --git a/teslamate/Chart.yaml b/teslamate/Chart.yaml new file mode 100644 index 00000000..efa8bd50 --- /dev/null +++ b/teslamate/Chart.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +appVersion: "v1.13.2" +description: A self-hosted data logger for your Tesla 🚘 +name: teslamate +version: 1.0.0 +keywords: + - teslamate + - tesla +home: https://github.com/billimek/billimek-charts/tree/master/teslamate +icon: https://upload.wikimedia.org/wikipedia/commons/thumb/b/bd/Tesla_Motors.svg/793px-Tesla_Motors.svg.png +sources: + - https://github.com/adriankumpf/teslamate +maintainers: + - name: billimek + email: jeff@billimek.com diff --git a/teslamate/OWNERS b/teslamate/OWNERS new file mode 100644 index 00000000..51f88652 --- /dev/null +++ b/teslamate/OWNERS @@ -0,0 +1,4 @@ +approvers: +- billimek +reviewers: +- billimek \ No newline at end of file diff --git a/teslamate/README.md b/teslamate/README.md new file mode 100644 index 00000000..c6802662 --- /dev/null +++ b/teslamate/README.md @@ -0,0 +1,48 @@ +# A self-hosted data logger for your Tesla 🚘 + +This is an opinionated helm chart for [Teslamate](https://github.com/adriankumpf/teslamate) installed with a standalone postgresql database. + +The default values and container images used in this chart will allow for running in a multi-arch cluster (amd64, arm, arm64) + +## TL;DR; + +```shell +$ helm repo add billimek https://billimek.com/billimek-charts/ +$ helm install billimek/teslamate +``` + +## Installing the Chart + +To install the chart with the release name `my-release`: + +```console +helm install --name teslamate billimek/teslamate +``` + +## Uninstalling the Chart + +To uninstall/delete the `teslamate` deployment: + +```console +helm delete teslamate --purge +``` + +The command removes all the Kubernetes components associated with the chart and deletes the release. + +## Configuration + +Read through the [values.yaml](https://github.com/billimek/billimek-charts/blob/master/teslamate/values.yaml) file. It has several commented out suggested values. + +Specify each parameter using the `--set key=value[,key=value]` argument to `helm install`. For example, + +```console +helm install --name teslamate \ + --set timeZone="America/New York" \ + billimek/teslamate +``` + +Alternatively, a YAML file that specifies the values for the above parameters can be provided while installing the chart. For example, + +```console +helm install --name teslamate -f values.yaml stable/teslamate +``` diff --git a/teslamate/requirements.lock b/teslamate/requirements.lock new file mode 100644 index 00000000..37003794 --- /dev/null +++ b/teslamate/requirements.lock @@ -0,0 +1,6 @@ +dependencies: +- name: postgresql + repository: https://kubernetes-charts.storage.googleapis.com/ + version: 8.1.0 +digest: sha256:45a6e2b72556d60b954a11ef8de75a48678c6117c2e78a33619b277c3d893fd0 +generated: 2019-12-22T03:34:50.317972Z diff --git a/teslamate/requirements.yaml b/teslamate/requirements.yaml new file mode 100644 index 00000000..9485c9a3 --- /dev/null +++ b/teslamate/requirements.yaml @@ -0,0 +1,5 @@ +dependencies: +- name: postgresql + version: 8.1.0 + repository: https://kubernetes-charts.storage.googleapis.com/ + condition: postgresql.enabled \ No newline at end of file diff --git a/teslamate/templates/NOTES.txt b/teslamate/templates/NOTES.txt new file mode 100644 index 00000000..08243a9b --- /dev/null +++ b/teslamate/templates/NOTES.txt @@ -0,0 +1,21 @@ +1. Get the application URL by running these commands: +{{- if .Values.ingress.enabled }} +{{- range $host := .Values.ingress.hosts }} + {{- range $.Values.ingress.paths }} + http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host }}{{ . }} + {{- end }} +{{- end }} +{{- else if contains "NodePort" .Values.service.type }} + export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "teslamate.fullname" . }}) + export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}") + echo http://$NODE_IP:$NODE_PORT +{{- else if contains "LoadBalancer" .Values.service.type }} + NOTE: It may take a few minutes for the LoadBalancer IP to be available. + You can watch the status of by running 'kubectl get svc -w {{ include "teslamate.fullname" . }}' + export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "teslamate.fullname" . }} -o jsonpath='{.status.loadBalancer.ingress[0].ip}') + echo http://$SERVICE_IP:{{ .Values.service.port }} +{{- else if contains "ClusterIP" .Values.service.type }} + export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "teslamate.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}") + echo "Visit http://127.0.0.1:8080 to use your application" + kubectl port-forward $POD_NAME 8080:80 +{{- end }} diff --git a/teslamate/templates/_helpers.tpl b/teslamate/templates/_helpers.tpl new file mode 100644 index 00000000..af2b257a --- /dev/null +++ b/teslamate/templates/_helpers.tpl @@ -0,0 +1,41 @@ +{{/* vim: set filetype=mustache: */}} +{{/* +Expand the name of the chart. +*/}} +{{- define "teslamate.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 "teslamate.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 a default fully qualified postgresql name. +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +*/}} +{{- define "teslamate.postgresql.fullname" -}} +{{- $name := default "postgresql" .Values.postgresql.nameOverride -}} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}} +{{- end -}} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "teslamate.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} +{{- end -}} diff --git a/teslamate/templates/deployment.yaml b/teslamate/templates/deployment.yaml new file mode 100644 index 00000000..edf67743 --- /dev/null +++ b/teslamate/templates/deployment.yaml @@ -0,0 +1,108 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "teslamate.fullname" . }} + labels: + app.kubernetes.io/name: {{ include "teslamate.name" . }} + helm.sh/chart: {{ include "teslamate.chart" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + app.kubernetes.io/managed-by: {{ .Release.Service }} +spec: + replicas: {{ .Values.replicaCount }} + selector: + matchLabels: + app.kubernetes.io/name: {{ include "teslamate.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + template: + metadata: + labels: + app.kubernetes.io/name: {{ include "teslamate.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + spec: + containers: + - name: {{ .Chart.Name }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + env: + {{- if .Values.postgresql.postgresqlUsername }} + - name: DATABASE_USER + value: {{ .Values.postgresql.postgresqlUsername | quote }} + {{- end }} + {{- if .Values.postgresql.postgresqlPassword }} + - name: DATABASE_PASS + value: {{ .Values.postgresql.postgresqlPassword | quote }} + {{- end }} + {{- if .Values.postgresql.postgresqlDatabase }} + - name: DATABASE_NAME + value: {{ .Values.postgresql.postgresqlDatabase | quote }} + {{- end }} + - name: DATABASE_HOST + value: {{ template "teslamate.postgresql.fullname" . }} + {{- if .Values.mqtt.enabled }} + - name: MQTT_HOST + value: {{ .Values.mqtt.host | quote }} + - name: MQTT_USERNAME + value: {{ .Values.mqtt.username | quote }} + - name: MQTT_PASSWORD + value: {{ .Values.mqtt.password | quote }} + - name: MQTT_TLS + value: {{ .Values.mqtt.tls | quote }} + - name: MQTT_TLS_ACCEPT_INVALID_CERTS + value: {{ .Values.mqtt.tlsAcceptInvalid | quote }} + {{- else }} + - name: DISABLE_MQTT + value: "true" + {{- end }} + {{- if .Values.timeZone }} + - name: TZ + value: {{ .Values.timeZone | quote }} + {{- end }} + {{- if .Values.checkOrigin }} + - name: CHECK_ORIGIN + value: {{ .Values.checkOrigin | quote }} + {{- end }} + {{- if .Values.virtualHost }} + - name: VIRTUAL_HOST + value: {{ .Values.virtualHost | quote }} + {{- end }} + {{- if .Values.locale }} + - name: LOCALE + value: {{ .Values.locale | quote }} + {{- end }} + ports: + - name: http + containerPort: 4000 + protocol: TCP + livenessProbe: + httpGet: + path: / + port: http + failureThreshold: {{ .Values.probes.liveness.failureThreshold }} + periodSeconds: {{ .Values.probes.liveness.periodSeconds }} + readinessProbe: + httpGet: + path: / + port: http + failureThreshold: {{ .Values.probes.readiness.failureThreshold }} + periodSeconds: {{ .Values.probes.readiness.periodSeconds }} + startupProbe: + httpGet: + path: / + port: http + initialDelaySeconds: {{ .Values.probes.startup.initialDelaySeconds }} + failureThreshold: {{ .Values.probes.startup.failureThreshold }} + periodSeconds: {{ .Values.probes.startup.periodSeconds }} + resources: + {{- toYaml .Values.resources | nindent 12 }} + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} diff --git a/teslamate/templates/ingress.yaml b/teslamate/templates/ingress.yaml new file mode 100644 index 00000000..30ce5a8a --- /dev/null +++ b/teslamate/templates/ingress.yaml @@ -0,0 +1,38 @@ +{{- if .Values.ingress.enabled -}} +{{- $fullName := include "teslamate.fullname" . -}} +{{- $ingressPath := .Values.ingress.path -}} +apiVersion: extensions/v1beta1 +kind: Ingress +metadata: + name: {{ $fullName }} + labels: + app.kubernetes.io/name: {{ include "teslamate.name" . }} + helm.sh/chart: {{ include "teslamate.chart" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + app.kubernetes.io/managed-by: {{ .Release.Service }} + {{- with .Values.ingress.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: +{{- if .Values.ingress.tls }} + tls: + {{- range .Values.ingress.tls }} + - hosts: + {{- range .hosts }} + - {{ . | quote }} + {{- end }} + secretName: {{ .secretName }} + {{- end }} +{{- end }} + rules: + {{- range .Values.ingress.hosts }} + - host: {{ . | quote }} + http: + paths: + - path: {{ $ingressPath }} + backend: + serviceName: {{ $fullName }} + servicePort: http + {{- end }} +{{- end }} diff --git a/teslamate/templates/service.yaml b/teslamate/templates/service.yaml new file mode 100644 index 00000000..3650d8c4 --- /dev/null +++ b/teslamate/templates/service.yaml @@ -0,0 +1,19 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "teslamate.fullname" . }} + labels: + app.kubernetes.io/name: {{ include "teslamate.name" . }} + helm.sh/chart: {{ include "teslamate.chart" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + app.kubernetes.io/managed-by: {{ .Release.Service }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: http + protocol: TCP + name: http + selector: + app.kubernetes.io/name: {{ include "teslamate.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} diff --git a/teslamate/templates/tests/test-connection.yaml b/teslamate/templates/tests/test-connection.yaml new file mode 100644 index 00000000..f63ca1e9 --- /dev/null +++ b/teslamate/templates/tests/test-connection.yaml @@ -0,0 +1,18 @@ +apiVersion: v1 +kind: Pod +metadata: + name: "{{ include "teslamate.fullname" . }}-test-connection" + labels: + app.kubernetes.io/name: {{ include "teslamate.name" . }} + helm.sh/chart: {{ include "teslamate.chart" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + app.kubernetes.io/managed-by: {{ .Release.Service }} + annotations: + "helm.sh/hook": test-success +spec: + containers: + - name: wget + image: busybox + command: ['wget'] + args: ['{{ include "teslamate.fullname" . }}:{{ .Values.service.port }}'] + restartPolicy: Never diff --git a/teslamate/values.yaml b/teslamate/values.yaml new file mode 100644 index 00000000..adb24ba1 --- /dev/null +++ b/teslamate/values.yaml @@ -0,0 +1,134 @@ +replicaCount: 1 + +image: + repository: teslamate/teslamate + tag: 1.13.2 + pullPolicy: IfNotPresent + +nameOverride: "" +fullnameOverride: "" + +timeZone: UTC + +mqtt: + enabled: false + + # mqtt broker hostname - REQUIRED if mqtt is enabled + host: + + username: + password: + + # Enables TLS if true + tls: + # Accepts invalid certificates if true + tlsAcceptInvalid: + +# Configures whether to check the origin header or not. +checkOrigin: false + +# Host part used for generating URLs throughout the app +virtualHost: + +# valid values are 'en' or 'de' +locale: en + +# Probes configuration +probes: + liveness: + failureThreshold: 5 + periodSeconds: 10 + readiness: + failureThreshold: 5 + periodSeconds: 10 + startup: + initialDelaySeconds: 5 + failureThreshold: 30 + periodSeconds: 10 + +service: + type: ClusterIP + port: 4000 + +ingress: + enabled: false + annotations: {} + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + path: / + hosts: + - chart-example.local + tls: [] + # - secretName: chart-example-tls + # hosts: + # - chart-example.local + +resources: {} + # We usually recommend not to specify default resources and to leave this as a conscious + # choice for the user. This also increases chances charts run on environments with little + # resources, such as Minikube. If you do want to specify resources, uncomment the following + # lines, adjust them as necessary, and remove the curly braces after 'resources:'. + # limits: + # cpu: 100m + # memory: 128Mi + # requests: + # cpu: 100m + # memory: 128Mi + +nodeSelector: {} + +tolerations: [] + +affinity: {} + +## Configuration values for the postgresql dependency. +## Ref: https://github.com/helm/charts/blob/master/stable/postgresql/README.md +postgresql: + image: + repository: postgres + tag: 12.1 + postgresqlDataDir: "/data/pgdata" + + ### PostgreSQL User to create. + ## + postgresqlUsername: teslamate + + ## PostgreSQL Password for the new user. + ## If not set, a random 10 characters password will be used. + ## + postgresqlPassword: teslamate + + ## PostgreSQL Database to create. + ## + postgresqlDatabase: teslamate + + ## Persistent Volume Storage configuration for PostgreSQL. + ## + ## Ref: https://kubernetes.io/docs/user-guide/persistent-volumes + ## + persistence: + ## Enable PostgreSQL persistence using Persistent Volume Claims. + ## + enabled: true + + ## Persistent Volume Storage Class to be used by PersistentVolumes created + ## for PostgreSQL. + ## + ## If defined, storageClassName: + ## If set to "-", storageClassName: "", which disables dynamic provisioning + ## If undefined (the default) or set to null, no storageClassName spec is + ## set, choosing the default provisioner. (gp2 on AWS, standard on + ## GKE, AWS & OpenStack) + ## + storageClass: + + ## Persistent Volume Access Mode. + ## + accessModes: + - ReadWriteOnce + + ## Persistent Volume Storage Size. + ## + size: 8Gi + + mountPath: "/data/"