diff --git a/.gitignore b/.gitignore index 9873473..7f62c5e 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,6 @@ vendor # Ignore binary and release tarballs -minigun +./minigun *.tgz output/* diff --git a/chart/minigun/.helmignore b/chart/minigun/.helmignore new file mode 100644 index 0000000..f6bd96f --- /dev/null +++ b/chart/minigun/.helmignore @@ -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 diff --git a/chart/minigun/Chart.yaml b/chart/minigun/Chart.yaml new file mode 100644 index 0000000..2c9997c --- /dev/null +++ b/chart/minigun/Chart.yaml @@ -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" diff --git a/chart/minigun/examples/two-miniguns.yaml b/chart/minigun/examples/two-miniguns.yaml new file mode 100644 index 0000000..ae5e163 --- /dev/null +++ b/chart/minigun/examples/two-miniguns.yaml @@ -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" + diff --git a/chart/minigun/templates/NOTES.txt b/chart/minigun/templates/NOTES.txt new file mode 100644 index 0000000..a2b23d7 --- /dev/null +++ b/chart/minigun/templates/NOTES.txt @@ -0,0 +1 @@ +Congratulations! You've deployed Minigun as {{ .Release.Name }} in {{ .Release.Namespace }} namespace. diff --git a/chart/minigun/templates/_helpers.tpl b/chart/minigun/templates/_helpers.tpl new file mode 100644 index 0000000..b55e59b --- /dev/null +++ b/chart/minigun/templates/_helpers.tpl @@ -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 }} + diff --git a/chart/minigun/templates/deployment.yaml b/chart/minigun/templates/deployment.yaml new file mode 100644 index 0000000..bd4a01d --- /dev/null +++ b/chart/minigun/templates/deployment.yaml @@ -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 }} diff --git a/chart/minigun/templates/service.yaml b/chart/minigun/templates/service.yaml new file mode 100644 index 0000000..6021ccd --- /dev/null +++ b/chart/minigun/templates/service.yaml @@ -0,0 +1,29 @@ +{{- $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 or $spec.service.enabled $spec.serviceMonitor.enabled }} +--- +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 }} +{{- end }} diff --git a/chart/minigun/templates/serviceaccount.yaml b/chart/minigun/templates/serviceaccount.yaml new file mode 100644 index 0000000..3ba96c0 --- /dev/null +++ b/chart/minigun/templates/serviceaccount.yaml @@ -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 }} diff --git a/chart/minigun/templates/servicemonitor.yaml b/chart/minigun/templates/servicemonitor.yaml new file mode 100644 index 0000000..3863244 --- /dev/null +++ b/chart/minigun/templates/servicemonitor.yaml @@ -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 }} diff --git a/chart/minigun/values.yaml b/chart/minigun/values.yaml new file mode 100644 index 0000000..cf96554 --- /dev/null +++ b/chart/minigun/values.yaml @@ -0,0 +1,109 @@ +# Default values for minigun. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +benchmarkDeployments: + + serviceAccount: + # Specifies whether a service account should be created + create: false + # Automatically mount a ServiceAccount's API credentials? + automount: true + # Annotations to add to the service account + annotations: {} + # The name of the service account to use. + name: "default" + + ###################### + # Default parameters to use for every instance. + # Can override via per instance values. + defaults: + replicaCount: 2 + + # Args converted to `--$ARG` for minigun. See `minigun --help` for supported args. + args: + fire-duration: 0 # infinite + fire-rate: 10 # per instance + send-method: GET + send-mode: http + workers: 4 + disable-keep-alive: true + + image: + repository: ghcr.io/wayfair-incubator/minigun + pullPolicy: IfNotPresent + # Overrides the image tag whose default is the chart appVersion. + tag: "v0.6.0" + + imagePullSecrets: [] + nameOverride: "" + fullnameOverride: "" + + podAnnotations: {} + podLabels: {} + + podSecurityContext: {} + # fsGroup: 2000 + + resources: + # We don't set default limits so that chart users have the flexibility to not + # specify limits at all (to avoid throttling for instance) + # limits: + # cpu: 4000m + # memory: 256Mi + requests: + cpu: 100m + memory: 64Mi + + securityContext: {} + # capabilities: + # drop: + # - ALL + # readOnlyRootFilesystem: true + # runAsNonRoot: true + # runAsUser: 1000 + + # Service customization + service: + enabled: true + type: ClusterIP + port: 8765 + + # ServiceMonitor from monitoring.coreos.com/v1 API group from Prometheus Operator. + serviceMonitor: + enabled: false + interval: 1m + scrapeTimeout: 10s + + # Additional volumes on the output Deployment definition. + volumes: [] + # - name: foo + # secret: + # secretName: mysecret + # optional: false + + # Additional volumeMounts on the output Deployment definition. + volumeMounts: [] + # - name: foo + # mountPath: "/etc/foo" + # readOnly: true + + nodeSelector: {} + tolerations: [] + affinity: {} + + livenessProbe: + httpGet: + path: /health + port: http + readinessProbe: + httpGet: + path: /health + port: http + + ###################### + # Actual instances of benchmarks + instances: {} + # minigun-1: # 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