Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[prometheus-opencost-exporter] new OpenCost Prometheus exporter chart #3872

Merged
merged 13 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
/charts/prometheus-nats-exporter/ @caarlos0 @okgolove
/charts/prometheus-nginx-exporter/ @nlamirault @zeritti
/charts/prometheus-node-exporter/ @gianrubio @zanhsieh @zeritti
/charts/prometheus-opencost-exporter/ @mattray
/charts/prometheus-operator-admission-webhook/ @zeritti
/charts/prometheus-operator-crds/ @dacamposol @desaintmartin @jkroepke @QuentinBisson
/charts/prometheus-pgbouncer-exporter/ @stewartshea @zeritti
Expand Down
23 changes: 23 additions & 0 deletions charts/prometheus-opencost-exporter/.helmignore
Original file line number Diff line number Diff line change
@@ -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/
16 changes: 16 additions & 0 deletions charts/prometheus-opencost-exporter/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
appVersion: 1.107.1
version: 0.1.0
description: Prometheus OpenCost Exporter
home: https://github.com/opencost/opencost
name: prometheus-opencost-exporter
sources:
- https://github.com/prometheus-community/opencost_exporter
apiVersion: v2
type: application
keywords:
- opencost
- prometheus
- exporter
maintainers:
- email: [email protected]
name: mattray
57 changes: 57 additions & 0 deletions charts/prometheus-opencost-exporter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Prometheus Opencost Exporter

Prometheus exporter for [OpenCost](https://www.opencost.io) Kubernetes cost monitoring data.

This chart bootstraps a Prometheus [OpenCost exporter](https://www.opencost.io/docs/integrations/opencost-exporter) deployment on a [Kubernetes](http://kubernetes.io) cluster using the [Helm](https://helm.sh) package manager.

The original source for this Helm chart is <https://github.com/opencost/opencost-helm-chart>.

## Prerequisites

- Kubernetes 1.23+
- Helm 3+

## Add Helm Chart Repository

```console
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo update
```

_See [`helm repo`](https://helm.sh/docs/helm/helm_repo/) for command documentation._

## Install Chart

```console
helm install [RELEASE_NAME] prometheus-community/prometheus-opencost-exporter
```

_See [configuration](#configuring) below._

_See [helm install](https://helm.sh/docs/helm/helm_install/) for command documentation._

## Uninstall Chart

```console
helm uninstall [RELEASE_NAME]
```

This removes all the Kubernetes components associated with the chart and deletes the release.

_See [helm uninstall](https://helm.sh/docs/helm/helm_uninstall/) for command documentation._

### Other minor version upgrade

```console
helm upgrade [RELEASE_NAME] [CHART] --install
```

_See [helm upgrade](https://helm.sh/docs/helm/helm_upgrade/) for command documentation._

## Configuring

See [Customizing the Chart Before Installing](https://helm.sh/docs/intro/using_helm/#customizing-the-chart-before-installing). To see all configurable options with detailed comments, visit the chart's [values.yaml](./values.yaml), or run these configuration commands:

```console
helm show values prometheus-community/prometheus-opencost-exporter
```
99 changes: 99 additions & 0 deletions charts/prometheus-opencost-exporter/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "prometheus-opencost-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-opencost-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-opencost-exporter.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Common labels
*/}}
{{- define "prometheus-opencost-exporter.labels" -}}
helm.sh/chart: {{ include "prometheus-opencost-exporter.chart" . }}
{{ include "prometheus-opencost-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-opencost-exporter.selectorLabels" -}}
app.kubernetes.io/name: {{ include "prometheus-opencost-exporter.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "prometheus-opencost-exporter.serviceAccountName" -}}
{{- if .Values.serviceAccount.create -}}
{{ default (include "prometheus-opencost-exporter.fullname" .) .Values.serviceAccount.name }}
{{- else -}}
{{ default "default" .Values.serviceAccount.name }}
{{- end -}}
{{- 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).
*/}}
{{- define "prometheus-opencost-exporter.prometheus.secretname" -}}
{{- if .Values.opencost.prometheus.secret_name -}}
{{- .Values.opencost.prometheus.secret_name -}}
{{- else -}}
{{- include "prometheus-opencost-exporter.fullname" . -}}
{{- end -}}
{{- end -}}

{{/*
Create the name of the controller service account to use
*/}}
{{- define "prometheus-opencost-exporter.prometheusServerEndpoint" -}}
{{- if .Values.opencost.prometheus.external.enabled -}}
{{ tpl .Values.opencost.prometheus.external.url . }}
{{- else -}}
{{- $host := tpl .Values.opencost.prometheus.internal.serviceName . }}
{{- $ns := tpl .Values.opencost.prometheus.internal.namespaceName . }}
{{- $port := .Values.opencost.prometheus.internal.port | int }}
{{- printf "http://%s.%s.svc:%d" $host $ns $port -}}
{{- end -}}
{{- end -}}


{{/*
Check that either prometheus external or internal is defined
*/}}
{{- define "isPrometheusConfigValid" -}}
{{- if and .Values.opencost.prometheus.external.enabled .Values.opencost.prometheus.internal.enabled -}}
{{- fail "Only use one of the prometheus setups, internal or external" -}}
{{- end -}}
{{- end -}}
79 changes: 79 additions & 0 deletions charts/prometheus-opencost-exporter/templates/clusterrole.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Cluster role giving opencost to get, list, watch required resources
# No write permissions are required
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: {{ include "prometheus-opencost-exporter.fullname" . }}
labels: {{- include "prometheus-opencost-exporter.labels" . | nindent 4 }}
rules:
- apiGroups: [""]
resources:
- configmaps
- deployments
- nodes
- pods
- services
- resourcequotas
- replicationcontrollers
- limitranges
- persistentvolumeclaims
- persistentvolumes
- namespaces
- endpoints
verbs:
- get
- list
- watch
- apiGroups:
- extensions
resources:
- daemonsets
- deployments
- replicasets
verbs:
- get
- list
- watch
- apiGroups:
- apps
resources:
- statefulsets
- deployments
- daemonsets
- replicasets
verbs:
- list
- watch
- apiGroups:
- batch
resources:
- cronjobs
- jobs
verbs:
- get
- list
- watch
- apiGroups:
- autoscaling
resources:
- horizontalpodautoscalers
verbs:
- get
- list
- watch
- apiGroups:
- policy
resources:
- poddisruptionbudgets
verbs:
- get
- list
- watch
- apiGroups:
- storage.k8s.io
resources:
- storageclasses
verbs:
- get
- list
- watch
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{{- if .Values.rbac.enabled }}
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: {{ include "prometheus-opencost-exporter.fullname" . }}
labels: {{- include "prometheus-opencost-exporter.labels" . | nindent 4 }}
{{- with .Values.annotations }}
annotations: {{- toYaml . | nindent 4 }}
{{- end }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: {{ include "prometheus-opencost-exporter.fullname" . }}
subjects:
- kind: ServiceAccount
name: {{ template "prometheus-opencost-exporter.serviceAccountName" . }}
namespace: {{ .Release.Namespace }}
{{- end }}
Loading