Skip to content

Commit

Permalink
chore: add helm chart
Browse files Browse the repository at this point in the history
  • Loading branch information
katallaxie authored Jul 14, 2024
1 parent d9ddfe9 commit 71bcc69
Show file tree
Hide file tree
Showing 12 changed files with 521 additions and 0 deletions.
5 changes: 5 additions & 0 deletions helm/cr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# https://github.com/helm/chart-releaser#config-file

pages-branch: gh-pages
pages-index-path: helm/charts/index.yaml
skip-existing: true
24 changes: 24 additions & 0 deletions helm/knox/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# 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
*~
# Various IDEs
.project
.idea/
*.tmproj

# Chart specific files
README.md
11 changes: 11 additions & 0 deletions helm/knox/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: v2
appVersion: 0.1.0
description: A helm chart for Knox
name: knox
keywords:
- terraform
- state
version: 0.1.0
sources:
- https://github.com/zeiss/knox
home: http://github.com/zeiss/knox
8 changes: 8 additions & 0 deletions helm/knox/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Knox

## TL;DR

```console
helm repo add knox https://zeiss.github.io/knox/helm/charts/
helm install my-knox knox/knox
```
70 changes: 70 additions & 0 deletions helm/knox/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "knox.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 "knox.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 }}

{{/*
Expand the namespace of the release.
Allows overriding it for multi-namespace deployments in combined charts.
*/}}
{{- define "knox.namespace" -}}
{{- default .Release.Namespace .Values.namespaceOverride | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "knox.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

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

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

{{/*
Create the name of the service account to use
*/}}
{{- define "knox.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "knox.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
116 changes: 116 additions & 0 deletions helm/knox/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "knox.fullname" . }}
labels:
{{- include "knox.labels" . | nindent 4 }}
{{- with .Values.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
{{- if not .Values.autoscaling.enabled }}
replicas: {{ .Values.replicaCount}}
{{- end }}
selector:
matchLabels:
{{- include "knox.selectorLabels" . | nindent 6 }}
template:
metadata:
annotations:
{{- with .Values.podAnnotations }}
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "knox.selectorLabels" . | nindent 8 }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "knox.serviceAccountName" . }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
{{ if or (and .Values.database.applyMigrations .Values.database.waitForMigrations) .Values.extraInitContainers }}
initContainers:
{{- if and .Values.database.applyMigrations .Values.database.waitForMigrations }}
- name: wait-for-migration
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.initContainer.repository }}:{{ .Values.initContainer.tag }}"
imagePullPolicy: {{ .Values.initContainer.pullPolicy }}
args: ["job-wr", '{{ include "knox.fullname" . }}-migrate']
resources:
{{- toYaml .Values.database.migrations.resources | nindent 12 }}
{{- end }}
{{- with .Values.extraInitContainers }}
{{- toYaml . | nindent 8 }}
{{- end }}
{{- end }}
containers:
- name: {{ .Chart.Name }}
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
args: []
ports:

- name: http
containerPort: {{ (split ":" .Values.http.addr)._1 }}
protocol: TCP

env:
{{- if .Values.database.uri }}
- name: knox_ACCOUNTS_DATABASE_URI
value: "{{ .Values.database.uri }}"
{{- else if .Values.database.uriSecret }}
- name: knox_ACCOUNTS_DATABASE_URI
valueFrom:
secretKeyRef:
name: "{{ .Values.database.uriSecret }}"
key: "uri"
{{- end }}

{{- if .Values.database.prefix }}
- name: knox_ACCOUNTS_DATABASE_PREFIX
value: "{{ .Values.database.prefix }}"
{{- end }}

{{- if .Values.http.addr }}
- name: knox_ACCOUNTS_ADDR
value: "{{ .Values.http.addr }}"
{{- end }}

{{- with .Values.extraEnvVars }}
{{- toYaml . | nindent 12 }}
{{- end }}

resources:
{{- toYaml .Values.resources | nindent 12 }}

{{- with .Values.extraVolumeMounts }}
volumeMounts:
{{- toYaml . | nindent 12 }}
{{- end }}

{{- if .Values.sidecars }}
{{- include "common.tplvalues.render" ( dict "value" .Values.sidecars "context" $) | nindent 8 }}
{{- end }}

{{- with .Values.extraVolumes }}
volumes:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
32 changes: 32 additions & 0 deletions helm/knox/templates/hpa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{{- if .Values.autoscaling.enabled }}
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: {{ include "knox.fullname" . }}
labels:
{{- include "knox.labels" . | nindent 4 }}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ include "knox.fullname" . }}
minReplicas: {{ .Values.autoscaling.minReplicas }}
maxReplicas: {{ .Values.autoscaling.maxReplicas }}
metrics:
{{- if .Values.autoscaling.targetCPUUtilizationPercentage }}
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }}
{{- end }}
{{- if .Values.autoscaling.targetMemoryUtilizationPercentage }}
- type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }}
{{- end }}
{{- end }}
78 changes: 78 additions & 0 deletions helm/knox/templates/job.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{{- if .Values.database.applyMigrations -}}
apiVersion: batch/v1
kind: Job
metadata:
name: {{ include "knox.fullname" . }}-migrate
labels:
{{- include "knox.labels" . | nindent 4 }}
{{- with .Values.migrate.labels }}
{{- toYaml . | nindent 4}}
{{- end}}
{{- with .Values.migrate.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
template:
metadata:
{{- with .Values.migrate.annotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.migrate.labels }}
labels:
{{- toYaml . | nindent 8 }}
{{- end }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "knox.serviceAccountName" . }}
containers:
- name: migrate-database
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
args: ["migrate"]
env:
{{- if .Values.database.uri }}
- name: knox_ACCOUNTS_DATABASE_URI
value: "{{ .Values.database.uri }}"
{{- else if .Values.database.uriSecret }}
- name: knox_ACCOUNTS_DATABASE_URI
valueFrom:
secretKeyRef:
name: "{{ .Values.database.uriSecret }}"
key: "uri"
{{- end }}

{{- if .Values.migrate.timeout }}
- name: knox_TIMEOUT
value: "{{ .Values.migrate.timeout }}"
{{- end }}

{{- with .Values.extraEnvVars }}
{{- toYaml . | nindent 12 }}
{{- end }}

resources:
{{- toYaml .Values.database.migrations.resources | nindent 12 }}
{{- if .Values.migrate.sidecars }}
{{- include "common.tplvalues.render" ( dict "value" .Values.migrate.sidecars "context" $) | nindent 8 }}
{{- end }}
restartPolicy: Never
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
backoffLimit: 1
{{- end }}
26 changes: 26 additions & 0 deletions helm/knox/templates/rbac.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{{- if .Values.serviceAccount.create -}}
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: {{ include "knox.fullname" . }}-job-status-reader
rules:
- apiGroups:
- batch
resources:
- jobs
verbs:
- get
- list
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: {{ include "knox.fullname" . }}-job-status-reader
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: {{ include "knox.fullname" . }}-job-status-reader
subjects:
- kind: ServiceAccount
name: {{ include "knox.serviceAccountName" . }}
{{- end }}
Loading

0 comments on commit 71bcc69

Please sign in to comment.