From a518a9f38421305e2d3c0a51f0fa6fb56a0cc544 Mon Sep 17 00:00:00 2001 From: Shane Starcher Date: Fri, 17 Jan 2020 14:15:51 -0800 Subject: [PATCH] move chart into repo for helm hub and fix helm 3 issues --- README.md | 4 +- go.mod | 7 ++- go.sum | 13 ++-- helm/Chart.yaml | 13 ++++ helm/README.md | 58 ++++++++++++++++++ helm/templates/NOTES.txt | 21 +++++++ helm/templates/_helpers.tpl | 63 +++++++++++++++++++ helm/templates/deployment.yaml | 62 +++++++++++++++++++ helm/templates/ingress.yaml | 41 +++++++++++++ helm/templates/role.yaml | 16 +++++ helm/templates/role_binding.yaml | 14 +++++ helm/templates/service.yaml | 19 ++++++ helm/templates/serviceaccount.yaml | 8 +++ helm/templates/servicemonitor.yaml | 31 ++++++++++ helm/templates/tests/test-connection.yaml | 15 +++++ helm/values.yaml | 73 +++++++++++++++++++++++ main.go | 25 ++++---- 17 files changed, 460 insertions(+), 23 deletions(-) create mode 100644 helm/Chart.yaml create mode 100644 helm/README.md create mode 100644 helm/templates/NOTES.txt create mode 100644 helm/templates/_helpers.tpl create mode 100644 helm/templates/deployment.yaml create mode 100644 helm/templates/ingress.yaml create mode 100644 helm/templates/role.yaml create mode 100644 helm/templates/role_binding.yaml create mode 100644 helm/templates/service.yaml create mode 100644 helm/templates/serviceaccount.yaml create mode 100644 helm/templates/servicemonitor.yaml create mode 100644 helm/templates/tests/test-connection.yaml create mode 100644 helm/values.yaml diff --git a/README.md b/README.md index 57302bc..06ab8f0 100644 --- a/README.md +++ b/README.md @@ -6,8 +6,8 @@ Exports helm release, chart, and version statistics in the prometheus format. # Installation -* A helm chart is available in this [repository](https://github.com/helm/charts/tree/master/stable/helm-exporter). -* `helm install helm/helm-exporter --name=helm-exporter` will install and metrics should scrape automatically if prometheus is running +* A helm chart is available in this [repository](https://hub.helm.sh/charts/sstarcher/helm-exporter). +* `helm install helm-exporter sstarcher/helm-exporter` will install and metrics should scrape automatically if prometheus is running * If using Grafana you can use this Dashboard to have a list of what's running https://grafana.com/dashboards/9367 # Metrics diff --git a/go.mod b/go.mod index 9516095..576f8d3 100644 --- a/go.mod +++ b/go.mod @@ -14,7 +14,8 @@ require ( github.com/orcaman/concurrent-map v0.0.0-20190826125027-8c72a8bb44f6 github.com/prometheus/client_golang v1.2.1 github.com/sirupsen/logrus v1.4.2 - helm.sh/helm/v3 v3.0.0 - k8s.io/apimachinery v0.0.0-20191028221656-72ed19daf4bb - k8s.io/client-go v0.0.0-20191114101535-6c5935290e33 + helm.sh/helm/v3 v3.0.2 + k8s.io/apimachinery v0.0.0-20191004115801-a2eda9f80ab8 + k8s.io/client-go v0.0.0-20191016111102-bec269661e48 + ) diff --git a/go.sum b/go.sum index f93dbe4..82ac8dc 100644 --- a/go.sum +++ b/go.sum @@ -25,10 +25,10 @@ github.com/MakeNowJust/heredoc v0.0.0-20171113091838-e9091a26100e h1:eb0Pzkt15Bm github.com/MakeNowJust/heredoc v0.0.0-20171113091838-e9091a26100e/go.mod h1:64YHyfSL2R96J44Nlwm39UHepQbyR5q10x7iYa1ks2E= github.com/Masterminds/goutils v1.1.0 h1:zukEsf/1JZwCMgHiK3GZftabmxiCw4apj3a28RPBiVg= github.com/Masterminds/goutils v1.1.0/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU= -github.com/Masterminds/semver/v3 v3.0.1 h1:2kKm5lb7dKVrt5TYUiAavE6oFc1cFT0057UVGT+JqLk= -github.com/Masterminds/semver/v3 v3.0.1/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs= -github.com/Masterminds/sprig/v3 v3.0.0 h1:KSQz7Nb08/3VU9E4ns29dDxcczhOD1q7O1UfM4G3t3g= -github.com/Masterminds/sprig/v3 v3.0.0/go.mod h1:NEUY/Qq8Gdm2xgYA+NwJM6wmfdRV9xkh8h/Rld20R0U= +github.com/Masterminds/semver/v3 v3.0.3 h1:znjIyLfpXEDQjOIEWh+ehwpTU14UzUPub3c3sm36u14= +github.com/Masterminds/semver/v3 v3.0.3/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs= +github.com/Masterminds/sprig/v3 v3.0.2 h1:wz22D0CiSctrliXiI9ZO3HoNApweeRGftyDN+BQa3B8= +github.com/Masterminds/sprig/v3 v3.0.2/go.mod h1:oesJ8kPONMONaZgtiHNzUShJbksypC5kWczhZAf6+aU= github.com/Masterminds/vcs v1.13.0/go.mod h1:N09YCmOQr6RLxC6UNHzuVwAdodYbbnycGHSmwVJjcKA= github.com/Microsoft/go-winio v0.4.11/go.mod h1:VhR8bwka0BXejwEJY73c50VrPtXAaKcyvVC4A4RozmA= github.com/Microsoft/go-winio v0.4.12 h1:xAfWHN1IrQ0NJ9TBC0KBZoqLjzDTr1ML+4MywiUOryc= @@ -561,8 +561,8 @@ gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo= gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw= -helm.sh/helm/v3 v3.0.0 h1:or/9cs1GgfcTQeEnR2CVJNw893/rmqIG1KsNHmUiSFw= -helm.sh/helm/v3 v3.0.0/go.mod h1:sI7B9yfvMgxtTPMWdk1jSKJ2aa59UyP9qhPydqW6mgo= +helm.sh/helm/v3 v3.0.2 h1:BggvLisIMrAc+Is5oAHVrlVxgwOOrMN8nddfQbm5gKo= +helm.sh/helm/v3 v3.0.2/go.mod h1:KBxE6XWO57XSNA1PA9CvVLYRY0zWqYQTad84bNXp1lw= honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= @@ -584,7 +584,6 @@ k8s.io/client-go v0.0.0-20191016111102-bec269661e48 h1:C2XVy2z0dV94q9hSSoCuTPp1K k8s.io/client-go v0.0.0-20191016111102-bec269661e48/go.mod h1:hrwktSwYGI4JK+TJA3dMaFyyvHVi/aLarVHpbs8bgCU= k8s.io/client-go v0.0.0-20191114101535-6c5935290e33 h1:07mhG/2oEoo3N+sHVOo0L9PJ/qvbk3N5n2dj8IWefnQ= k8s.io/client-go v0.0.0-20191114101535-6c5935290e33/go.mod h1:4L/zQOBkEf4pArQJ+CMk1/5xjA30B5oyWv+Bzb44DOw= -k8s.io/client-go v11.0.0+incompatible h1:LBbX2+lOwY9flffWlJM7f1Ct8V2SRNiMRDFeiwnJo9o= k8s.io/code-generator v0.0.0-20191004115455-8e001e5d1894/go.mod h1:mJUgkl06XV4kstAnLHAIzJPVCOzVR+ZcfPIv4fUsFCY= k8s.io/component-base v0.0.0-20191016111319-039242c015a9/go.mod h1:SuWowIgd/dtU/m/iv8OD9eOxp3QZBBhTIiWMsBQvKjI= k8s.io/gengo v0.0.0-20190128074634-0689ccc1d7d6/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0= diff --git a/helm/Chart.yaml b/helm/Chart.yaml new file mode 100644 index 0000000..6518db0 --- /dev/null +++ b/helm/Chart.yaml @@ -0,0 +1,13 @@ +apiVersion: v2 +name: helm-exporter +description: Exporter for helm metrics +type: application +version: 0.1.0 +appVersion: latest +home: https://github.com/sstarcher/helm-exporter +sources: +- https://github.com/sstarcher/helm-exporter +maintainers: +- name: sstarcher + email: shane.starcher@gmail.com + url: https://shanestarcher.com diff --git a/helm/README.md b/helm/README.md new file mode 100644 index 0000000..0c52582 --- /dev/null +++ b/helm/README.md @@ -0,0 +1,58 @@ +# helm-exporter + +Installs [helm-exporter](https://github.com/sstarcher/helm-exporter) to export helm stats to prometheus. + +## TL;DR; + +```console +$ helm install sstarcher/helm-exporter +``` + +## Introduction + +This chart bootstraps a [helm-exporter](https://github.com/sstarcher/helm-exporter) deployment on a [Kubernetes](http://kubernetes.io) cluster using the [Helm](https://helm.sh) package manager. + +The chart comes with a ServiceMonitor for use with the [Prometheus Operator](https://github.com/helm/charts/tree/master/stable/prometheus-operator). + +## Installing the Chart + +To install the chart with the release name `my-release`: + +```console +$ helm install sstarcher/helm-exporter --name my-release +``` + +The command deploys helm-exporter on the Kubernetes cluster in the default configuration. The [configuration](#configuration) section lists the parameters that can be configured during installation. + +## Uninstalling the Chart + +To uninstall/delete the `my-release` deployment: + +```console +$ helm delete my-release +``` + +The command removes all the Kubernetes components associated with the chart and deletes the release. + +## Configuration + +The following table lists the configurable parameters of the helm-exporter chart that are in addition to values in a default helm chart. + +Parameter | Description | Default +--- | --- | --- +`namespaces` | Specifies which namespaces to query for helm 3 metrics. Defaults to all | "" +`serviceMonitor.create` | Set to true if using the Prometheus Operator | `false` +`serviceMonitor.interval` | Interval at which metrics should be scraped | `` +`serviceMonitor.namespace` | The namespace where the Prometheus Operator is deployed | `` +`serviceMonitor.additionalLabels` | Additional labels to add to the ServiceMonitor | `{}` +```console +$ helm install my-release sstarcher/helm-exporter +``` + +Alternatively, a YAML file that specifies the values for the above parameters can be provided while installing the chart. For example, + +```console +$ helm install my-release sstarcher/helm-exporter -f values.yaml +``` + +> **Tip**: You can use the default [values.yaml](values.yaml) diff --git a/helm/templates/NOTES.txt b/helm/templates/NOTES.txt new file mode 100644 index 0000000..7e5ab23 --- /dev/null +++ b/helm/templates/NOTES.txt @@ -0,0 +1,21 @@ +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 "helm-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 "helm-exporter.fullname" . }}' + export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "helm-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 "helm-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:80 +{{- end }} diff --git a/helm/templates/_helpers.tpl b/helm/templates/_helpers.tpl new file mode 100644 index 0000000..972e5b1 --- /dev/null +++ b/helm/templates/_helpers.tpl @@ -0,0 +1,63 @@ +{{/* vim: set filetype=mustache: */}} +{{/* +Expand the name of the chart. +*/}} +{{- define "helm-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 "helm-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 "helm-exporter.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} +{{- end -}} + +{{/* +Common labels +*/}} +{{- define "helm-exporter.labels" -}} +helm.sh/chart: {{ include "helm-exporter.chart" . }} +{{ include "helm-exporter.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end -}} + +{{/* +Selector labels +*/}} +{{- define "helm-exporter.selectorLabels" -}} +app.kubernetes.io/name: {{ include "helm-exporter.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end -}} + +{{/* +Create the name of the service account to use +*/}} +{{- define "helm-exporter.serviceAccountName" -}} +{{- if .Values.serviceAccount.create -}} + {{ default (include "helm-exporter.fullname" .) .Values.serviceAccount.name }} +{{- else -}} + {{ default "default" .Values.serviceAccount.name }} +{{- end -}} +{{- end -}} diff --git a/helm/templates/deployment.yaml b/helm/templates/deployment.yaml new file mode 100644 index 0000000..96c93d4 --- /dev/null +++ b/helm/templates/deployment.yaml @@ -0,0 +1,62 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "helm-exporter.fullname" . }} + labels: + {{- include "helm-exporter.labels" . | nindent 4 }} + {{- with .Values.annotations }} + annotations: + {{ toYaml . | nindent 4 }} + {{- end }} +spec: + replicas: {{ .Values.replicaCount }} + selector: + matchLabels: + {{- include "helm-exporter.selectorLabels" . | nindent 6 }} + template: + metadata: + labels: + {{- include "helm-exporter.selectorLabels" . | nindent 8 }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + serviceAccountName: {{ include "helm-exporter.serviceAccountName" . }} + securityContext: + {{- toYaml .Values.podSecurityContext | nindent 8 }} + containers: + - name: {{ .Chart.Name }} + securityContext: + {{- toYaml .Values.securityContext | nindent 12 }} + image: "{{ .Values.image.repository }}:{{ .Chart.AppVersion }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + {{- if .Values.tillerNamespaces }} + args: ["-namespaces", {{ .Values.namespaces | quote }}] + {{- end }} + ports: + - name: http + containerPort: 9571 + protocol: TCP + livenessProbe: + httpGet: + path: /healthz + port: http + readinessProbe: + httpGet: + path: /healthz + port: http + 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/helm/templates/ingress.yaml b/helm/templates/ingress.yaml new file mode 100644 index 0000000..e8715cc --- /dev/null +++ b/helm/templates/ingress.yaml @@ -0,0 +1,41 @@ +{{- if .Values.ingress.enabled -}} +{{- $fullName := include "helm-exporter.fullname" . -}} +{{- $svcPort := .Values.service.port -}} +{{- 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 "helm-exporter.labels" . | nindent 4 }} + {{- 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: {{ .host | quote }} + http: + paths: + {{- range .paths }} + - path: {{ . }} + backend: + serviceName: {{ $fullName }} + servicePort: {{ $svcPort }} + {{- end }} + {{- end }} +{{- end }} diff --git a/helm/templates/role.yaml b/helm/templates/role.yaml new file mode 100644 index 0000000..f34ca09 --- /dev/null +++ b/helm/templates/role.yaml @@ -0,0 +1,16 @@ +kind: ClusterRole +apiVersion: rbac.authorization.k8s.io/v1 +metadata: + name: {{ include "helm-exporter.fullname" . }} + labels: +{{ include "helm-exporter.labels" . | nindent 4 }} +rules: +- apiGroups: + - "" + resources: + - namespaces + - secrets + verbs: + - get + - watch + - list diff --git a/helm/templates/role_binding.yaml b/helm/templates/role_binding.yaml new file mode 100644 index 0000000..b17b6d5 --- /dev/null +++ b/helm/templates/role_binding.yaml @@ -0,0 +1,14 @@ +kind: ClusterRoleBinding +apiVersion: rbac.authorization.k8s.io/v1 +metadata: + name: {{ include "helm-exporter.fullname" . }} + labels: +{{ include "helm-exporter.labels" . | nindent 4 }} +subjects: +- kind: ServiceAccount + namespace: {{ .Release.Namespace }} + name: {{ include "helm-exporter.serviceAccountName" . }} +roleRef: + kind: ClusterRole + name: {{ include "helm-exporter.fullname" . }} + apiGroup: rbac.authorization.k8s.io diff --git a/helm/templates/service.yaml b/helm/templates/service.yaml new file mode 100644 index 0000000..a124bec --- /dev/null +++ b/helm/templates/service.yaml @@ -0,0 +1,19 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "helm-exporter.fullname" . }} + labels: + {{- include "helm-exporter.labels" . | nindent 4 }} + {{- if not .Values.serviceMonitor.create }} + annotations: + prometheus.io/scrape: "true" + {{- end }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: http + protocol: TCP + name: http + selector: + {{- include "helm-exporter.selectorLabels" . | nindent 4 }} diff --git a/helm/templates/serviceaccount.yaml b/helm/templates/serviceaccount.yaml new file mode 100644 index 0000000..1737422 --- /dev/null +++ b/helm/templates/serviceaccount.yaml @@ -0,0 +1,8 @@ +{{- if .Values.serviceAccount.create -}} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "helm-exporter.serviceAccountName" . }} + labels: +{{ include "helm-exporter.labels" . | nindent 4 }} +{{- end -}} diff --git a/helm/templates/servicemonitor.yaml b/helm/templates/servicemonitor.yaml new file mode 100644 index 0000000..6c81232 --- /dev/null +++ b/helm/templates/servicemonitor.yaml @@ -0,0 +1,31 @@ +{{ if .Values.serviceMonitor.create }} +apiVersion: monitoring.coreos.com/v1 +kind: ServiceMonitor +metadata: + name: {{ include "helm-exporter.fullname" . }} + labels: + {{ include "helm-exporter.labels" . | nindent 4 }} + {{- range $key, $value := .Values.serviceMonitor.additionalLabels }} + {{ $key }}: {{ $value | quote }} + {{- end }} + {{- with .Values.serviceMonitor.namespace }} + namespace: {{ . }} + {{- end }} +spec: + endpoints: + - port: {{ .Values.service.port }} + honorLabels: true + {{- with .Values.serviceMonitor.interval }} + interval: {{ . }} + {{- end }} + {{- with .Values.serviceMonitor.scrapeTimeout }} + scrapeTimeout: {{ . }} + {{- end }} + namespaceSelector: + matchNames: + - {{ .Release.Namespace }} + selector: + matchLabels: + {{- include "helm-exporter.selectorLabels" . | nindent 4 }} + +{{- end }} diff --git a/helm/templates/tests/test-connection.yaml b/helm/templates/tests/test-connection.yaml new file mode 100644 index 0000000..34f7031 --- /dev/null +++ b/helm/templates/tests/test-connection.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Pod +metadata: + name: "{{ include "helm-exporter.fullname" . }}-test-connection" + labels: +{{ include "helm-exporter.labels" . | nindent 4 }} + annotations: + "helm.sh/hook": test-success +spec: + containers: + - name: wget + image: busybox + command: ['wget'] + args: ['{{ include "helm-exporter.fullname" . }}:{{ .Values.service.port }}'] + restartPolicy: Never diff --git a/helm/values.yaml b/helm/values.yaml new file mode 100644 index 0000000..27bec3d --- /dev/null +++ b/helm/values.yaml @@ -0,0 +1,73 @@ +# Specifies which namespaces to query for helm 3 metrics. Defaults to all +namespaces: "" + +serviceMonitor: + # Specifies whether a ServiceMonitor should be created + create: false + interval: + scrapeTimeout: + namespace: + additionalLabels: {} + +replicaCount: 1 + +image: + repository: sstarcher/helm-exporter + pullPolicy: Always + +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 + +service: + type: ClusterIP + port: 9571 + +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: {} diff --git a/main.go b/main.go index ceb64da..4e71274 100644 --- a/main.go +++ b/main.go @@ -67,17 +67,20 @@ func runStats() { for _, client := range clients.Items() { list := action.NewList(client.(*action.Configuration)) items, err := list.Run() - if err == nil { - for _, item := range items { - chart := item.Chart.Name() - releaseName := item.Name - version := item.Chart.Metadata.Version - appVersion := item.Chart.AppVersion() - updated := strconv.FormatInt((item.Info.LastDeployed.Unix() * 1000), 10) - namespace := item.Namespace - status := statusCodeMap[item.Info.Status.String()] - stats.WithLabelValues(chart, releaseName, version, appVersion, updated, namespace).Set(status) - } + if err != nil { + log.Warnf("got error while listing %v", err) + continue + } + + for _, item := range items { + chart := item.Chart.Name() + releaseName := item.Name + version := item.Chart.Metadata.Version + appVersion := item.Chart.AppVersion() + updated := strconv.FormatInt((item.Info.LastDeployed.Unix() * 1000), 10) + namespace := item.Namespace + status := statusCodeMap[item.Info.Status.String()] + stats.WithLabelValues(chart, releaseName, version, appVersion, updated, namespace).Set(status) } } }