From b80f372c822aba482b8472fe2cf5ca402b0cb7c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=97=AA=D1=94=CE=BD=CE=B9=CE=B7=20=E1=97=B7=CF=85=D0=BD?= =?UTF-8?q?=CA=9F?= Date: Sun, 15 Nov 2020 15:53:07 -0500 Subject: [PATCH] [unifi-poller] convert to common library (#166) --- charts/unifi-poller/.helmignore | 2 + charts/unifi-poller/Chart.yaml | 6 +- charts/unifi-poller/OWNERS | 2 +- charts/unifi-poller/README.md | 59 ++++++++++----- charts/unifi-poller/ci/ct-values.yaml | 2 + charts/unifi-poller/templates/NOTES.txt | 22 +----- charts/unifi-poller/templates/_helpers.tpl | 56 --------------- charts/unifi-poller/templates/common.yaml | 31 ++++++++ charts/unifi-poller/templates/configmap.yaml | 10 +-- charts/unifi-poller/templates/deployment.yaml | 70 ------------------ charts/unifi-poller/templates/ingress.yaml | 38 ---------- charts/unifi-poller/templates/service.yaml | 20 ------ .../templates/serviceaccount.yaml | 8 --- .../templates/servicemonitor.yaml | 22 +++--- .../templates/tests/test-connection.yaml | 18 ----- charts/unifi-poller/values.yaml | 71 +++---------------- 16 files changed, 108 insertions(+), 329 deletions(-) mode change 100755 => 100644 charts/unifi-poller/.helmignore mode change 100755 => 100644 charts/unifi-poller/Chart.yaml mode change 100755 => 100644 charts/unifi-poller/README.md create mode 100644 charts/unifi-poller/ci/ct-values.yaml mode change 100755 => 100644 charts/unifi-poller/templates/NOTES.txt delete mode 100755 charts/unifi-poller/templates/_helpers.tpl create mode 100644 charts/unifi-poller/templates/common.yaml mode change 100755 => 100644 charts/unifi-poller/templates/configmap.yaml delete mode 100755 charts/unifi-poller/templates/deployment.yaml delete mode 100755 charts/unifi-poller/templates/ingress.yaml delete mode 100755 charts/unifi-poller/templates/service.yaml delete mode 100755 charts/unifi-poller/templates/serviceaccount.yaml delete mode 100755 charts/unifi-poller/templates/tests/test-connection.yaml mode change 100755 => 100644 charts/unifi-poller/values.yaml diff --git a/charts/unifi-poller/.helmignore b/charts/unifi-poller/.helmignore old mode 100755 new mode 100644 index 50af0317..e559de0a --- a/charts/unifi-poller/.helmignore +++ b/charts/unifi-poller/.helmignore @@ -20,3 +20,5 @@ .idea/ *.tmproj .vscode/ +# OWNERS file for Kubernetes +OWNERS diff --git a/charts/unifi-poller/Chart.yaml b/charts/unifi-poller/Chart.yaml old mode 100755 new mode 100644 index be27d5f2..843d5387 --- a/charts/unifi-poller/Chart.yaml +++ b/charts/unifi-poller/Chart.yaml @@ -2,7 +2,7 @@ apiVersion: v2 appVersion: 2.0.1 description: Collect ALL UniFi Controller, Site, Device & Client Data - Export to InfluxDB or Prometheus name: unifi-poller -version: 2.0.1 +version: 3.0.0 keywords: - unifi - unifi-poller @@ -14,3 +14,7 @@ sources: maintainers: - name: billimek email: jeff@billimek.com +dependencies: + - name: common + repository: https://k8s-at-home.com/charts/ + version: ^1.5.0 diff --git a/charts/unifi-poller/OWNERS b/charts/unifi-poller/OWNERS index 51f88652..b90909f4 100644 --- a/charts/unifi-poller/OWNERS +++ b/charts/unifi-poller/OWNERS @@ -1,4 +1,4 @@ approvers: - billimek reviewers: -- billimek \ No newline at end of file +- billimek diff --git a/charts/unifi-poller/README.md b/charts/unifi-poller/README.md old mode 100755 new mode 100644 index e360d6c6..d1d8313b --- a/charts/unifi-poller/README.md +++ b/charts/unifi-poller/README.md @@ -1,10 +1,6 @@ # unifi-poller -This is an opinionated helm chart for [unifi-poller](https://github.com/unifi-poller/unifi-poller) - -Collect ALL UniFi Controller, Site, Device & Client Data - Export to InfluxDB or Prometheus - -The default values and container images used in this chart will allow for running in a multi-arch cluster (amd64, arm, arm64) +This is a helm chart for [unifi-poller](https://github.com/unifi-poller/unifi-poller). ## TL;DR; @@ -18,32 +14,63 @@ $ helm install k8s-at-home/unifi-poller To install the chart with the release name `my-release`: ```console -helm install --name unifi-poller k8s-at-home/unifi-poller +helm install --name my-release k8s-at-home/unifi-poller ``` ## Uninstalling the Chart -To uninstall/delete the `unifi-poller` deployment: +To uninstall/delete the `my-release` deployment: ```console -helm delete unifi-poller --purge +helm delete my-release --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/k8s-at-home/charts/blob/master/charts/unifi-poller/values.yaml) file. It has several commented out suggested values. +Read through the charts [values.yaml](https://github.com/k8s-at-home/charts/blob/master/charts/unifi-poller/values.yaml) +file. It has several commented out suggested values. +Additionally you can take a look at the common library [values.yaml](https://github.com/k8s-at-home/charts/blob/master/charts/common/values.yaml) for more (advanced) configuration options. Specify each parameter using the `--set key=value[,key=value]` argument to `helm install`. For example, - ```console -helm install --name unifi-poller \ +helm install unifi-poller \ + --set env.TZ="America/New_York" \ k8s-at-home/unifi-poller ``` - -Alternatively, a YAML file that specifies the values for the above parameters can be provided while installing the chart. For example, - +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 unifi-poller -f values.yaml stable/unifi-poller +helm install unifi-poller k8s-at-home/unifi-poller --values values.yaml ``` + +```yaml +image: + tag: ... +``` + +--- +**NOTE** + +If you get +```console +Error: rendered manifests contain a resource that already exists. Unable to continue with install: existing resource conflict: ...` +``` +it may be because you uninstalled the chart with `skipuninstall` enabled, you need to manually delete the pvc or use `existingClaim`. + +--- + +## Upgrading an existing Release to a new major version + +A major chart version change (like 4.0.1 -> 5.0.0) indicates that there is an incompatible breaking change potentially needing manual actions. + +### Upgrading from 2.x.x to 3.x.x + +Due to migrating to a centralized common library some values in `values.yaml` have changed. + +Examples: + +* `service.port` has been moved to `service.port.port`. +* `persistence.type` has been moved to `controllerType`. + +Refer to the library values.yaml for more configuration options. diff --git a/charts/unifi-poller/ci/ct-values.yaml b/charts/unifi-poller/ci/ct-values.yaml new file mode 100644 index 00000000..9c60e566 --- /dev/null +++ b/charts/unifi-poller/ci/ct-values.yaml @@ -0,0 +1,2 @@ +ingress: + enabled: false diff --git a/charts/unifi-poller/templates/NOTES.txt b/charts/unifi-poller/templates/NOTES.txt old mode 100755 new mode 100644 index 1a0a5a5a..90f7b653 --- a/charts/unifi-poller/templates/NOTES.txt +++ b/charts/unifi-poller/templates/NOTES.txt @@ -1,21 +1 @@ -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 }}{{ . }} - {{- 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 "unifi-poller.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 "unifi-poller.fullname" . }}' - export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "unifi-poller.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 "unifi-poller.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}") - echo "Visit http://127.0.0.1:9130 to use your application" - kubectl port-forward $POD_NAME 9130:80 -{{- end }} +{{- include "common.notes.defaultNotes" . -}} diff --git a/charts/unifi-poller/templates/_helpers.tpl b/charts/unifi-poller/templates/_helpers.tpl deleted file mode 100755 index 3f052d20..00000000 --- a/charts/unifi-poller/templates/_helpers.tpl +++ /dev/null @@ -1,56 +0,0 @@ -{{/* vim: set filetype=mustache: */}} -{{/* -Expand the name of the chart. -*/}} -{{- define "unifi-poller.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 "unifi-poller.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 "unifi-poller.chart" -}} -{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Common labels -*/}} -{{- define "unifi-poller.labels" -}} -app.kubernetes.io/name: {{ include "unifi-poller.name" . }} -helm.sh/chart: {{ include "unifi-poller.chart" . }} -app.kubernetes.io/instance: {{ .Release.Name }} -{{- if .Chart.AppVersion }} -app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} -{{- end }} -app.kubernetes.io/managed-by: {{ .Release.Service }} -{{- end -}} - -{{/* -Create the name of the service account to use -*/}} -{{- define "unifi-poller.serviceAccountName" -}} -{{- if .Values.serviceAccount.create -}} - {{ default (include "unifi-poller.fullname" .) .Values.serviceAccount.name }} -{{- else -}} - {{ default "default" .Values.serviceAccount.name }} -{{- end -}} -{{- end -}} diff --git a/charts/unifi-poller/templates/common.yaml b/charts/unifi-poller/templates/common.yaml new file mode 100644 index 00000000..e89dd659 --- /dev/null +++ b/charts/unifi-poller/templates/common.yaml @@ -0,0 +1,31 @@ +{{/* Make sure all variables are set properly */}} +{{- include "common.values.setup" . }} + +{{/* Append the configMap to the additionalVolumes */}} +{{- define "unifi-poller.configmap.volume" -}} +name: unifi-poller-settings +configMap: + name: {{ template "common.names.fullname" . }}-settings +{{- end -}} + +{{- $volume := include "unifi-poller.configmap.volume" . | fromYaml -}} +{{- if $volume -}} + {{- $additionalVolumes := append .Values.additionalVolumes $volume }} + {{- $_ := set .Values "additionalVolumes" (deepCopy $additionalVolumes) -}} +{{- end -}} + +{{/* Append the configMap volume to the additionalVolumeMounts */}} +{{- define "unifi-poller.configmap.volumeMount" -}} +name: unifi-poller-settings +mountPath: /config/unifi-poller.yaml +subPath: unifi-poller.yaml +{{- end -}} + +{{- $volumeMount := include "unifi-poller.configmap.volumeMount" . | fromYaml -}} +{{- if $volumeMount -}} + {{- $additionalVolumeMounts := append .Values.additionalVolumeMounts $volumeMount }} + {{- $_ := set .Values "additionalVolumeMounts" (deepCopy $additionalVolumeMounts) -}} +{{- end -}} + +{{/* Render the templates */}} +{{ include "common.all" . }} diff --git a/charts/unifi-poller/templates/configmap.yaml b/charts/unifi-poller/templates/configmap.yaml old mode 100755 new mode 100644 index 6c672a3a..2d02e6a4 --- a/charts/unifi-poller/templates/configmap.yaml +++ b/charts/unifi-poller/templates/configmap.yaml @@ -1,9 +1,11 @@ apiVersion: v1 kind: ConfigMap metadata: - name: {{ include "unifi-poller.fullname" . }} + name: {{ template "common.names.fullname" . }}-settings labels: -{{ include "unifi-poller.labels" . | indent 4 }} + {{- include "common.labels" . | nindent 4 }} data: - up.yaml: {{ .Values.config | toYaml | quote }} - + unifi-poller.yaml: | + {{- with .Values.config }} + {{- toYaml . | nindent 4 }} + {{- end }} diff --git a/charts/unifi-poller/templates/deployment.yaml b/charts/unifi-poller/templates/deployment.yaml deleted file mode 100755 index c1e14220..00000000 --- a/charts/unifi-poller/templates/deployment.yaml +++ /dev/null @@ -1,70 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: {{ include "unifi-poller.fullname" . }} - labels: -{{ include "unifi-poller.labels" . | indent 4 }} -spec: - replicas: {{ .Values.replicaCount }} - revisionHistoryLimit: 3 - selector: - matchLabels: - app.kubernetes.io/name: {{ include "unifi-poller.name" . }} - app.kubernetes.io/instance: {{ .Release.Name }} - template: - metadata: - annotations: - checksum/configmap: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }} - labels: - app.kubernetes.io/name: {{ include "unifi-poller.name" . }} - app.kubernetes.io/instance: {{ .Release.Name }} - spec: - {{- with .Values.imagePullSecrets }} - imagePullSecrets: - {{- toYaml . | nindent 8 }} - {{- end }} - serviceAccountName: {{ template "unifi-poller.serviceAccountName" . }} - securityContext: - {{- toYaml .Values.podSecurityContext | nindent 8 }} - containers: - - name: {{ .Chart.Name }} - securityContext: - {{- toYaml .Values.securityContext | nindent 12 }} - image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" - imagePullPolicy: {{ .Values.image.pullPolicy }} - args: - - "-c" - - "/etc/unifi-poller/up.yaml" - ports: - - name: http - containerPort: 9130 - protocol: TCP - livenessProbe: - httpGet: - path: / - port: http - readinessProbe: - httpGet: - path: / - port: http - volumeMounts: - - name: config - mountPath: /etc/unifi-poller - 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 }} - volumes: - - name: config - configMap: - name: {{ template "unifi-poller.fullname" . }} diff --git a/charts/unifi-poller/templates/ingress.yaml b/charts/unifi-poller/templates/ingress.yaml deleted file mode 100755 index 3452009a..00000000 --- a/charts/unifi-poller/templates/ingress.yaml +++ /dev/null @@ -1,38 +0,0 @@ -{{- if .Values.ingress.enabled -}} -{{- $fullName := include "unifi-poller.fullname" . -}} -{{- $ingressPath := .Values.ingress.path -}} -apiVersion: extensions/v1beta1 -kind: Ingress -metadata: - name: {{ $fullName }} - labels: - app.kubernetes.io/name: {{ include "unifi-poller.name" . }} - helm.sh/chart: {{ include "unifi-poller.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/charts/unifi-poller/templates/service.yaml b/charts/unifi-poller/templates/service.yaml deleted file mode 100755 index 22b58d6a..00000000 --- a/charts/unifi-poller/templates/service.yaml +++ /dev/null @@ -1,20 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - name: {{ include "unifi-poller.fullname" . }} - labels: -{{ include "unifi-poller.labels" . | indent 4 }} -{{- if .Values.service.annotations }} - annotations: -{{ toYaml .Values.service.annotations | indent 4 }} -{{- end }} -spec: - type: {{ .Values.service.type }} - ports: - - port: {{ .Values.service.port }} - targetPort: http - protocol: TCP - name: http - selector: - app.kubernetes.io/name: {{ include "unifi-poller.name" . }} - app.kubernetes.io/instance: {{ .Release.Name }} diff --git a/charts/unifi-poller/templates/serviceaccount.yaml b/charts/unifi-poller/templates/serviceaccount.yaml deleted file mode 100755 index 76eac3a1..00000000 --- a/charts/unifi-poller/templates/serviceaccount.yaml +++ /dev/null @@ -1,8 +0,0 @@ -{{- if .Values.serviceAccount.create -}} -apiVersion: v1 -kind: ServiceAccount -metadata: - name: {{ template "unifi-poller.serviceAccountName" . }} - labels: -{{ include "unifi-poller.labels" . | indent 4 }} -{{- end -}} diff --git a/charts/unifi-poller/templates/servicemonitor.yaml b/charts/unifi-poller/templates/servicemonitor.yaml index 64d5a416..5fdcf649 100644 --- a/charts/unifi-poller/templates/servicemonitor.yaml +++ b/charts/unifi-poller/templates/servicemonitor.yaml @@ -2,24 +2,20 @@ apiVersion: monitoring.coreos.com/v1 kind: ServiceMonitor metadata: - name: {{ include "unifi-poller.fullname" . }} + name: {{ template "common.names.fullname" . }} labels: - app.kubernetes.io/name: {{ include "unifi-poller.name" . }} - app.kubernetes.io/instance: {{ .Release.Name }} - app.kubernetes.io/managed-by: {{ .Release.Service }} - helm.sh/chart: {{ include "unifi-poller.chart" . }} - {{- with .Values.prometheus.serviceMonitor.additionalLabels }} + {{- include "common.labels" . | nindent 4 }} + {{- with .Values.prometheus.serviceMonitor.additionalLabels }} {{- toYaml . | nindent 4 }} - {{- end }} + {{- end }} spec: selector: matchLabels: - app.kubernetes.io/name: {{ include "unifi-poller.name" . }} - app.kubernetes.io/instance: {{ .Release.Name }} + {{- include "common.labels.selectorLabels" . | nindent 6 }} endpoints: - port: http -{{- if .Values.prometheus.serviceMonitor.interval }} - interval: {{ .Values.prometheus.serviceMonitor.interval }} -{{- end }} + {{- with .Values.prometheus.serviceMonitor.interval }} + interval: {{ . }} + {{- end }} path: /metrics -{{- end }} \ No newline at end of file +{{- end }} diff --git a/charts/unifi-poller/templates/tests/test-connection.yaml b/charts/unifi-poller/templates/tests/test-connection.yaml deleted file mode 100755 index 7f76f9bb..00000000 --- a/charts/unifi-poller/templates/tests/test-connection.yaml +++ /dev/null @@ -1,18 +0,0 @@ -apiVersion: v1 -kind: Pod -metadata: - name: "{{ include "unifi-poller.fullname" . }}-test-connection" - labels: - app.kubernetes.io/name: {{ include "unifi-poller.name" . }} - helm.sh/chart: {{ include "unifi-poller.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 "unifi-poller.fullname" . }}:{{ .Values.service.port }}'] - restartPolicy: Never diff --git a/charts/unifi-poller/values.yaml b/charts/unifi-poller/values.yaml old mode 100755 new mode 100644 index a4852aca..d91fd5a5 --- a/charts/unifi-poller/values.yaml +++ b/charts/unifi-poller/values.yaml @@ -1,81 +1,26 @@ # Default values for unifi-poller. -# This is a YAML-formatted file. -# Declare variables to be passed into your templates. - -replicaCount: 1 image: repository: golift/unifi-poller - tag: 2.0.1 pullPolicy: IfNotPresent + tag: 2.0.1 -imagePullSecrets: [] -nameOverride: "" -fullnameOverride: "" - -serviceAccount: - # Specifies whether a service account should be created - create: true - # The name of the service account to use. - # If not set and create is true, a name is generated using the fullname template - name: - -podSecurityContext: {} - # fsGroup: 2000 - -securityContext: {} - # capabilities: - # drop: - # - ALL - # readOnlyRootFilesystem: true - # runAsNonRoot: true - # runAsUser: 1000 +strategy: + type: Recreate service: - type: ClusterIP - port: 9130 - annotations: {} + port: + port: 9130 -ingress: - enabled: false - annotations: {} - # kubernetes.io/ingress.class: nginx - # kubernetes.io/tls-acme: "true" - hosts: - - host: chart-example.local - paths: [] - - 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: {} - -# if using prometheus in the options below -# wire up a servicemonitor for prometheus-operator +# enable a prometheus-operator servicemonitor prometheus: serviceMonitor: enabled: false interval: 1m additionalLabels: {} +# unifi-poller configuration settings +# https://github.com/unifi-poller/unifi-poller/wiki/Configuration config: poller: # config.poller.debug -- Turns on line numbers, microsecond logging, and a per-device log.