From 91c8466022ae12c5158eff82ee0eb6a0371f833e 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: Thu, 25 Mar 2021 20:22:00 -0400 Subject: [PATCH] [prometheus-nut-exporter] migrate to common (#721) * prometheus-nut-exporter common * remove useless with --- .../prometheus-nut-exporter/.helmignore | 5 +- .../stable/prometheus-nut-exporter/Chart.yaml | 12 ++- .../stable/prometheus-nut-exporter/README.md | 51 +++++------ .../README_CHANGELOG.md.gotmpl | 14 +++ .../README_CONFIG.md.gotmpl | 4 +- .../templates/NOTES.txt | 16 +--- .../templates/_helpers.tpl | 62 ------------- .../templates/common.yaml | 1 + .../templates/deployment.yaml | 72 --------------- .../templates/service.yaml | 15 ---- .../templates/serviceaccount.yaml | 12 --- .../templates/servicemonitor.yaml | 32 ++++--- .../prometheus-nut-exporter/values.yaml | 88 +++++-------------- 13 files changed, 91 insertions(+), 293 deletions(-) delete mode 100644 charts/stable/prometheus-nut-exporter/templates/_helpers.tpl create mode 100644 charts/stable/prometheus-nut-exporter/templates/common.yaml delete mode 100644 charts/stable/prometheus-nut-exporter/templates/deployment.yaml delete mode 100644 charts/stable/prometheus-nut-exporter/templates/service.yaml delete mode 100644 charts/stable/prometheus-nut-exporter/templates/serviceaccount.yaml diff --git a/charts/stable/prometheus-nut-exporter/.helmignore b/charts/stable/prometheus-nut-exporter/.helmignore index 0e8a0eb3..4379e2b3 100644 --- a/charts/stable/prometheus-nut-exporter/.helmignore +++ b/charts/stable/prometheus-nut-exporter/.helmignore @@ -14,10 +14,13 @@ *.swp *.bak *.tmp -*.orig *~ # Various IDEs .project .idea/ *.tmproj .vscode/ +# OWNERS file for Kubernetes +OWNERS +# helm-docs templates +*.gotmpl diff --git a/charts/stable/prometheus-nut-exporter/Chart.yaml b/charts/stable/prometheus-nut-exporter/Chart.yaml index 5ac5fb7a..fa785221 100644 --- a/charts/stable/prometheus-nut-exporter/Chart.yaml +++ b/charts/stable/prometheus-nut-exporter/Chart.yaml @@ -1,9 +1,9 @@ apiVersion: v2 -name: prometheus-nut-exporter -description: Prometheus NUT Exporter a service monitor to send NUT server metrics to a Prometheus instance. -type: application -version: 1.0.4 appVersion: 1.0.1 +description: Prometheus NUT Exporter a service monitor to send NUT server metrics to a Prometheus instance. +name: prometheus-nut-exporter +version: 2.0.0 +kubeVersion: ">=1.16.0-0" keywords: - nut - prometheus @@ -14,3 +14,7 @@ sources: maintainers: - name: billimek email: jeff@billimek.com +dependencies: +- name: common + repository: https://library-charts.k8s-at-home.com + version: 2.0.1 diff --git a/charts/stable/prometheus-nut-exporter/README.md b/charts/stable/prometheus-nut-exporter/README.md index b94f9a06..b5413dd0 100644 --- a/charts/stable/prometheus-nut-exporter/README.md +++ b/charts/stable/prometheus-nut-exporter/README.md @@ -1,6 +1,6 @@ # prometheus-nut-exporter -![Version: 1.0.4](https://img.shields.io/badge/Version-1.0.4-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 1.0.1](https://img.shields.io/badge/AppVersion-1.0.1-informational?style=flat-square) +![Version: 2.0.0](https://img.shields.io/badge/Version-2.0.0-informational?style=flat-square) ![AppVersion: 1.0.1](https://img.shields.io/badge/AppVersion-1.0.1-informational?style=flat-square) Prometheus NUT Exporter a service monitor to send NUT server metrics to a Prometheus instance. @@ -12,10 +12,13 @@ Prometheus NUT Exporter a service monitor to send NUT server metrics to a Promet ## Requirements +Kubernetes: `>=1.16.0-0` + ## Dependencies | Repository | Name | Version | |------------|------|---------| +| https://library-charts.k8s-at-home.com | common | 2.0.1 | ## TL;DR @@ -64,9 +67,7 @@ helm install prometheus-nut-exporter k8s-at-home/prometheus-nut-exporter -f valu ## Custom configuration -### Metrics - -You can find the exported metrics here: [metrics](https://github.com/HON95/prometheus-nut-exporter/blob/master/metrics.md). +N/A ## Values @@ -74,34 +75,14 @@ You can find the exported metrics here: [metrics](https://github.com/HON95/prome | Key | Type | Default | Description | |-----|------|---------|-------------| -| affinity | object | `{}` | | | env | object | `{}` | | -| fullnameOverride | string | `""` | | | image.pullPolicy | string | `"IfNotPresent"` | | | image.repository | string | `"hon95/prometheus-nut-exporter"` | | | image.tag | string | `"1.0.1"` | | -| imagePullSecrets | list | `[]` | | -| nameOverride | string | `""` | | -| nodeSelector | object | `{}` | | -| podAnnotations | object | `{}` | | -| podSecurityContext | object | `{}` | | -| probes.liveness.failureThreshold | int | `5` | | -| probes.liveness.initialDelaySeconds | int | `30` | | -| probes.liveness.timeoutSeconds | int | `10` | | -| probes.readiness.failureThreshold | int | `5` | | -| probes.readiness.initialDelaySeconds | int | `30` | | -| probes.readiness.timeoutSeconds | int | `10` | | -| replicaCount | int | `1` | | -| resources | object | `{}` | | -| securityContext | object | `{}` | | -| service.port | int | `9995` | | -| service.type | string | `"ClusterIP"` | | -| serviceAccount.annotations | object | `{}` | | -| serviceAccount.create | bool | `true` | | -| serviceAccount.name | string | `""` | | -| serviceMonitor.enabled | bool | `false` | | -| serviceMonitor.targets | list | `[]` | | -| tolerations | list | `[]` | | +| prometheus.serviceMonitor.enabled | bool | `false` | | +| prometheus.serviceMonitor.targets | list | `[]` | | +| service.port.port | int | `9995` | | +| strategy.type | string | `"Recreate"` | | ## Changelog @@ -109,6 +90,20 @@ All notable changes to this application Helm chart will be documented in this fi The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +### [2.0.0] + +#### Added + +- N/A + +#### Changed + +- **BREAKING** Migrate prometheus-nut-exporter to the common library, Helm configuration values have changed. + +#### Removed + +- N/A + ### [1.0.2] #### Added diff --git a/charts/stable/prometheus-nut-exporter/README_CHANGELOG.md.gotmpl b/charts/stable/prometheus-nut-exporter/README_CHANGELOG.md.gotmpl index e4da5f77..e3b9642e 100644 --- a/charts/stable/prometheus-nut-exporter/README_CHANGELOG.md.gotmpl +++ b/charts/stable/prometheus-nut-exporter/README_CHANGELOG.md.gotmpl @@ -9,6 +9,20 @@ All notable changes to this application Helm chart will be documented in this fi The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +### [2.0.0] + +#### Added + +- N/A + +#### Changed + +- **BREAKING** Migrate prometheus-nut-exporter to the common library, Helm configuration values have changed. + +#### Removed + +- N/A + ### [1.0.2] #### Added diff --git a/charts/stable/prometheus-nut-exporter/README_CONFIG.md.gotmpl b/charts/stable/prometheus-nut-exporter/README_CONFIG.md.gotmpl index 18f7c8cd..e93d80bf 100644 --- a/charts/stable/prometheus-nut-exporter/README_CONFIG.md.gotmpl +++ b/charts/stable/prometheus-nut-exporter/README_CONFIG.md.gotmpl @@ -5,7 +5,5 @@ {{- define "custom.custom.configuration" -}} {{ template "custom.custom.configuration.header" . }} -### Metrics - -You can find the exported metrics here: [metrics](https://github.com/HON95/prometheus-nut-exporter/blob/master/metrics.md). +N/A {{- end -}} diff --git a/charts/stable/prometheus-nut-exporter/templates/NOTES.txt b/charts/stable/prometheus-nut-exporter/templates/NOTES.txt index 0bf4fc52..90f7b653 100644 --- a/charts/stable/prometheus-nut-exporter/templates/NOTES.txt +++ b/charts/stable/prometheus-nut-exporter/templates/NOTES.txt @@ -1,15 +1 @@ -1. Get the application URL by running these commands: -{{- if contains "NodePort" .Values.service.type }} - export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "prometheus-nut-exporter.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 "prometheus-nut-exporter.fullname" . }}' - export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "prometheus-nut-exporter.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 "prometheus-nut-exporter.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}") - echo "Visit http://127.0.0.1:8080 to use your application" - kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:{{ .Values.service.port }} -{{- end }} +{{- include "common.notes.defaultNotes" . -}} diff --git a/charts/stable/prometheus-nut-exporter/templates/_helpers.tpl b/charts/stable/prometheus-nut-exporter/templates/_helpers.tpl deleted file mode 100644 index bde39613..00000000 --- a/charts/stable/prometheus-nut-exporter/templates/_helpers.tpl +++ /dev/null @@ -1,62 +0,0 @@ -{{/* -Expand the name of the chart. -*/}} -{{- define "prometheus-nut-exporter.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 "prometheus-nut-exporter.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 "prometheus-nut-exporter.chart" -}} -{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} -{{- end }} - -{{/* -Common labels -*/}} -{{- define "prometheus-nut-exporter.labels" -}} -helm.sh/chart: {{ include "prometheus-nut-exporter.chart" . }} -{{ include "prometheus-nut-exporter.selectorLabels" . }} -{{- if .Chart.AppVersion }} -app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} -{{- end }} -app.kubernetes.io/managed-by: {{ .Release.Service }} -{{- end }} - -{{/* -Selector labels -*/}} -{{- define "prometheus-nut-exporter.selectorLabels" -}} -app.kubernetes.io/name: {{ include "prometheus-nut-exporter.name" . }} -app.kubernetes.io/instance: {{ .Release.Name }} -{{- end }} - -{{/* -Create the name of the service account to use -*/}} -{{- define "prometheus-nut-exporter.serviceAccountName" -}} -{{- if .Values.serviceAccount.create }} -{{- default (include "prometheus-nut-exporter.fullname" .) .Values.serviceAccount.name }} -{{- else }} -{{- default "default" .Values.serviceAccount.name }} -{{- end }} -{{- end }} diff --git a/charts/stable/prometheus-nut-exporter/templates/common.yaml b/charts/stable/prometheus-nut-exporter/templates/common.yaml new file mode 100644 index 00000000..a6613c2c --- /dev/null +++ b/charts/stable/prometheus-nut-exporter/templates/common.yaml @@ -0,0 +1 @@ +{{ include "common.all" . }} diff --git a/charts/stable/prometheus-nut-exporter/templates/deployment.yaml b/charts/stable/prometheus-nut-exporter/templates/deployment.yaml deleted file mode 100644 index eae9696e..00000000 --- a/charts/stable/prometheus-nut-exporter/templates/deployment.yaml +++ /dev/null @@ -1,72 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: {{ include "prometheus-nut-exporter.fullname" . }} - labels: - {{- include "prometheus-nut-exporter.labels" . | nindent 4 }} -spec: - replicas: {{ .Values.replicaCount }} - selector: - matchLabels: - {{- include "prometheus-nut-exporter.selectorLabels" . | nindent 6 }} - template: - metadata: - {{- with .Values.podAnnotations }} - annotations: - {{- toYaml . | nindent 8 }} - {{- end }} - labels: - {{- include "prometheus-nut-exporter.selectorLabels" . | nindent 8 }} - spec: - {{- with .Values.imagePullSecrets }} - imagePullSecrets: - {{- toYaml . | nindent 8 }} - {{- end }} - serviceAccountName: {{ include "prometheus-nut-exporter.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 }} - ports: - - name: http - containerPort: {{ .Values.service.port }} - protocol: TCP - {{- if .Values.env }} - env: - {{- range $key, $value := .Values.env }} - - name: {{ $key | quote }} - value: {{ $value | quote }} - {{- end }} - {{- end }} - livenessProbe: - httpGet: - path: / - port: http - initialDelaySeconds: {{ .Values.probes.liveness.initialDelaySeconds }} - failureThreshold: {{ .Values.probes.liveness.failureThreshold }} - timeoutSeconds: {{ .Values.probes.liveness.timeoutSeconds }} - readinessProbe: - httpGet: - path: / - port: http - initialDelaySeconds: {{ .Values.probes.readiness.initialDelaySeconds }} - failureThreshold: {{ .Values.probes.readiness.failureThreshold }} - timeoutSeconds: {{ .Values.probes.readiness.timeoutSeconds }} - 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 }} diff --git a/charts/stable/prometheus-nut-exporter/templates/service.yaml b/charts/stable/prometheus-nut-exporter/templates/service.yaml deleted file mode 100644 index 4a7fa666..00000000 --- a/charts/stable/prometheus-nut-exporter/templates/service.yaml +++ /dev/null @@ -1,15 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - name: {{ include "prometheus-nut-exporter.fullname" . }} - labels: - {{- include "prometheus-nut-exporter.labels" . | nindent 4 }} -spec: - type: {{ .Values.service.type }} - ports: - - port: {{ .Values.service.port }} - targetPort: http - protocol: TCP - name: http - selector: - {{- include "prometheus-nut-exporter.selectorLabels" . | nindent 4 }} diff --git a/charts/stable/prometheus-nut-exporter/templates/serviceaccount.yaml b/charts/stable/prometheus-nut-exporter/templates/serviceaccount.yaml deleted file mode 100644 index 61b76d13..00000000 --- a/charts/stable/prometheus-nut-exporter/templates/serviceaccount.yaml +++ /dev/null @@ -1,12 +0,0 @@ -{{- if .Values.serviceAccount.create -}} -apiVersion: v1 -kind: ServiceAccount -metadata: - name: {{ include "prometheus-nut-exporter.serviceAccountName" . }} - labels: - {{- include "prometheus-nut-exporter.labels" . | nindent 4 }} - {{- with .Values.serviceAccount.annotations }} - annotations: - {{- toYaml . | nindent 4 }} - {{- end }} -{{- end }} diff --git a/charts/stable/prometheus-nut-exporter/templates/servicemonitor.yaml b/charts/stable/prometheus-nut-exporter/templates/servicemonitor.yaml index 6d4837aa..183fd8b4 100644 --- a/charts/stable/prometheus-nut-exporter/templates/servicemonitor.yaml +++ b/charts/stable/prometheus-nut-exporter/templates/servicemonitor.yaml @@ -1,22 +1,28 @@ -{{- if .Values.serviceMonitor.enabled }} +{{- if .Values.prometheus.serviceMonitor.enabled }} apiVersion: monitoring.coreos.com/v1 kind: ServiceMonitor metadata: - name: {{ include "prometheus-nut-exporter.fullname" . }} + name: {{ template "common.names.fullname" . }} labels: - {{- include "prometheus-nut-exporter.labels" . | nindent 4 }} + {{- include "common.labels" . | nindent 4 }} + {{- with .Values.prometheus.serviceMonitor.additionalLabels }} + {{- toYaml . | nindent 4 }} + {{- end }} spec: selector: matchLabels: - {{- include "prometheus-nut-exporter.selectorLabels" . | nindent 6 }} + {{- include "common.labels.selectorLabels" . | nindent 6 }} endpoints: - {{- range .Values.serviceMonitor.targets }} - - port: http - interval: 15s - scrapeTimeout: 10s - path: "/nut" - params: - target: - - "{{ .hostname }}:{{ .port }}" - {{- end }} + {{- range .Values.prometheus.serviceMonitor.targets }} + - port: http + interval: {{ .interval }} + scrapeTimeout: {{ .scrapeTimeout }} + path: /nut + params: + target: + - "{{ .hostname }}:{{ .port }}" + relabelings: + - sourceLabels: [__param_target] + targetLabel: target + {{- end }} {{- end }} diff --git a/charts/stable/prometheus-nut-exporter/values.yaml b/charts/stable/prometheus-nut-exporter/values.yaml index 2faa7ae8..6cebb725 100644 --- a/charts/stable/prometheus-nut-exporter/values.yaml +++ b/charts/stable/prometheus-nut-exporter/values.yaml @@ -1,79 +1,31 @@ -# Default values for prometheus-nut-exporter. -# This is a YAML-formatted file. -# Declare variables to be passed into your templates. - -replicaCount: 1 +# +# IMPORTANT NOTE +# +# This chart inherits from our common library chart. You can check the default values/options here: +# https://github.com/k8s-at-home/library-charts/tree/main/charts/stable/common/values.yaml +# image: repository: hon95/prometheus-nut-exporter pullPolicy: IfNotPresent - tag: "1.0.1" + tag: 1.0.1 -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: "" +strategy: + type: Recreate env: {} # TZ: UTC -serviceMonitor: - enabled: false - # Specify the list of NUT servers that should be monitored - targets: [] +service: + port: + port: 9995 + +prometheus: + serviceMonitor: + enabled: false + # Specify the list of NUT servers that should be monitored + targets: [] # - hostname: nut-server # port: 3493 - -# Probes configuration -probes: - liveness: - initialDelaySeconds: 30 - failureThreshold: 5 - timeoutSeconds: 10 - readiness: - initialDelaySeconds: 30 - failureThreshold: 5 - timeoutSeconds: 10 - -podAnnotations: {} - -podSecurityContext: {} - # fsGroup: 2000 - -securityContext: {} - # capabilities: - # drop: - # - ALL - # readOnlyRootFilesystem: true - # runAsNonRoot: true - # runAsUser: 1000 - -service: - type: ClusterIP - port: 9995 - -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: {} + # interval: 30s + # scrapeTimeout: 10s