From 32fdea39c1efe25f6bc8b4e4c76a110b4b97c5ac Mon Sep 17 00:00:00 2001 From: Jrester Date: Mon, 28 Aug 2023 16:56:29 +0200 Subject: [PATCH] add ntfy --- charts/ntfy/.helmignore | 23 +++++ charts/ntfy/Chart.yaml | 6 ++ charts/ntfy/README.md | 49 +++++++++++ charts/ntfy/templates/NOTES.txt | 22 +++++ charts/ntfy/templates/_helpers.tpl | 62 +++++++++++++ charts/ntfy/templates/configmap.yaml | 7 ++ charts/ntfy/templates/hpa.yaml | 32 +++++++ charts/ntfy/templates/ingress.yaml | 61 +++++++++++++ charts/ntfy/templates/service.yaml | 15 ++++ charts/ntfy/templates/serviceaccount.yaml | 12 +++ charts/ntfy/templates/statefulset.yaml | 88 +++++++++++++++++++ .../ntfy/templates/tests/test-connection.yaml | 15 ++++ charts/ntfy/values.yaml | 80 +++++++++++++++++ 13 files changed, 472 insertions(+) create mode 100644 charts/ntfy/.helmignore create mode 100644 charts/ntfy/Chart.yaml create mode 100644 charts/ntfy/README.md create mode 100644 charts/ntfy/templates/NOTES.txt create mode 100644 charts/ntfy/templates/_helpers.tpl create mode 100644 charts/ntfy/templates/configmap.yaml create mode 100644 charts/ntfy/templates/hpa.yaml create mode 100644 charts/ntfy/templates/ingress.yaml create mode 100644 charts/ntfy/templates/service.yaml create mode 100644 charts/ntfy/templates/serviceaccount.yaml create mode 100644 charts/ntfy/templates/statefulset.yaml create mode 100644 charts/ntfy/templates/tests/test-connection.yaml create mode 100644 charts/ntfy/values.yaml diff --git a/charts/ntfy/.helmignore b/charts/ntfy/.helmignore new file mode 100644 index 0000000..0e8a0eb --- /dev/null +++ b/charts/ntfy/.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/ntfy/Chart.yaml b/charts/ntfy/Chart.yaml new file mode 100644 index 0000000..a95d03e --- /dev/null +++ b/charts/ntfy/Chart.yaml @@ -0,0 +1,6 @@ +apiVersion: v2 +name: ntfy +description: A Helm chart for ntfy +type: application +version: 0.1.0 +appVersion: "v2.7.0" diff --git a/charts/ntfy/README.md b/charts/ntfy/README.md new file mode 100644 index 0000000..2b0274f --- /dev/null +++ b/charts/ntfy/README.md @@ -0,0 +1,49 @@ +# ntfy + +![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: v2.7.0](https://img.shields.io/badge/AppVersion-v2.7.0-informational?style=flat-square) + +A Helm chart for ntfy + +## Values + +| Key | Type | Default | Description | +|-----|------|---------|-------------| +| affinity | object | `{}` | | +| autoscaling.enabled | bool | `false` | | +| autoscaling.maxReplicas | int | `100` | | +| autoscaling.minReplicas | int | `1` | | +| autoscaling.targetCPUUtilizationPercentage | int | `80` | | +| fullnameOverride | string | `""` | | +| image.pullPolicy | string | `"IfNotPresent"` | | +| image.repository | string | `"binwiederhier/ntfy"` | | +| image.tag | string | `""` | | +| imagePullSecrets | list | `[]` | | +| ingress.annotations | object | `{}` | | +| ingress.className | string | `""` | | +| ingress.enabled | bool | `false` | | +| ingress.hosts[0].host | string | `"chart-example.local"` | | +| ingress.hosts[0].paths[0].path | string | `"/"` | | +| ingress.hosts[0].paths[0].pathType | string | `"ImplementationSpecific"` | | +| ingress.tls | list | `[]` | | +| nameOverride | string | `""` | | +| nodeSelector | object | `{}` | | +| ntfy.cache.enabled | bool | `true` | | +| ntfy.cache.size | string | `"1Gi"` | | +| ntfy.config.attachment-cache-dir | string | `"/var/cache/ntfy/attachments"` | | +| ntfy.config.base-url | string | `"https://example.com"` | | +| ntfy.config.cache-file | string | `"/var/cache/ntfy/cache.db"` | | +| ntfy.extraEnv | list | `[]` | | +| podAnnotations | object | `{}` | | +| podSecurityContext | object | `{}` | | +| replicaCount | int | `1` | | +| resources | object | `{}` | | +| securityContext | object | `{}` | | +| service.port | int | `80` | | +| service.type | string | `"ClusterIP"` | | +| serviceAccount.annotations | object | `{}` | | +| serviceAccount.create | bool | `true` | | +| serviceAccount.name | string | `""` | | +| tolerations | list | `[]` | | + +---------------------------------------------- +Autogenerated from chart metadata using [helm-docs v1.11.0](https://github.com/norwoodj/helm-docs/releases/v1.11.0) diff --git a/charts/ntfy/templates/NOTES.txt b/charts/ntfy/templates/NOTES.txt new file mode 100644 index 0000000..33672f5 --- /dev/null +++ b/charts/ntfy/templates/NOTES.txt @@ -0,0 +1,22 @@ +1. Get the application URL by running these commands: +{{- if .Values.ingress.enabled }} +{{- range $host := .Values.ingress.hosts }} + {{- range .paths }} + http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }} + {{- 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 "ntfy.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 --namespace {{ .Release.Namespace }} svc -w {{ include "ntfy.fullname" . }}' + export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "ntfy.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}") + 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 "ntfy.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}") + export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}") + echo "Visit http://127.0.0.1:8080 to use your application" + kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT +{{- end }} diff --git a/charts/ntfy/templates/_helpers.tpl b/charts/ntfy/templates/_helpers.tpl new file mode 100644 index 0000000..6904d88 --- /dev/null +++ b/charts/ntfy/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "ntfy.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 "ntfy.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 "ntfy.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "ntfy.labels" -}} +helm.sh/chart: {{ include "ntfy.chart" . }} +{{ include "ntfy.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "ntfy.selectorLabels" -}} +app.kubernetes.io/name: {{ include "ntfy.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "ntfy.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "ntfy.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/charts/ntfy/templates/configmap.yaml b/charts/ntfy/templates/configmap.yaml new file mode 100644 index 0000000..59244f6 --- /dev/null +++ b/charts/ntfy/templates/configmap.yaml @@ -0,0 +1,7 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ include "ntfy.fullname" . }} +data: + server.yml: | +{{ toYaml .Values.ntfy.config | indent 4 }} diff --git a/charts/ntfy/templates/hpa.yaml b/charts/ntfy/templates/hpa.yaml new file mode 100644 index 0000000..994a13e --- /dev/null +++ b/charts/ntfy/templates/hpa.yaml @@ -0,0 +1,32 @@ +{{- if .Values.autoscaling.enabled }} +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: {{ include "ntfy.fullname" . }} + labels: + {{- include "ntfy.labels" . | nindent 4 }} +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ include "ntfy.fullname" . }} + minReplicas: {{ .Values.autoscaling.minReplicas }} + maxReplicas: {{ .Values.autoscaling.maxReplicas }} + metrics: + {{- if .Values.autoscaling.targetCPUUtilizationPercentage }} + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }} + {{- end }} + {{- if .Values.autoscaling.targetMemoryUtilizationPercentage }} + - type: Resource + resource: + name: memory + target: + type: Utilization + averageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }} + {{- end }} +{{- end }} diff --git a/charts/ntfy/templates/ingress.yaml b/charts/ntfy/templates/ingress.yaml new file mode 100644 index 0000000..8072595 --- /dev/null +++ b/charts/ntfy/templates/ingress.yaml @@ -0,0 +1,61 @@ +{{- if .Values.ingress.enabled -}} +{{- $fullName := include "ntfy.fullname" . -}} +{{- $svcPort := .Values.service.port -}} +{{- if and .Values.ingress.className (not (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion)) }} + {{- if not (hasKey .Values.ingress.annotations "kubernetes.io/ingress.class") }} + {{- $_ := set .Values.ingress.annotations "kubernetes.io/ingress.class" .Values.ingress.className}} + {{- end }} +{{- end }} +{{- if semverCompare ">=1.19-0" .Capabilities.KubeVersion.GitVersion -}} +apiVersion: networking.k8s.io/v1 +{{- else if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}} +apiVersion: networking.k8s.io/v1beta1 +{{- else -}} +apiVersion: extensions/v1beta1 +{{- end }} +kind: Ingress +metadata: + name: {{ $fullName }} + labels: + {{- include "ntfy.labels" . | nindent 4 }} + {{- with .Values.ingress.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + {{- if and .Values.ingress.className (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion) }} + ingressClassName: {{ .Values.ingress.className }} + {{- end }} + {{- if .Values.ingress.tls }} + tls: + {{- range .Values.ingress.tls }} + - hosts: + {{- range .hosts }} + - {{ . | quote }} + {{- end }} + secretName: {{ .secretName }} + {{- end }} + {{- end }} + rules: + {{- range .Values.ingress.hosts }} + - host: {{ .host | quote }} + http: + paths: + {{- range .paths }} + - path: {{ .path }} + {{- if and .pathType (semverCompare ">=1.18-0" $.Capabilities.KubeVersion.GitVersion) }} + pathType: {{ .pathType }} + {{- end }} + backend: + {{- if semverCompare ">=1.19-0" $.Capabilities.KubeVersion.GitVersion }} + service: + name: {{ $fullName }} + port: + number: {{ $svcPort }} + {{- else }} + serviceName: {{ $fullName }} + servicePort: {{ $svcPort }} + {{- end }} + {{- end }} + {{- end }} +{{- end }} diff --git a/charts/ntfy/templates/service.yaml b/charts/ntfy/templates/service.yaml new file mode 100644 index 0000000..2aa3dbe --- /dev/null +++ b/charts/ntfy/templates/service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "ntfy.fullname" . }} + labels: + {{- include "ntfy.labels" . | nindent 4 }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: http + protocol: TCP + name: http + selector: + {{- include "ntfy.selectorLabels" . | nindent 4 }} diff --git a/charts/ntfy/templates/serviceaccount.yaml b/charts/ntfy/templates/serviceaccount.yaml new file mode 100644 index 0000000..d0a8689 --- /dev/null +++ b/charts/ntfy/templates/serviceaccount.yaml @@ -0,0 +1,12 @@ +{{- if .Values.serviceAccount.create -}} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "ntfy.serviceAccountName" . }} + labels: + {{- include "ntfy.labels" . | nindent 4 }} + {{- with .Values.serviceAccount.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +{{- end }} diff --git a/charts/ntfy/templates/statefulset.yaml b/charts/ntfy/templates/statefulset.yaml new file mode 100644 index 0000000..f0ef567 --- /dev/null +++ b/charts/ntfy/templates/statefulset.yaml @@ -0,0 +1,88 @@ +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: {{ include "ntfy.fullname" . }} + labels: + {{- include "ntfy.labels" . | nindent 4 }} +spec: + {{- if not .Values.autoscaling.enabled }} + replicas: {{ .Values.replicaCount }} + {{- end }} + selector: + matchLabels: + {{- include "ntfy.selectorLabels" . | nindent 6 }} + template: + metadata: + {{- with .Values.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "ntfy.selectorLabels" . | nindent 8 }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + serviceAccountName: {{ include "ntfy.serviceAccountName" . }} + securityContext: + {{- toYaml .Values.podSecurityContext | nindent 8 }} + containers: + - name: {{ .Chart.Name }} + securityContext: + {{- toYaml .Values.securityContext | nindent 12 }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + args: ["serve"] + ports: + - name: http + containerPort: {{ .Values.service.port }} + protocol: TCP + livenessProbe: + httpGet: + path: / + port: http + readinessProbe: + httpGet: + path: / + port: http + resources: + {{- toYaml .Values.resources | nindent 12 }} + {{- if not (empty .Values.ntfy.extraEnv) }} + env: + {{- toYaml .Values.ntfy.extraEnv | nindent 12 }} + {{- end }} + volumeMounts: + - name: config + mountPath: "/etc/ntfy" + readOnly: true + {{- if .Values.ntfy.cache.enabled }} + - name: cache + mountPath: "/var/cache/ntfy" + {{- end }} + volumes: + - name: config + configMap: + name: {{ include "ntfy.fullname" . }} + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- if .Values.ntfy.cache.enabled }} + volumeClaimTemplates: + - metadata: + name: cache + spec: + accessModes: ["ReadWriteOnce"] + resources: + requests: + storage: {{ .Values.ntfy.cache.size }} + {{- end}} diff --git a/charts/ntfy/templates/tests/test-connection.yaml b/charts/ntfy/templates/tests/test-connection.yaml new file mode 100644 index 0000000..5970b5a --- /dev/null +++ b/charts/ntfy/templates/tests/test-connection.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Pod +metadata: + name: "{{ include "ntfy.fullname" . }}-test-connection" + labels: + {{- include "ntfy.labels" . | nindent 4 }} + annotations: + "helm.sh/hook": test +spec: + containers: + - name: wget + image: busybox + command: ['wget'] + args: ['{{ include "ntfy.fullname" . }}:{{ .Values.service.port }}'] + restartPolicy: Never diff --git a/charts/ntfy/values.yaml b/charts/ntfy/values.yaml new file mode 100644 index 0000000..8459772 --- /dev/null +++ b/charts/ntfy/values.yaml @@ -0,0 +1,80 @@ +# Default values for ntfy. + +replicaCount: 1 + +image: + repository: binwiederhier/ntfy + pullPolicy: IfNotPresent + # Overrides the image tag whose default is the chart appVersion. + tag: "" + +imagePullSecrets: [] +nameOverride: "" +fullnameOverride: "" + +serviceAccount: + # Specifies whether a service account should be created + create: 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: "" + +podAnnotations: {} + +podSecurityContext: {} + # fsGroup: 2000 + +securityContext: {} + # capabilities: + # drop: + # - ALL + # readOnlyRootFilesystem: true + # runAsNonRoot: true + # runAsUser: 1000 + +service: + type: ClusterIP + port: 80 + +ingress: + enabled: false + className: "" + annotations: {} + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + hosts: + - host: chart-example.local + paths: + - path: / + pathType: ImplementationSpecific + tls: [] + # - secretName: chart-example-tls + # hosts: + # - chart-example.local + +resources: {} + +autoscaling: + enabled: false + minReplicas: 1 + maxReplicas: 100 + targetCPUUtilizationPercentage: 80 + # targetMemoryUtilizationPercentage: 80 + +nodeSelector: {} + +tolerations: [] + +affinity: {} + +ntfy: + cache: + enabled: true + size: 1Gi + config: + base-url: https://example.com + cache-file: "/var/cache/ntfy/cache.db" + attachment-cache-dir: "/var/cache/ntfy/attachments" + extraEnv: []