Skip to content

Commit

Permalink
feat: Add eks-cost-explorer chart
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreZiviani committed Dec 30, 2022
1 parent 6ca512d commit 18790f3
Show file tree
Hide file tree
Showing 9 changed files with 419 additions and 0 deletions.
8 changes: 8 additions & 0 deletions charts/eks-cost-exporter/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: v2
name: eks-cost-exporter
description: Exports the cost of each Kubernetes pod as prometheus metrics
type: application
appVersion: v0.2.1
version: 0.1.0
maintainers:
- name: AndreZiviani
54 changes: 54 additions & 0 deletions charts/eks-cost-exporter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# eks-cost-exporter

Exports the cost of each Kubernetes pod 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 | list | `[]` | |
| containerSecurityContext.privileged | bool | `false` | |
| containerSecurityContext.runAsUser | int | `1000` | |
| fullnameOverride | string | `nil` | |
| image.pullPolicy | string | `"IfNotPresent"` | |
| image.registry | string | `"docker.io"` | |
| image.repository | string | `"andreziviani/eks-cost-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 | `false` | |
| serviceMonitor.interval | string | `"30s"` | |
| serviceMonitor.labels | object | `{}` | |
| serviceMonitor.path | string | `"/metrics"` | |
| serviceMonitor.relabelings | list | `[]` | |
| serviceMonitor.scheme | string | `"http"` | |
| serviceMonitor.scrapeTimeout | string | `"30s"` | |
| serviceMonitor.tlsConfig | object | `{}` | |
| updateStrategy.type | string | `"RollingUpdate"` | |
17 changes: 17 additions & 0 deletions charts/eks-cost-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/eks-cost-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 "eks-cost-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 "eks-cost-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 "eks-cost-exporter.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}

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

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

{{/*
Create the name of the service account
*/}}
{{- define "eks-cost-exporter.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "eks-cost-exporter.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
73 changes: 73 additions & 0 deletions charts/eks-cost-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 "eks-cost-exporter.fullname" . }}
labels:
{{- include "eks-cost-exporter.labels" . | nindent 4 }}
{{- with .Values.annotations }}
annotations:
{{ toYaml . | indent 4 }}
{{- end }}
spec:
selector:
matchLabels:
{{- include "eks-cost-exporter.selectorLabels" . | nindent 6 }}
replicas: {{ .Values.replicas }}
template:
metadata:
labels:
{{- include "eks-cost-exporter.selectorLabels" . | nindent 8 }}
{{- with .Values.podLabels }}
{{- toYaml . | indent 8 }}
{{- end }}
annotations:
{{- with .Values.podAnnotations }}
{{- toYaml . | indent 8 }}
{{- end }}
spec:
serviceAccountName: {{ include "eks-cost-exporter.serviceAccountName" . }}
{{- with .Values.priorityClassName }}
priorityClassName: {{ . }}
{{- end }}
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
containers:
- name: eks-cost-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/eks-cost-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 "eks-cost-exporter.fullname" . }}
labels:
{{- include "eks-cost-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 "eks-cost-exporter.selectorLabels" . | nindent 4 }}
{{- end }}
16 changes: 16 additions & 0 deletions charts/eks-cost-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 "eks-cost-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 "eks-cost-exporter.serviceAccountName" . }}
{{- end }}
42 changes: 42 additions & 0 deletions charts/eks-cost-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 "eks-cost-exporter.fullname" . }}
{{- if .Values.serviceMonitor.namespace }}
namespace: {{ tpl .Values.serviceMonitor.namespace . }}
{{- end }}
labels:
{{- include "eks-cost-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 "eks-cost-exporter.selectorLabels" . | nindent 6 }}
namespaceSelector:
matchNames:
- {{ .Release.Namespace }}
{{- end }}
Loading

0 comments on commit 18790f3

Please sign in to comment.