Skip to content

Commit

Permalink
feat: Add ec2-pricing-exporter chart
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreZiviani committed Dec 28, 2022
1 parent 761d8e9 commit 500358d
Show file tree
Hide file tree
Showing 9 changed files with 422 additions and 0 deletions.
8 changes: 8 additions & 0 deletions charts/ec2-pricing-exporter/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: v2
name: ec2-pricing-exporter
description: Exports the price of each EC2 instance type (spot and ondemand) as prometheus metrics
type: application
appVersion: v0.2.0
version: 0.1.0
maintainers:
- name: AndreZiviani
55 changes: 55 additions & 0 deletions charts/ec2-pricing-exporter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# ec2-pricing-exporter

Exports the price of each EC2 instance type (spot and ondemand) as prometheus metrics

## Chart Repo

Add the following repo to use the chart:

```console
helm repo add andreziviani https://andreziviani.github.io/helm-charts
```

## Values

| Key | Type | Default | Description |
|-----|------|---------|-------------|
| annotations | object | `{}` | |
| args[0] | string | `"-cache"` | |
| args[1] | string | `"3600"` | |
| containerSecurityContext.privileged | bool | `false` | |
| containerSecurityContext.runAsUser | int | `1000` | |
| fullnameOverride | string | `nil` | |
| image.pullPolicy | string | `"IfNotPresent"` | |
| image.registry | string | `"docker.io"` | |
| image.repository | string | `"andreziviani/ec2-price-exporter"` | |
| image.tag | string | `nil` | Overrides the image tag whose default is the chart's appVersion |
| imagePullSecrets | list | `[]` | |
| nameOverride | string | `nil` | |
| podAnnotations | object | `{}` | |
| podLabels | object | `{}` | |
| podPortName | string | `"http-metrics"` | |
| podSecurityContext | object | `{}` | |
| priorityClassName | string | `"system-node-critical"` | |
| replicas | int | `1` | |
| resources.requests.cpu | string | `"50m"` | |
| resources.requests.memory | string | `"128Mi"` | |
| service.annotations | object | `{}` | |
| service.enabled | bool | `true` | |
| service.labels | object | `{}` | |
| service.port | int | `80` | |
| service.portName | string | `"service"` | |
| service.targetPort | int | `8080` | |
| service.type | string | `"ClusterIP"` | |
| serviceAccount.create | bool | `true` | |
| serviceAccount.labels | object | `{}` | |
| serviceAccount.name | string | `nil` | |
| serviceMonitor.enabled | bool | `true` | |
| serviceMonitor.interval | string | `"30s"` | |
| serviceMonitor.labels | object | `{}` | |
| serviceMonitor.path | string | `"/metrics"` | |
| serviceMonitor.relabelings | list | `[]` | |
| serviceMonitor.scheme | string | `"http"` | |
| serviceMonitor.scrapeTimeout | string | `"120s"` | |
| serviceMonitor.tlsConfig | object | `{}` | |
| updateStrategy.type | string | `"RollingUpdate"` | |
17 changes: 17 additions & 0 deletions charts/ec2-pricing-exporter/README.md.gotmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{{ template "chart.header" . }}

{{ template "chart.description" . }}

{{ template "chart.sourcesSection" . }}

{{ template "chart.requirementsSection" . }}

## Chart Repo

Add the following repo to use the chart:

```console
helm repo add andreziviani https://andreziviani.github.io/helm-charts
```

