From 94b038cee8518b30178d3f8ac5923ace38b47753 Mon Sep 17 00:00:00 2001 From: Nathan Wang Date: Wed, 7 Jun 2023 23:03:25 -0700 Subject: [PATCH] fleet-telemetry helm chart --- charts/fleet-telemetry/.helmignore | 23 +++ charts/fleet-telemetry/Chart.yaml | 23 +++ charts/fleet-telemetry/README.md | 156 ++++++++++++++++++ .../templates/0-configmap.yaml | 9 + .../fleet-telemetry/templates/1-secret.yaml | 16 ++ .../templates/2-deployment.yaml | 76 +++++++++ .../fleet-telemetry/templates/3-service.yaml | 19 +++ .../templates/4-service-internal.yaml | 17 ++ charts/fleet-telemetry/templates/_helpers.tpl | 62 +++++++ charts/fleet-telemetry/values.yaml | 41 +++++ 10 files changed, 442 insertions(+) create mode 100644 charts/fleet-telemetry/.helmignore create mode 100644 charts/fleet-telemetry/Chart.yaml create mode 100644 charts/fleet-telemetry/README.md create mode 100644 charts/fleet-telemetry/templates/0-configmap.yaml create mode 100644 charts/fleet-telemetry/templates/1-secret.yaml create mode 100644 charts/fleet-telemetry/templates/2-deployment.yaml create mode 100644 charts/fleet-telemetry/templates/3-service.yaml create mode 100644 charts/fleet-telemetry/templates/4-service-internal.yaml create mode 100644 charts/fleet-telemetry/templates/_helpers.tpl create mode 100644 charts/fleet-telemetry/values.yaml diff --git a/charts/fleet-telemetry/.helmignore b/charts/fleet-telemetry/.helmignore new file mode 100644 index 0000000..0e8a0eb --- /dev/null +++ b/charts/fleet-telemetry/.helmignore @@ -0,0 +1,23 @@ +# 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 +*.orig +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ diff --git a/charts/fleet-telemetry/Chart.yaml b/charts/fleet-telemetry/Chart.yaml new file mode 100644 index 0000000..c4487f3 --- /dev/null +++ b/charts/fleet-telemetry/Chart.yaml @@ -0,0 +1,23 @@ +apiVersion: v2 +name: fleet-telemetry +description: An Open Source Helm chart for fleet-telemetry +# A chart can be either an 'application' or a 'library' chart. +# +# Application charts are a collection of templates that can be packaged into versioned archives +# to be deployed. +# +# Library charts provide useful utilities or functions for the chart developer. They're included as +# a dependency of application charts to inject those utilities and functions into the rendering +# pipeline. Library charts do not define any templates and therefore cannot be deployed. +type: application +# This is the chart version. This version number should be incremented each time you make changes +# to the chart and its templates, including the app version. +# Versions are expected to follow Semantic Versioning (https://semver.org/) +version: 0.1.0 +# This is the version number of the application being deployed. This version number should be +# incremented each time you make changes to the application. Versions are not expected to +# follow Semantic Versioning. They should reflect the version the application is using. +# It is recommended to use it with quotes. +appVersion: "0.0.3" +maintainers: + - name: nathwang diff --git a/charts/fleet-telemetry/README.md b/charts/fleet-telemetry/README.md new file mode 100644 index 0000000..1da407b --- /dev/null +++ b/charts/fleet-telemetry/README.md @@ -0,0 +1,156 @@ +# Fleet Telemetry Helm Chart +* Installs the fleet-telemetry system. [fleet-telemetry](https://github.com/teslamotors/fleet-telemetry) +## Get Repo Info +```console +helm repo add teslamotors https://teslamotors.github.io/helm-charts/ +helm repo update +``` +_See [helm repo](https://helm.sh/docs/helm/helm_repo/) for command documentation._ + +## Installing the Chart + +To install the chart with the release name `fleet-telemetry`: + +```console +helm install fleet-telemetry charts/fleet-telemetry -n fleet-telemetry +``` + +## Uninstalling the Chart + +To uninstall/delete the fleet-telemetry deployment: + +```console +helm uninstall fleet-telemetry -n fleet-telemetry +``` +The command removes all the Kubernetes components associated with the chart and deletes the release. + +## Upgrade the Chart +To upgrade the chart with the release name `fleet-telemetry`: +```console +helm upgrade fleet-telemetry charts/fleet-telemetry -n fleet-telemetry +``` + +## Configuration +| Parameter | Description | Default | +|-----------------------|-------------------------------------------------------------------------------------|-------------------------| +| `tlsSecret.name` | Name of existing secret, if this value is set `tlsCrt` and `tlsKey` will be ignored | `nil` | +| `tlsSecret.tlsCrt` | value of the certification | `nil` | +| `tlsSecret.tlsKey` | value of the encryption key | `nil` | +| `image.repository` | value of the docker image repo | `tesla/fleet-telemetry` | +| `image.tag` | value of the docker image tag | `v0.0.3` | +| `resources` | CPU/Memory resource requests/limits | {} | +| `nodeSelector` | Node labels for pod assignment | {} | +| `tolerations` | Toleration labels for pod assignment | {} | +| `replicas` | Number of pods | `1` | +| `service.annotations` | Service Annotations | {} | +| `service.type` | Service Type | ClusterIP | + +## Example +* Set `config.data` in `values.yaml` +```yaml +service: + annotations: + service.beta.kubernetes.io/aws-load-balancer-scheme: "internet-facing" + service.beta.kubernetes.io/aws-load-balancer-type: "nlb-ip" + service.beta.kubernetes.io/aws-load-balancer-nlb-target-type: "ip" + service.beta.kubernetes.io/aws-load-balancer-subnets: subnet-1, subnet-2, subnet-3 + type: LoadBalancer +tlsSecret: + tlsCrt: | + value of the cert PEM + tlsKey: | + value the private key +config: + data: | + { + "host": "0.0.0.0", + "port": 8443, + "status_port": 8080, + "log_level": "info", + "json_log_enable": true, + "namespace": "tesla_telemetry", + "reliable_ack": false, + "monitoring": { + "prometheus_metrics_port": 9273, + "profiler_port": 4269, + "profiling_path": "/tmp/trace.out" + }, + "rate_limit": { + "enabled": true, + "message_interval_time": 30, + "message_limit": 1000 + }, + "records": { + "alerts": [ + "logger" + ], + "errors": [ + "logger" + ], + "V": [ + "logger" + ] + }, + "tls": { + "server_cert": "/etc/certs/server/tls.crt", + "server_key": "/etc/certs/server/tls.key" + } + } +``` +```console +helm install fleet-telemetry teslamotors/fleet-telemetry -n fleet-telemetry -f values.yaml +``` +* Set `config.data` by `--set-file` +```yaml +service: + annotations: + service.beta.kubernetes.io/aws-load-balancer-scheme: "internet-facing" + service.beta.kubernetes.io/aws-load-balancer-type: "nlb-ip" + service.beta.kubernetes.io/aws-load-balancer-nlb-target-type: "ip" + service.beta.kubernetes.io/aws-load-balancer-subnets: subnet-1, subnet-2, subnet-3 + type: LoadBalancer +tlsSecret: + tlsCrt: | + value of the cert PEM + tlsKey: | + value the private key +``` +```json +{ + "host": "0.0.0.0", + "port": 8443, + "status_port": 8080, + "log_level": "info", + "json_log_enable": true, + "namespace": "tesla_telemetry", + "reliable_ack": false, + "monitoring": { + "prometheus_metrics_port": 9273, + "profiler_port": 4269, + "profiling_path": "/tmp/trace.out" + }, + "rate_limit": { + "enabled": true, + "message_interval_time": 30, + "message_limit": 1000 + }, + "records": { + "alerts": [ + "logger" + ], + "errors": [ + "logger" + ], + "V": [ + "logger" + ] + }, + "tls": { + "server_cert": "/etc/certs/server/tls.crt", + "server_key": "/etc/certs/server/tls.key" + } +} +``` +```console +helm install fleet-telemetry teslamotors/fleet-telemetry -n fleet-telemetry -f values.yaml --set-file config.data=config.json +``` diff --git a/charts/fleet-telemetry/templates/0-configmap.yaml b/charts/fleet-telemetry/templates/0-configmap.yaml new file mode 100644 index 0000000..7a2c03f --- /dev/null +++ b/charts/fleet-telemetry/templates/0-configmap.yaml @@ -0,0 +1,9 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ include "fleet-telemetry.fullname" . }} + labels: + service: fleet-telemetry + {{- include "fleet-telemetry.labels" . | nindent 4 }} +data: + config.json: {{ .Values.config.data | toJson }} diff --git a/charts/fleet-telemetry/templates/1-secret.yaml b/charts/fleet-telemetry/templates/1-secret.yaml new file mode 100644 index 0000000..88a7fcd --- /dev/null +++ b/charts/fleet-telemetry/templates/1-secret.yaml @@ -0,0 +1,16 @@ +{{- if not .Values.tlsSecret.name -}} +apiVersion: v1 +kind: Secret +metadata: + name: {{ include "fleet-telemetry.fullname" . }} + labels: + {{- include "fleet-telemetry.labels" . | nindent 4 }} +data: + tls.crt: {{ required "tlsSecret.tlsCrt is required" + .Values.tlsSecret.tlsCrt | b64enc | quote + }} + tls.key: {{ required "tlsSecret.tlsKey is required" + .Values.tlsSecret.tlsKey | b64enc | quote + }} +type: kubernetes.io/tls +{{- end -}} diff --git a/charts/fleet-telemetry/templates/2-deployment.yaml b/charts/fleet-telemetry/templates/2-deployment.yaml new file mode 100644 index 0000000..dc5e7c7 --- /dev/null +++ b/charts/fleet-telemetry/templates/2-deployment.yaml @@ -0,0 +1,76 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "fleet-telemetry.fullname" . }} + labels: + role: api + service: fleet-telemetry + {{- include "fleet-telemetry.labels" . | nindent 4 }} +spec: + replicas: {{ .Values.replicas }} + selector: + matchLabels: + role: api + service: fleet-telemetry + {{- include "fleet-telemetry.selectorLabels" . | nindent 6 }} + template: + metadata: + labels: + role: api + service: fleet-telemetry + {{- include "fleet-telemetry.selectorLabels" . | nindent 8 }} + spec: + containers: + - command: + - /fleet-telemetry + - -config=/etc/fleet-telemetry/config.json + env: + - name: KUBERNETES_CLUSTER_DOMAIN + value: {{ quote .Values.kubernetesClusterDomain }} + image: {{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }} + livenessProbe: + failureThreshold: 5 + httpGet: + path: /metrics + port: {{ .Values.config.metrics.port }} + scheme: HTTP + initialDelaySeconds: 5 + timeoutSeconds: 10 + readinessProbe: + failureThreshold: 5 + httpGet: + path: /status + port: {{ .Values.config.status.port }} + scheme: HTTP + initialDelaySeconds: 5 + timeoutSeconds: 10 + name: fleet-telemetry + ports: + - containerPort: {{ .Values.config.profile.port }} + name: profile + protocol: TCP + - containerPort: {{ .Values.config.port }} + name: https + protocol: TCP + - containerPort: {{ .Values.config.metrics.port }} + name: metrics + protocol: TCP + resources: {{- toYaml .Values.resources | nindent 10 }} + volumeMounts: + - mountPath: /etc/fleet-telemetry/ + name: config + - mountPath: /etc/certs/server + name: server-certs + nodeSelector: {{- toYaml .Values.nodeSelector | nindent 8 }} + tolerations: {{- toYaml .Values.tolerations | nindent 8 }} + volumes: + - name: config + projected: + sources: + - configMap: + name: {{ include "fleet-telemetry.fullname" . }} + - name: server-certs + projected: + sources: + - secret: + name: {{ .Values.tlsSecret.name | default (printf "%s" (include "fleet-telemetry.fullname" .)) }} diff --git a/charts/fleet-telemetry/templates/3-service.yaml b/charts/fleet-telemetry/templates/3-service.yaml new file mode 100644 index 0000000..b024d53 --- /dev/null +++ b/charts/fleet-telemetry/templates/3-service.yaml @@ -0,0 +1,19 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "fleet-telemetry.fullname" . }} + labels: + prometheus_scrape: "true" + role: api + service: fleet-telemetry + {{- include "fleet-telemetry.labels" . | nindent 4 }} + annotations: + {{- .Values.service.annotations | toYaml | nindent 4 }} +spec: + type: {{ .Values.service.type }} + selector: + role: api + service: fleet-telemetry + {{- include "fleet-telemetry.selectorLabels" . | nindent 4 }} + ports: + {{- .Values.service.ports | toYaml | nindent 2 -}} diff --git a/charts/fleet-telemetry/templates/4-service-internal.yaml b/charts/fleet-telemetry/templates/4-service-internal.yaml new file mode 100644 index 0000000..c931e6b --- /dev/null +++ b/charts/fleet-telemetry/templates/4-service-internal.yaml @@ -0,0 +1,17 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "fleet-telemetry.fullname" . }}-internal + labels: + prometheus_scrape: "true" + role: api + service: fleet-telemetry + {{- include "fleet-telemetry.labels" . | nindent 4 }} +spec: + type: {{ .Values.serviceInternal.type }} + selector: + role: api + service: fleet-telemetry + {{- include "fleet-telemetry.selectorLabels" . | nindent 4 }} + ports: + {{- .Values.serviceInternal.ports | toYaml | nindent 2 -}} \ No newline at end of file diff --git a/charts/fleet-telemetry/templates/_helpers.tpl b/charts/fleet-telemetry/templates/_helpers.tpl new file mode 100644 index 0000000..911010b --- /dev/null +++ b/charts/fleet-telemetry/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "fleet-telemetry.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 "fleet-telemetry.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 "fleet-telemetry.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "fleet-telemetry.labels" -}} +helm.sh/chart: {{ include "fleet-telemetry.chart" . }} +{{ include "fleet-telemetry.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "fleet-telemetry.selectorLabels" -}} +app.kubernetes.io/name: {{ include "fleet-telemetry.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "fleet-telemetry.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "fleet-telemetry.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/charts/fleet-telemetry/values.yaml b/charts/fleet-telemetry/values.yaml new file mode 100644 index 0000000..a76ea52 --- /dev/null +++ b/charts/fleet-telemetry/values.yaml @@ -0,0 +1,41 @@ +tlsSecret: + name: "" + create: false + tlsCrt: "" + tlsKey: "" +image: + repository: tesla/fleet-telemetry + tag: v0.0.3 +resources: {} +nodeSelector: {} +tolerations: [] +replicas: 1 +service: + annotations: {} + ports: + - name: http + port: 80 + targetPort: 8080 + - name: https + port: 443 + targetPort: 8443 + type: ClusterIP +serviceInternal: + ports: + - name: metrics + port: 9273 + targetPort: 9273 + - name: profile + port: 4269 + targetPort: 4269 + type: ClusterIP +config: + data: "" + port: 8443 + status: + port: 8080 + metrics: + port: 9273 + profile: + port: 4269 +kubernetesClusterDomain: cluster.local