[unifi-poller] convert to common library (#166)

This commit is contained in:
ᗪєνιη ᗷυнʟ 2020-11-15 15:53:07 -05:00 committed by GitHub
parent eb14f4a479
commit b80f372c82
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 108 additions and 329 deletions

2
charts/unifi-poller/.helmignore Executable file → Normal file
View File

@ -20,3 +20,5 @@
.idea/ .idea/
*.tmproj *.tmproj
.vscode/ .vscode/
# OWNERS file for Kubernetes
OWNERS

6
charts/unifi-poller/Chart.yaml Executable file → Normal file
View File

@ -2,7 +2,7 @@ apiVersion: v2
appVersion: 2.0.1 appVersion: 2.0.1
description: Collect ALL UniFi Controller, Site, Device & Client Data - Export to InfluxDB or Prometheus description: Collect ALL UniFi Controller, Site, Device & Client Data - Export to InfluxDB or Prometheus
name: unifi-poller name: unifi-poller
version: 2.0.1 version: 3.0.0
keywords: keywords:
- unifi - unifi
- unifi-poller - unifi-poller
@ -14,3 +14,7 @@ sources:
maintainers: maintainers:
- name: billimek - name: billimek
email: jeff@billimek.com email: jeff@billimek.com
dependencies:
- name: common
repository: https://k8s-at-home.com/charts/
version: ^1.5.0

59
charts/unifi-poller/README.md Executable file → Normal file
View File

@ -1,10 +1,6 @@
# unifi-poller # unifi-poller
This is an opinionated helm chart for [unifi-poller](https://github.com/unifi-poller/unifi-poller) This is a 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)
## TL;DR; ## TL;DR;
@ -18,32 +14,63 @@ $ helm install k8s-at-home/unifi-poller
To install the chart with the release name `my-release`: To install the chart with the release name `my-release`:
```console ```console
helm install --name unifi-poller k8s-at-home/unifi-poller helm install --name my-release k8s-at-home/unifi-poller
``` ```
## Uninstalling the Chart ## Uninstalling the Chart
To uninstall/delete the `unifi-poller` deployment: To uninstall/delete the `my-release` deployment:
```console ```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. The command removes all the Kubernetes components associated with the chart and deletes the release.
## Configuration ## Configuration
Read through the charts [values.yaml](https://github.com/k8s-at-home/charts/blob/master/charts/unifi-poller/values.yaml)
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. 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, Specify each parameter using the `--set key=value[,key=value]` argument to `helm install`. For example,
```console ```console
helm install --name unifi-poller \ helm install unifi-poller \
--set env.TZ="America/New_York" \
k8s-at-home/unifi-poller k8s-at-home/unifi-poller
``` ```
Alternatively, a YAML file that specifies the values for the above parameters can be provided while installing the
Alternatively, a YAML file that specifies the values for the above parameters can be provided while installing the chart. For example, chart. For example,
```console ```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.

View File

@ -0,0 +1,2 @@
ingress:
enabled: false

22
charts/unifi-poller/templates/NOTES.txt Executable file → Normal file
View File

@ -1,21 +1 @@
1. Get the application URL by running these commands: {{- include "common.notes.defaultNotes" . -}}
{{- 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 }}

View File

@ -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 -}}

View File

@ -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" . }}

10
charts/unifi-poller/templates/configmap.yaml Executable file → Normal file
View File

@ -1,9 +1,11 @@
apiVersion: v1 apiVersion: v1
kind: ConfigMap kind: ConfigMap
metadata: metadata:
name: {{ include "unifi-poller.fullname" . }} name: {{ template "common.names.fullname" . }}-settings
labels: labels:
{{ include "unifi-poller.labels" . | indent 4 }} {{- include "common.labels" . | nindent 4 }}
data: data:
up.yaml: {{ .Values.config | toYaml | quote }} unifi-poller.yaml: |
{{- with .Values.config }}
{{- toYaml . | nindent 4 }}
{{- end }}

View File

@ -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" . }}

View File

@ -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 }}

View File

@ -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 }}

View File

@ -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 -}}

View File

@ -2,24 +2,20 @@
apiVersion: monitoring.coreos.com/v1 apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor kind: ServiceMonitor
metadata: metadata:
name: {{ include "unifi-poller.fullname" . }} name: {{ template "common.names.fullname" . }}
labels: labels:
app.kubernetes.io/name: {{ include "unifi-poller.name" . }} {{- include "common.labels" . | nindent 4 }}
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 }} {{- with .Values.prometheus.serviceMonitor.additionalLabels }}
{{- toYaml . | nindent 4 }} {{- toYaml . | nindent 4 }}
{{- end }} {{- end }}
spec: spec:
selector: selector:
matchLabels: matchLabels:
app.kubernetes.io/name: {{ include "unifi-poller.name" . }} {{- include "common.labels.selectorLabels" . | nindent 6 }}
app.kubernetes.io/instance: {{ .Release.Name }}
endpoints: endpoints:
- port: http - port: http
{{- if .Values.prometheus.serviceMonitor.interval }} {{- with .Values.prometheus.serviceMonitor.interval }}
interval: {{ .Values.prometheus.serviceMonitor.interval }} interval: {{ . }}
{{- end }} {{- end }}
path: /metrics path: /metrics
{{- end }} {{- end }}

View File

@ -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

69
charts/unifi-poller/values.yaml Executable file → Normal file
View File

@ -1,81 +1,26 @@
# Default values for unifi-poller. # Default values for unifi-poller.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.
replicaCount: 1
image: image:
repository: golift/unifi-poller repository: golift/unifi-poller
tag: 2.0.1
pullPolicy: IfNotPresent pullPolicy: IfNotPresent
tag: 2.0.1
imagePullSecrets: [] strategy:
nameOverride: "" type: Recreate
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
service: service:
type: ClusterIP port:
port: 9130 port: 9130
annotations: {}
ingress: # enable a prometheus-operator servicemonitor
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
prometheus: prometheus:
serviceMonitor: serviceMonitor:
enabled: false enabled: false
interval: 1m interval: 1m
additionalLabels: {} additionalLabels: {}
# unifi-poller configuration settings
# https://github.com/unifi-poller/unifi-poller/wiki/Configuration
config: config:
poller: poller:
# config.poller.debug -- Turns on line numbers, microsecond logging, and a per-device log. # config.poller.debug -- Turns on line numbers, microsecond logging, and a per-device log.