{{ template "chart.valuesSection" . }}
62 changes: 62 additions & 0 deletions charts/ec2-pricing-exporter/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "ec2-pricing-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 "ec2-pricing-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 "ec2-pricing-exporter.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Common labels
*/}}
{{- define "ec2-pricing-exporter.labels" -}}
helm.sh/chart: {{ include "ec2-pricing-exporter.chart" . }}
{{ include "ec2-pricing-exporter.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "ec2-pricing-exporter.selectorLabels" -}}
app.kubernetes.io/name: {{ include "ec2-pricing-exporter.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Create the name of the service account
*/}}
{{- define "ec2-pricing-exporter.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "ec2-pricing-exporter.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
73 changes: 73 additions & 0 deletions charts/ec2-pricing-exporter/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "ec2-pricing-exporter.fullname" . }}
labels:
{{- include "ec2-pricing-exporter.labels" . | nindent 4 }}
{{- with .Values.annotations }}
annotations:
{{ toYaml . | indent 4 }}
{{- end }}
spec:
selector:
matchLabels:
{{- include "ec2-pricing-exporter.selectorLabels" . | nindent 6 }}
replicas: {{ .Values.replicas }}
template:
metadata:
labels:
{{- include "ec2-pricing-exporter.selectorLabels" . | nindent 8 }}
{{- with .Values.podLabels }}
{{- toYaml . | indent 8 }}
{{- end }}
annotations:
{{- with .Values.podAnnotations }}
{{- toYaml . | indent 8 }}
{{- end }}
spec:
serviceAccountName: {{ include "ec2-pricing-exporter.serviceAccountName" . }}
{{- with .Values.priorityClassName }}
priorityClassName: {{ . }}
{{- end }}
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
containers:
- name: ec2-pricing-exporter
image: "{{ .Values.image.registry }}/{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
{{- with .Values.args }}
args:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with .Values.containerSecurityContext }}
securityContext:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with .Values.resources }}
resources:
{{- toYaml . | nindent 12 }}
{{- end }}
ports:
- name: {{ .Values.podPortName }}
containerPort: {{ .Values.service.targetPort }}
protocol: TCP
{{- if .Values.topologySpreadConstraints }}
topologySpreadConstraints:
{{- tpl (.Values.topologySpreadConstraints) . | nindent 8 }}
{{- end }}
{{- if .Values.nodeSelector }}
nodeSelector:
{{- tpl (.Values.nodeSelector) . | nindent 8 }}
{{- end }}
{{- if .Values.tolerations }}
tolerations:
{{- tpl (.Values.tolerations) . | nindent 8 }}
{{- end }}
{{- if .Values.affinity }}
affinity:
{{- tpl (.Values.affinity) . | nindent 8 }}
{{- end }}
54 changes: 54 additions & 0 deletions charts/ec2-pricing-exporter/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{{- if .Values.service.enabled }}
{{- $root := . }}
apiVersion: v1
kind: Service
metadata:
name: {{ include "ec2-pricing-exporter.fullname" . }}
labels:
{{- include "ec2-pricing-exporter.labels" . | nindent 4 }}
{{- with .Values.service.labels }}
{{- toYaml . | nindent 4 }}
{{- end }}
{{- with .Values.service.annotations }}
annotations:
{{- tpl (toYaml . | nindent 4) $root }}
{{- end }}
spec:
{{- if (or (eq .Values.service.type "ClusterIP") (empty .Values.service.type)) }}
type: ClusterIP
{{- with .Values.service.clusterIP }}
clusterIP: {{ . }}
{{- end }}
{{- else if eq .Values.service.type "LoadBalancer" }}
type: {{ .Values.service.type }}
{{- with .Values.service.loadBalancerIP }}
loadBalancerIP: {{ . }}
{{- end }}
{{- with .Values.service.loadBalancerSourceRanges }}
loadBalancerSourceRanges:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- else }}
type: {{ .Values.service.type }}
{{- end }}
{{- with .Values.service.externalIPs }}
externalIPs:
{{- toYaml . | nindent 4 }}
{{- end }}
ports:
- name: {{ .Values.service.portName }}
port: {{ .Values.service.port }}
protocol: TCP
targetPort: {{ .Values.service.targetPort }}
{{- with .Values.service.appProtocol }}
appProtocol: {{ . }}
{{- end }}
{{- if (and (eq .Values.service.type "NodePort") (not (empty .Values.service.nodePort))) }}
nodePort: {{ .Values.service.nodePort }}
{{- end }}
{{- with .Values.extraExposePorts }}
{{- tpl (toYaml . | nindent 4) $root }}
{{- end }}
selector:
{{- include "ec2-pricing-exporter.selectorLabels" . | nindent 4 }}
{{- end }}
16 changes: 16 additions & 0 deletions charts/ec2-pricing-exporter/templates/serviceaccount.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{{- if .Values.serviceAccount.create }}
{{- $root := . -}}
apiVersion: v1
kind: ServiceAccount
metadata:
labels:
{{- include "ec2-pricing-exporter.labels" . | nindent 4 }}
{{- with .Values.serviceAccount.labels }}
{{- toYaml . | nindent 4 }}
{{- end }}
{{- with .Values.serviceAccount.annotations }}
annotations:
{{- tpl (toYaml . | nindent 4) $root }}
{{- end }}
name: {{ include "ec2-pricing-exporter.serviceAccountName" . }}
{{- end }}
42 changes: 42 additions & 0 deletions charts/ec2-pricing-exporter/templates/servicemonitor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{{- if .Values.serviceMonitor.enabled }}
---
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: {{ include "ec2-pricing-exporter.fullname" . }}
{{- if .Values.serviceMonitor.namespace }}
namespace: {{ tpl .Values.serviceMonitor.namespace . }}
{{- end }}
labels:
{{- include "ec2-pricing-exporter.labels" . | nindent 4 }}
{{- with .Values.serviceMonitor.labels }}
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
endpoints:
- port: {{ .Values.service.portName }}
{{- with .Values.serviceMonitor.interval }}
interval: {{ . }}
{{- end }}
{{- with .Values.serviceMonitor.scrapeTimeout }}
scrapeTimeout: {{ . }}
{{- end }}
honorLabels: true
path: {{ .Values.serviceMonitor.path }}
scheme: {{ .Values.serviceMonitor.scheme }}
{{- with .Values.serviceMonitor.tlsConfig }}
tlsConfig:
{{- toYaml . | nindent 6 }}
{{- end }}
{{- with .Values.serviceMonitor.relabelings }}
relabelings:
{{- toYaml . | nindent 6 }}
{{- end }}
jobLabel: "{{ .Release.Name }}"
selector:
matchLabels:
{{- include "ec2-pricing-exporter.selectorLabels" . | nindent 6 }}
namespaceSelector:
matchNames:
- {{ .Release.Namespace }}
{{- end }}
Loading

0 comments on commit 500358d

Please sign in to comment.