diff --git a/.github/workflows/cd-helm-release.yml b/.github/workflows/cd-helm-release.yml new file mode 100644 index 0000000..4faf87c --- /dev/null +++ b/.github/workflows/cd-helm-release.yml @@ -0,0 +1,39 @@ +name: Release Helm Chart +concurrency: chart_releaser + +on: + push: + branches: + - main + paths: + - 'charts/generic-device-plugin/**' + +jobs: + release: + # depending on default permission settings for your org (contents being read-only or read-write for workloads), you will have to add permissions + # see: https://docs.github.com/en/actions/security-guides/automatic-token-authentication#modifying-the-permissions-for-the-github_token + permissions: + contents: write + runs-on: ubuntu-22.04 + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Fetch history + run: git fetch --prune --unshallow + + - name: Configure Git + run: | + git config user.name "$GITHUB_ACTOR" + git config user.email "$GITHUB_ACTOR@users.noreply.github.com" + + - name: Set up Helm + uses: azure/setup-helm@v3.5 + with: + version: v3.14.3 + + - name: Run chart-releaser for generic-device-plugin + uses: helm/chart-releaser-action@v1.6.0 + env: + CR_GENERATE_RELEASE_NOTES: true + CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}" diff --git a/.github/workflows/ci-helm-lint-test.yml b/.github/workflows/ci-helm-lint-test.yml new file mode 100644 index 0000000..c198731 --- /dev/null +++ b/.github/workflows/ci-helm-lint-test.yml @@ -0,0 +1,38 @@ +name: Lint Chart + +on: + pull_request: + paths: + - 'charts/generic-device-plugin/**' + +permissions: + contents: read + +jobs: + lint: + name: Lint + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: "0" + + - name: Install Helm + uses: azure/setup-helm@v4 + + - name: Set up chart-testing + uses: helm/chart-testing-action@v2.6.1 + + - name: Run chart-testing (list-changed) + id: list-changed + run: | + changed=$(ct list-changed --target-branch ${{ github.event.repository.default_branch }}) + if [[ -n "$changed" ]]; then + echo "changed=true" >> "$GITHUB_OUTPUT" + fi + + - name: Run chart-testing (lint) + id: lint + if: steps.list-changed.outputs.changed == 'true' + run: ct lint --target-branch ${{ github.event.repository.default_branch }} diff --git a/charts/generic-device-plugin/.helmignore b/charts/generic-device-plugin/.helmignore new file mode 100644 index 0000000..0e8a0eb --- /dev/null +++ b/charts/generic-device-plugin/.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/generic-device-plugin/Chart.yaml b/charts/generic-device-plugin/Chart.yaml new file mode 100644 index 0000000..71c65a1 --- /dev/null +++ b/charts/generic-device-plugin/Chart.yaml @@ -0,0 +1,28 @@ +apiVersion: v2 +name: generic-device-plugin +description: A Helm chart for deploying the generic-device-plugin on Kubernetes + +# 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.1.0" + +maintainers: + - name: squat + url: https://github.com/squat diff --git a/charts/generic-device-plugin/README.md b/charts/generic-device-plugin/README.md new file mode 100644 index 0000000..3350915 --- /dev/null +++ b/charts/generic-device-plugin/README.md @@ -0,0 +1,50 @@ +# generic-device-plugin + +![Version: 0.1.0](https://img.shields.io/badge/Version-0.1.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 0.1.0](https://img.shields.io/badge/AppVersion-0.1.0-informational?style=flat-square) + +A Helm chart for deploying the generic-device-plugin on Kubernetes. + +## Tips + +Ensure that this is deployed into the `kube-system` namespace. + +### Installing directly from the git repo + +```bash +# clone the repo +git clone https://github.com/squat/generic-device-plugin + +# change to the chart directory +cd charts/generic-device-plugin + +# install the helm chart in the kube-system namespace +helm install -n kube-system generic-device-plugin . +``` + +## Maintainers + +| Name | Email | Url | +| ---- | ------ | --- | +| squat | | | + +## Values + +| Key | Type | Default | Description | +|-----|------|---------|-------------| +| deployPodMonitor | bool | `true` | deploy the podMonitor (requires PodMonitor CRD to be installed) | +| fullnameOverride | string | `""` | override the fullname of the chart resources | +| image.pullPolicy | string | `"Always"` | image pullPolicy is set to always because tag is set to latest | +| image.repository | string | `"squat/generic-device-plugin"` | container image repo | +| image.tag | string | `"latest"` | Overrides the image tag whose default is the chart appVersion. | +| nameOverride | string | `""` | override the name of the chart resources | +| podAnnotations | object | `{}` | additional annotations for the generic-device-plugin pod | +| podLabels | object | `{}` | additional labels for the generic-device-plugin pod | +| resources | object | `{"limits":{"cpu":"50m","memory":"20Mi"},"requests":{"cpu":"50m","memory":"10Mi"}}` | resource requests and limits for the generic-device-plugin pod | +| serviceAccount.annotations | object | `{}` | Annotations to add to the service account | +| serviceAccount.automount | bool | `true` | Automatically mount a ServiceAccount's API credentials? | +| serviceAccount.create | bool | `true` | Specifies whether a service account should be created | +| serviceAccount.name | string | `""` | The name of the service account to use. If not set and create is true, a name is generated using the fullname template | +| tolerations | list | `[{"effect":"NoExecute","operator":"Exists"},{"effect":"NoSchedule","operator":"Exists"}]` | tolerations of kubernetes taints | + +---------------------------------------------- +Autogenerated from chart metadata using [helm-docs v1.13.1](https://github.com/norwoodj/helm-docs/releases/v1.13.1) diff --git a/charts/generic-device-plugin/templates/_helpers.tpl b/charts/generic-device-plugin/templates/_helpers.tpl new file mode 100644 index 0000000..d323c54 --- /dev/null +++ b/charts/generic-device-plugin/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "generic-device-plugin.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 "generic-device-plugin.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 "generic-device-plugin.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "generic-device-plugin.labels" -}} +helm.sh/chart: {{ include "generic-device-plugin.chart" . }} +{{ include "generic-device-plugin.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "generic-device-plugin.selectorLabels" -}} +app.kubernetes.io/name: {{ include "generic-device-plugin.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "generic-device-plugin.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "generic-device-plugin.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/charts/generic-device-plugin/templates/daemonset.yaml b/charts/generic-device-plugin/templates/daemonset.yaml new file mode 100644 index 0000000..2a8dce2 --- /dev/null +++ b/charts/generic-device-plugin/templates/daemonset.yaml @@ -0,0 +1,115 @@ +apiVersion: apps/v1 +kind: DaemonSet +metadata: + name: {{ include "generic-device-plugin.fullname" . }} + namespace: kube-system + labels: + app.kubernetes.io/name: generic-device-plugin + {{- include "generic-device-plugin.labels" . | nindent 4 }} +spec: + selector: + matchLabels: + app.kubernetes.io/name: generic-device-plugin + template: + metadata: + {{- with .Values.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + app.kubernetes.io/name: generic-device-plugin + {{- include "generic-device-plugin.labels" . | nindent 8 }} + {{- with .Values.podLabels }} + {{- toYaml . | nindent 8 }} + {{- end }} + spec: + serviceAccountName: {{ include "generic-device-plugin.serviceAccountName" . }} + priorityClassName: system-node-critical + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} + containers: + - name: generic-device-plugin + image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + args: + - --device + - | + name: serial + groups: + - paths: + - path: /dev/ttyUSB* + - paths: + - path: /dev/ttyACM* + - paths: + - path: /dev/tty.usb* + - paths: + - path: /dev/cu.* + - paths: + - path: /dev/cuaU* + - paths: + - path: /dev/rfcomm* + - --device + - | + name: video + groups: + - paths: + - path: /dev/video0 + - --device + - | + name: fuse + groups: + - count: 10 + paths: + - path: /dev/fuse + - --device + - | + name: audio + groups: + - count: 10 + paths: + - path: /dev/snd + - --device + - | + name: capture + groups: + - paths: + - path: /dev/snd/controlC0 + - path: /dev/snd/pcmC0D0c + - paths: + - path: /dev/snd/controlC1 + mountPath: /dev/snd/controlC0 + - path: /dev/snd/pcmC1D0c + mountPath: /dev/snd/pcmC0D0c + - paths: + - path: /dev/snd/controlC2 + mountPath: /dev/snd/controlC0 + - path: /dev/snd/pcmC2D0c + mountPath: /dev/snd/pcmC0D0c + - paths: + - path: /dev/snd/controlC3 + mountPath: /dev/snd/controlC0 + - path: /dev/snd/pcmC3D0c + mountPath: /dev/snd/pcmC0D0c + resources: + {{- toYaml .Values.resources | nindent 12 }} + ports: + - containerPort: 8080 + name: http + securityContext: + privileged: true + volumeMounts: + - name: device-plugin + mountPath: /var/lib/kubelet/device-plugins + - name: dev + mountPath: /dev + volumes: + - name: device-plugin + hostPath: + path: /var/lib/kubelet/device-plugins + - name: dev + hostPath: + path: /dev + updateStrategy: + type: RollingUpdate diff --git a/charts/generic-device-plugin/templates/podmonitor.yaml b/charts/generic-device-plugin/templates/podmonitor.yaml new file mode 100644 index 0000000..a747d58 --- /dev/null +++ b/charts/generic-device-plugin/templates/podmonitor.yaml @@ -0,0 +1,18 @@ +{{- if .Values.deployPodMonitor }} +apiVersion: monitoring.coreos.com/v1 +kind: PodMonitor +metadata: + labels: + app.kubernetes.io/name: generic-device-plugin + {{- include "generic-device-plugin.labels" . | nindent 4 }} + name: {{ include "generic-device-plugin.fullname" . }} + namespace: kube-system +spec: + podMetricsEndpoints: + - interval: 15s + port: http + path: /metrics + selector: + matchLabels: + app.kubernetes.io/name: generic-device-plugin +{{- end }} diff --git a/charts/generic-device-plugin/templates/serviceaccount.yaml b/charts/generic-device-plugin/templates/serviceaccount.yaml new file mode 100644 index 0000000..d9ceb6f --- /dev/null +++ b/charts/generic-device-plugin/templates/serviceaccount.yaml @@ -0,0 +1,13 @@ +{{- if .Values.serviceAccount.create -}} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "generic-device-plugin.serviceAccountName" . }} + labels: + {{- include "generic-device-plugin.labels" . | nindent 4 }} + {{- with .Values.serviceAccount.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +automountServiceAccountToken: {{ .Values.serviceAccount.automount }} +{{- end }} diff --git a/charts/generic-device-plugin/values.yaml b/charts/generic-device-plugin/values.yaml new file mode 100644 index 0000000..84945e0 --- /dev/null +++ b/charts/generic-device-plugin/values.yaml @@ -0,0 +1,51 @@ +# Default values for generic-device-plugin. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +image: + # -- container image repo + repository: squat/generic-device-plugin + # -- image pullPolicy is set to always because tag is set to latest + pullPolicy: Always + # -- Overrides the image tag whose default is the chart appVersion. + tag: "latest" + +# -- override the name of the chart resources +nameOverride: "" +# -- override the fullname of the chart resources +fullnameOverride: "" + +serviceAccount: + # -- Specifies whether a service account should be created + create: true + # -- Automatically mount a ServiceAccount's API credentials? + automount: true + # -- Annotations to add to the service account + annotations: {} + # -- The name of the service account to use. + # If not set and create is true, a name is generated using the fullname template + name: "" + +# -- additional annotations for the generic-device-plugin pod +podAnnotations: {} +# -- additional labels for the generic-device-plugin pod +podLabels: {} + +# -- resource requests and limits for the generic-device-plugin pod +resources: + requests: + cpu: 50m + memory: 10Mi + limits: + cpu: 50m + memory: 20Mi + +# -- tolerations of kubernetes taints +tolerations: + - operator: "Exists" + effect: "NoExecute" + - operator: "Exists" + effect: "NoSchedule" + +# -- deploy the podMonitor (requires PodMonitor CRD to be installed) +deployPodMonitor: true