Skip to content

Commit

Permalink
Add a helm chart
Browse files Browse the repository at this point in the history
Adding a helm chart with some basic stuff, like minigun instances
deployments
  • Loading branch information
adidenko committed Sep 19, 2024
1 parent abe4eb2 commit 2bea5c2
Show file tree
Hide file tree
Showing 11 changed files with 415 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
vendor

# Ignore binary and release tarballs
minigun
./minigun
*.tgz
output/*
25 changes: 25 additions & 0 deletions chart/minigun/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# 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/
# Local files not needed in state
examples
24 changes: 24 additions & 0 deletions chart/minigun/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: v2
name: minigun
description: A Helm chart for Minigun

# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application

# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.1.0

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "0.6.0"
43 changes: 43 additions & 0 deletions chart/minigun/examples/two-miniguns.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Values example
benchmarkDeployments:
# Defaults for all benchmark instances
defaults:
resources:
limits:
cpu: 4
memory: 1Gi

serviceMonitor:
enabled: true

# Define benchmark instances
instances:

test-google: # unique name of the benchmark, will be used for k8s resource names
enabled: true # toggle to enable override via deeper merge
spec: # the rest the of spec, same as in the `default` section above
replicas: 3
args:
fire-duration: 0 # infinite
fire-rate: 10 # per instance
send-method: GET
send-mode: http
send-timeout: 3s
workers: 16
disable-keep-alive: true
fire-target: https://www.google.com/

test-local-ip: # unique name of the benchmark, will be used for k8s resource names
enabled: true # toggle to enable override via deeper merge
spec: # the rest the of spec, same as in the `default` section above
args:
fire-duration: 0 # infinite
fire-rate: 10 # per instance
send-method: GET
send-mode: http
send-timeout: 1s
workers: 8
disable-keep-alive: true
fire-target: http://10.10.10.10/
http-header: "Host: my-site.cluster.local"

1 change: 1 addition & 0 deletions chart/minigun/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Congratulations! You've deployed Minigun as {{ .Release.Name }} in {{ .Release.Namespace }} namespace.
49 changes: 49 additions & 0 deletions chart/minigun/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "minigun.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 "minigun.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 "minigun.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "minigun.labels" -}}
helm.sh/chart: {{ include "minigun.chart" . }}
{{ include "minigun.selectorLabels" . }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

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

89 changes: 89 additions & 0 deletions chart/minigun/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
{{- $defaults := .Values.benchmarkDeployments.defaults }}
{{- $app := include "minigun.fullname" . }}
{{- $labels := include "minigun.labels" . }}
{{- $selectorLabels := include "minigun.selectorLabels" . }}
{{- $saName := .Values.benchmarkDeployments.serviceAccount.name }}
{{- range $name, $values := .Values.benchmarkDeployments.instances }}
{{- if $values.enabled }}
{{- $spec := deepCopy $defaults | merge $values.spec }}
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ $app }}-{{ $name }}
labels:
{{- $labels | nindent 4 }}
benchmark: {{ $name }}
spec:
replicas: {{ $spec.replicas }}
selector:
matchLabels:
{{- $selectorLabels | nindent 6 }}
benchmark: {{ $name }}
template:
metadata:
{{- with $spec.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- $labels | nindent 8 }}
{{- with $spec.podLabels }}
{{- toYaml . | nindent 8 }}
{{- end }}
benchmark: {{ $name }}
spec:
{{- with $spec.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ $saName }}
securityContext:
{{- toYaml $spec.podSecurityContext | nindent 8 }}
containers:
- name: minigun
args:
- --name={{ $name }}
{{- range $k, $v := $spec.args }}
{{- if eq $k "http-header" }}
- --{{ $k }}='{{ $v }}'
{{- else }}
- --{{ $k }}={{ $v }}
{{- end }}
{{- end }}
securityContext:
{{- toYaml $spec.securityContext | nindent 12 }}
image: "{{ $spec.image.repository }}:{{ $spec.image.tag }}"
imagePullPolicy: {{ $spec.image.pullPolicy }}
ports:
- name: http
containerPort: {{ $spec.service.port }}
protocol: TCP
livenessProbe:
{{- toYaml $spec.livenessProbe | nindent 12 }}
readinessProbe:
{{- toYaml $spec.readinessProbe | nindent 12 }}
resources:
{{- toYaml $spec.resources | nindent 12 }}
{{- with $spec.volumeMounts }}
volumeMounts:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with $spec.volumes }}
volumes:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with $spec.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with $spec.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with $spec.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- end }}
{{- end }}
27 changes: 27 additions & 0 deletions chart/minigun/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{{- $defaults := .Values.benchmarkDeployments.defaults }}
{{- $app := include "minigun.fullname" . }}
{{- $labels := include "minigun.labels" . }}
{{- $selectorLabels := include "minigun.selectorLabels" . }}
{{- range $name, $values := .Values.benchmarkDeployments.instances }}
{{- if $values.enabled }}
{{- $spec := deepCopy $defaults | merge $values.spec }}
---
apiVersion: v1
kind: Service
metadata:
name: {{ $app }}-{{ $name }}
labels:
{{- $labels | nindent 4 }}
benchmark: {{ $name }}
spec:
type: {{ $spec.service.type }}
ports:
- port: {{ $spec.service.port }}
targetPort: http
protocol: TCP
name: http
selector:
{{- $selectorLabels | nindent 4 }}
benchmark: {{ $name }}
{{- end }}
{{- end }}
13 changes: 13 additions & 0 deletions chart/minigun/templates/serviceaccount.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{{- if and .Values.benchmarkDeployments.serviceAccount.create (ne .Values.benchmarkDeployments.serviceAccount.name "default")}}
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ .Values.benchmarkDeployments.serviceAccount.name }}
labels:
{{- include "minigun.labels" . | nindent 4 }}
{{- with .Values.benchmarkDeployments.serviceAccount.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
automountServiceAccountToken: {{ .Values.benchmarkDeployments.serviceAccount.automount }}
{{- end }}
37 changes: 37 additions & 0 deletions chart/minigun/templates/servicemonitor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{{- $defaults := .Values.benchmarkDeployments.defaults }}
{{- $app := include "minigun.fullname" . }}
{{- $labels := include "minigun.labels" . }}
{{- $selectorLabels := include "minigun.selectorLabels" . }}
{{- range $name, $values := .Values.benchmarkDeployments.instances }}
{{- if $values.enabled }}
{{- $spec := deepCopy $defaults | merge $values.spec }}
{{- if $spec.serviceMonitor.enabled }}
---
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: {{ $app }}-{{ $name }}
labels:
{{- $labels | nindent 4 }}
benchmark: {{ $name }}
spec:
endpoints:
- interval: {{ $spec.serviceMonitor.interval }}
metricRelabelings:
- action: keep
regex: "^minigun_.*"
sourceLabels:
- __name__
path: /metrics
port: http
relabelings:
scheme: http
scrapeTimeout: {{ $spec.serviceMonitor.scrapeTimeout }}
jobLabel: app.kubernetes.io/instance
selector:
matchLabels:
{{- $selectorLabels | nindent 6 }}
benchmark: {{ $name }}
{{- end }}
{{- end }}
{{- end }}
Loading

0 comments on commit 2bea5c2

Please sign in to comment.