Skip to content

Commit

Permalink
Bootstrap Helm chart (#3)
Browse files Browse the repository at this point in the history
Co-authored-by: Kai Ren <tyranron@gmail.com>
  • Loading branch information
xDarksome and tyranron authored Jul 8, 2022
1 parent f6133ad commit 00d90bd
Show file tree
Hide file tree
Showing 14 changed files with 581 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,11 @@ max_line_length = off
indent_style = space
indent_size = 4

[Makefile]
indent_style = tab
indent_size = 4

[Dockerfile]
indent_style = space
indent_size = 4

10 changes: 10 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ jobs:
needs:
- clippy
- docker
- helm-lint
- rustdoc
- rustfmt
- test-e2e
Expand Down Expand Up @@ -61,6 +62,15 @@ jobs:

- run: make cargo.lint

helm-lint:
name: Lint Helm chart
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: azure/setup-helm@v3

- run: make helm.lint

rustfmt:
runs-on: ubuntu-latest
steps:
Expand Down
18 changes: 18 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -279,11 +279,29 @@ docker.untar:



#################
# Helm commands #
#################

helm-chart-dir := helm/baza

# Lint project Helm chart.
#
# Usage:
# make helm.lint

helm.lint:
helm lint $(helm-chart-dir)/




##################
# .PHONY section #
##################

.PHONY: all docs down fmt image lint test up \
cargo.doc cargo.fmt cargo.lint \
docker.image docker.tags docker.push docker.tar docker.untar \
helm.lint \
test.e2e test.unit
3 changes: 3 additions & 0 deletions helm/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[*.tpl]
indent_style = space
indent_size = 2
1 change: 1 addition & 0 deletions helm/baza/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.DS_Store
4 changes: 4 additions & 0 deletions helm/baza/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: v2
name: baza
version: 0.0.0-edge
type: application
15 changes: 15 additions & 0 deletions helm/baza/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Baza can be accessed via these URLs inside your cluster:
{{- if $.Values.nginx.enabled }}
Nginx: http://{{ include "baza.fullname" . }}.{{ .Release.Namespace }}.svc.cluster.local:{{ .Values.nginx.port | int }}/
{{- end }}
S3 API: http://{{ include "baza.fullname" . }}.{{ .Release.Namespace }}.svc.cluster.local:{{ .Values.conf.port | int }}/

{{- if .Values.ingress.enabled }}{{ "\n" }}
Baza can be accessed via these URLs outside your cluster:
{{- range .Values.ingress.hosts }}
{{- if $.Values.nginx.enabled }}
Nginx: http{{ if $.Values.ingress.tls.enabled }}s{{ end }}://{{ . }}{{ $.Values.ingress.subPath | trimSuffix "/" }}/
{{- end }}
S3 API: http{{ if $.Values.ingress.tls.enabled }}s{{ end }}://{{ . }}{{ $.Values.ingress.subPath | trimSuffix "/" }}/s3/
{{- end }}
{{- end }}
32 changes: 32 additions & 0 deletions helm/baza/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "baza.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 55 | trimSuffix "-" -}}
{{- end -}}

{{/*
Create a default fully qualified app name.
We truncate at 55 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 "baza.fullname" -}}
{{- if .Values.fullnameOverride -}}
{{- .Values.fullnameOverride | trunc 55 | trimSuffix "-" -}}
{{- else -}}
{{- $name := default .Chart.Name .Values.nameOverride -}}
{{- if contains $name .Release.Name -}}
{{- .Release.Name | trunc 55 | trimSuffix "-" -}}
{{- else -}}
{{- printf "%s-%s" .Release.Name $name | trunc 55 | trimSuffix "-" -}}
{{- end -}}
{{- end -}}
{{- end -}}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "baza.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 55 | trimSuffix "-" -}}
{{- end -}}
28 changes: 28 additions & 0 deletions helm/baza/templates/configmap.nginx.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{{- if .Values.nginx.enabled }}
kind: ConfigMap
apiVersion: v1
metadata:
name: {{ printf "%s.nginx.conf" (include "baza.fullname" .) | quote }}
namespace: {{ .Release.Namespace | quote }}
labels:
helm.sh/chart: {{ include "baza.chart" . | quote }}
app.kubernetes.io/name: {{ include "baza.name" . | quote }}
app.kubernetes.io/instance: {{ .Release.Name | quote }}
app.kubernetes.io/managed-by: {{ .Release.Service | quote }}
{{- with .Values.labels }}
{{- toYaml . | nindent 4 }}
{{- end }}
data:
{{- with .Values.nginx.conf }}
nginx.conf: |
{{- . | nindent 4 }}
{{- end }}
{{- if index .Values.nginx "conf.d" }}
{{- range $file := slice (keys (index .Values.nginx "conf.d") | sortAlpha) }}
{{- with index $.Values.nginx "conf.d" $file }}
{{ printf "conf.d__%s" $file | quote }}: |
{{- . | nindent 4 }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
63 changes: 63 additions & 0 deletions helm/baza/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{{- if .Values.ingress.enabled }}
{{- range $host := .Values.ingress.hosts }}
---
kind: Ingress
apiVersion: networking.k8s.io/v1
metadata:
name: {{ printf "%s.%s" (include "baza.fullname" $) $host | quote }}
namespace: {{ $.Release.Namespace | quote }}
labels:
helm.sh/chart: {{ include "baza.chart" $ | quote }}
app.kubernetes.io/name: {{ include "baza.name" $ | quote }}
app.kubernetes.io/instance: {{ $.Release.Name | quote }}
app.kubernetes.io/managed-by: {{ $.Release.Service | quote }}
{{- with $.Values.labels }}
{{- toYaml . | nindent 4 }}
{{- end }}
annotations:
{{- if and $.Values.ingress.tls.enabled $.Values.ingress.tls.auto }}
kubernetes.io/tls-acme: "true"
{{- end }}
{{- if not $.Values.ingress.tls.enabled }}
nginx.ingress.kubernetes.io/ssl-redirect: "false"
{{- end }}
nginx.ingress.kubernetes.io/rewrite-target: /$1
{{- with $.Values.ingress.annotations }}
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
rules:
{{- range $h := list $host (printf "www.%s" $host) }}
- host: {{ $h | quote }}
http:
paths:
- path: {{ $.Values.ingress.subPath | trimSuffix "/" }}/s3/(.*)
pathType: ImplementationSpecific
backend:
service:
name: {{ include "baza.fullname" $ | quote }}
port:
name: s3
{{- if $.Values.nginx.enabled }}
- path: {{ $.Values.ingress.subPath | trimSuffix "/" }}/(.*)
pathType: ImplementationSpecific
backend:
service:
name: {{ include "baza.fullname" $ | quote }}
port:
name: http
{{- end }}
{{- end }}
{{- if $.Values.ingress.tls.enabled }}
tls:
- secretName: {{ if $.Values.ingress.tls.auto -}}
{{ printf "%s.tls" ($host | trunc 48 | trimSuffix ".") | quote }}
{{- else -}}
{{ required (print `TLS Secret name must be specified for host ` $host ` !`) (index $.Values.ingress.tls.secretName $host) | quote }}
{{- end }}
hosts:
- {{ $host | quote }}
- {{ printf "www.%s" $host | quote }}
{{- end }}
{{- end }}
{{- end }}
29 changes: 29 additions & 0 deletions helm/baza/templates/pvc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{{- if .Values.data.persistentVolume.enabled }}
{{- if not .Values.data.persistentVolume.existingClaim }}
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: {{ include "baza.fullname" . | quote }}
namespace: {{ .Release.Namespace | quote }}
labels:
helm.sh/chart: {{ include "baza.chart" . | quote }}
app.kubernetes.io/name: {{ include "baza.name" . | quote }}
app.kubernetes.io/instance: {{ .Release.Name | quote }}
app.kubernetes.io/managed-by: {{ .Release.Service | quote }}
{{- with .Values.data.persistentVolume.annotations }}
annotations: {{- toYaml . | nindent 4 }}
{{- end }}
spec:
accessModes: {{- toYaml .Values.data.persistentVolume.accessModes | nindent 4 }}
{{- if .Values.data.persistentVolume.storageClass }}
{{- if (eq "-" .Values.data.persistentVolume.storageClass) }}
storageClassName: ""
{{- else }}
storageClassName: {{ .Values.data.persistentVolume.storageClass | quote }}
{{- end }}
{{- end }}
resources:
requests:
storage: {{ .Values.data.persistentVolume.size | quote }}
{{- end }}
{{- end }}
64 changes: 64 additions & 0 deletions helm/baza/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
kind: Service
apiVersion: v1
metadata:
name: {{ include "baza.fullname" . | quote }}
namespace: {{ .Release.Namespace | quote }}
labels:
helm.sh/chart: {{ include "baza.chart" . | quote }}
app.kubernetes.io/name: {{ include "baza.name" . | quote }}
app.kubernetes.io/instance: {{ .Release.Name | quote }}
app.kubernetes.io/managed-by: {{ .Release.Service | quote }}
{{- with .Values.labels }}
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
type: ClusterIP
clusterIP: None
selector:
app.kubernetes.io/name: {{ include "baza.name" . | quote }}
app.kubernetes.io/instance: {{ .Release.Name | quote }}
ports:
{{- if .Values.nginx.enabled }}
- name: http
port: {{ .Values.nginx.port | int }}
targetPort: http
protocol: TCP
{{- end }}
- name: s3
port: {{ .Values.conf.port | int }}
targetPort: s3
protocol: TCP

{{- range $n := until (.Values.statefulset.replicas | int) }}
---
kind: Service
apiVersion: v1
metadata:
name: {{ printf "%s-%d" (include "baza.fullname" $) $n | quote }}
namespace: {{ $.Release.Namespace | quote }}
labels:
helm.sh/chart: {{ include "baza.chart" $ | quote }}
app.kubernetes.io/name: {{ include "baza.name" $ | quote }}
app.kubernetes.io/instance: {{ $.Release.Name | quote }}
app.kubernetes.io/managed-by: {{ $.Release.Service | quote }}
{{- with $.Values.labels }}
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
type: ClusterIP
selector:
app.kubernetes.io/name: {{ include "baza.name" $ | quote }}
app.kubernetes.io/instance: {{ $.Release.Name | quote }}
statefulset.kubernetes.io/pod-name: {{ printf "%s-%d" (include "baza.fullname" $) $n | quote }}
ports:
{{- if $.Values.nginx.enabled }}
- name: http
port: {{ $.Values.nginx.port | int }}
targetPort: http
protocol: TCP
{{- end }}
- name: s3
port: {{ $.Values.conf.port | int }}
targetPort: s3
protocol: TCP
{{- end }}
Loading

0 comments on commit 00d90bd

Please sign in to comment.