Skip to content

Commit 0a55189

Browse files
committed
initial version of rails-application chart
1 parent 31374de commit 0a55189

11 files changed

+455
-0
lines changed

charts/rails-application/.helmignore

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Patterns to ignore when building packages.
2+
# This supports shell glob matching, relative path matching, and
3+
# negation (prefixed with !). Only one pattern per line.
4+
.DS_Store
5+
# Common VCS dirs
6+
.git/
7+
.gitignore
8+
.bzr/
9+
.bzrignore
10+
.hg/
11+
.hgignore
12+
.svn/
13+
# Common backup files
14+
*.swp
15+
*.bak
16+
*.tmp
17+
*.orig
18+
*~
19+
# Various IDEs
20+
.project
21+
.idea/
22+
*.tmproj
23+
.vscode/

charts/rails-application/Chart.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
apiVersion: v2
2+
name: rails-application
3+
description: Base chart for my rails applications
4+
type: application
5+
version: "0.1.0-alpha1"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{{/*
2+
Expand the name of the chart.
3+
*/}}
4+
{{- define "rails-application.name" -}}
5+
{{- default .Values.name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
6+
{{- end }}
7+
8+
{{/*
9+
Create a default fully qualified app name.
10+
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
11+
If release name contains chart name it will be used as a full name.
12+
*/}}
13+
{{- define "rails-application.fullname" -}}
14+
{{- if .Values.fullnameOverride }}
15+
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
16+
{{- else }}
17+
{{- $name := default .Values.name .Values.nameOverride }}
18+
{{- if contains $name .Release.Name }}
19+
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
20+
{{- else }}
21+
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
22+
{{- end }}
23+
{{- end }}
24+
{{- end }}
25+
26+
{{/*
27+
Create chart name and version as used by the chart label.
28+
*/}}
29+
{{- define "rails-application.chart" -}}
30+
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
31+
{{- end }}
32+
33+
{{/*
34+
Common labels
35+
*/}}
36+
{{- define "rails-application.labels" -}}
37+
helm.sh/chart: {{ include "rails-application.chart" . }}
38+
{{ include "rails-application.selectorLabels" . }}
39+
{{- if .Values.version }}
40+
app.kubernetes.io/version: {{ .Values.version | quote }}
41+
{{- end }}
42+
app.kubernetes.io/managed-by: {{ .Release.Service }}
43+
{{- end }}
44+
45+
{{/*
46+
Selector labels
47+
*/}}
48+
{{- define "rails-application.selectorLabels" -}}
49+
app.kubernetes.io/name: {{ include "rails-application.name" . }}
50+
app.kubernetes.io/instance: {{ .Release.Name }}
51+
{{- end }}
52+
53+
{{/*
54+
Create the name of the service account to use
55+
*/}}
56+
{{- define "rails-application.serviceAccountName" -}}
57+
{{- if .Values.serviceAccount.create }}
58+
{{- default (include "rails-application.fullname" .) .Values.serviceAccount.name }}
59+
{{- else }}
60+
{{- default "default" .Values.serviceAccount.name }}
61+
{{- end }}
62+
{{- end }}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: {{ include "rails-application.fullname" . }}
5+
namespace: {{ .Release.Namespace }}
6+
labels:
7+
{{- include "rails-application.labels" . | nindent 4 }}
8+
data:
9+
{{- range $key, $value := .Values.environment.plain }}
10+
{{ $key }}: {{ $value | quote }}
11+
{{- end -}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
{{- range $deploymentName, $deploymentValues := .Values.deployments }}
2+
apiVersion: apps/v1
3+
kind: Deployment
4+
metadata:
5+
name: {{ printf "%s-%s" (include "rails-application.fullname" $) $deploymentName }}
6+
labels:
7+
{{- include "rails-application.labels" $ | nindent 4 }}
8+
spec:
9+
{{- if not $.Values.autoscaling.enabled }}
10+
replicas: {{ $deploymentValues.replicaCount }}
11+
{{- end }}
12+
selector:
13+
matchLabels:
14+
{{- include "rails-application.selectorLabels" $ | nindent 6 }}
15+
template:
16+
metadata:
17+
{{- with $.Values.podAnnotations }}
18+
annotations:
19+
{{- toYaml . | nindent 8 }}
20+
{{- end }}
21+
labels:
22+
"k8s.klaus-meyer.net/deployment-type": {{ $deploymentName }}
23+
{{- include "rails-application.labels" $ | nindent 8 }}
24+
{{- with $.Values.podLabels }}
25+
{{- toYaml . | nindent 8 }}
26+
{{- end }}
27+
spec:
28+
{{- with $.Values.imagePullSecrets }}
29+
imagePullSecrets:
30+
{{- toYaml . | nindent 8 }}
31+
{{- end }}
32+
serviceAccountName: {{ include "rails-application.serviceAccountName" $ }}
33+
securityContext:
34+
{{- toYaml $.Values.podSecurityContext | nindent 8 }}
35+
containers:
36+
- name: {{ printf "%s-%s" (include "rails-application.fullname" $) $deploymentName }}
37+
securityContext:
38+
{{- toYaml $.Values.securityContext | nindent 12 }}
39+
image: "{{ $.Values.image.repository }}:{{ $.Values.image.tag | default $.Values.version }}"
40+
imagePullPolicy: {{ $.Values.image.pullPolicy }}
41+
args: ["{{ $deploymentName }}"]
42+
envFrom:
43+
- configMapRef:
44+
name: {{ include "rails-application.fullname" $ }}
45+
- secretRef:
46+
name: {{ include "rails-application.fullname" $ }}
47+
{{- if $deploymentValues.ports }}
48+
{{- with $deploymentValues.ports }}
49+
ports:
50+
{{- toYaml . | nindent 12 }}
51+
{{- end }}
52+
{{- end }}
53+
{{- if $deploymentValues.livenessProbe }}
54+
livenessProbe:
55+
{{- toYaml $deploymentValues.livenessProbe | nindent 12 }}
56+
{{- end -}}
57+
{{- if $deploymentValues.readinessProbe }}
58+
readinessProbe:
59+
{{- toYaml $deploymentValues.readinessProbe | nindent 12 }}
60+
{{ end }}
61+
resources:
62+
{{- toYaml $.Values.resources | nindent 12 }}
63+
{{- with $.Values.volumeMounts }}
64+
volumeMounts:
65+
{{- toYaml . | nindent 12 }}
66+
{{- end }}
67+
{{- with $.Values.volumes }}
68+
volumes:
69+
{{- toYaml . | nindent 8 }}
70+
{{- end }}
71+
{{- with $.Values.nodeSelector }}
72+
nodeSelector:
73+
{{- toYaml . | nindent 8 }}
74+
{{- end }}
75+
{{- with $.Values.affinity }}
76+
affinity:
77+
{{- toYaml . | nindent 8 }}
78+
{{- end }}
79+
{{- with $.Values.tolerations }}
80+
tolerations:
81+
{{- toYaml . | nindent 8 }}
82+
{{- end }}
83+
---
84+
{{- end }}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{{- if .Values.autoscaling.enabled }}
2+
apiVersion: autoscaling/v2
3+
kind: HorizontalPodAutoscaler
4+
metadata:
5+
name: {{ include "rails-application.fullname" . }}
6+
labels:
7+
{{- include "rails-application.labels" . | nindent 4 }}
8+
spec:
9+
scaleTargetRef:
10+
apiVersion: apps/v1
11+
kind: Deployment
12+
name: {{ include "rails-application.fullname" . }}
13+
minReplicas: {{ .Values.autoscaling.minReplicas }}
14+
maxReplicas: {{ .Values.autoscaling.maxReplicas }}
15+
metrics:
16+
{{- if .Values.autoscaling.targetCPUUtilizationPercentage }}
17+
- type: Resource
18+
resource:
19+
name: cpu
20+
target:
21+
type: Utilization
22+
averageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }}
23+
{{- end }}
24+
{{- if .Values.autoscaling.targetMemoryUtilizationPercentage }}
25+
- type: Resource
26+
resource:
27+
name: memory
28+
target:
29+
type: Utilization
30+
averageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }}
31+
{{- end }}
32+
{{- end }}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{{- if .Values.ingress.enabled -}}
2+
{{- $fullName := include "rails-application.fullname" . -}}
3+
{{- $svcName := printf "%s-%s" $fullName "web" -}}
4+
{{- $svcPort := .Values.service.port -}}
5+
{{- if and .Values.ingress.className (not (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion)) }}
6+
{{- if not (hasKey .Values.ingress.annotations "kubernetes.io/ingress.class") }}
7+
{{- $_ := set .Values.ingress.annotations "kubernetes.io/ingress.class" .Values.ingress.className}}
8+
{{- end }}
9+
{{- end }}
10+
{{- if semverCompare ">=1.19-0" .Capabilities.KubeVersion.GitVersion -}}
11+
apiVersion: networking.k8s.io/v1
12+
{{- else if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}}
13+
apiVersion: networking.k8s.io/v1beta1
14+
{{- else -}}
15+
apiVersion: extensions/v1beta1
16+
{{- end }}
17+
kind: Ingress
18+
metadata:
19+
name: {{ $fullName }}
20+
labels:
21+
{{- include "rails-application.labels" . | nindent 4 }}
22+
{{- with .Values.ingress.annotations }}
23+
annotations:
24+
{{- toYaml . | nindent 4 }}
25+
{{- end }}
26+
spec:
27+
{{- if and .Values.ingress.className (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion) }}
28+
ingressClassName: {{ .Values.ingress.className }}
29+
{{- end }}
30+
{{- if .Values.ingress.tls }}
31+
tls:
32+
{{- range .Values.ingress.tls }}
33+
- hosts:
34+
{{- range .hosts }}
35+
- {{ . | quote }}
36+
{{- end }}
37+
secretName: {{ .secretName }}
38+
{{- end }}
39+
{{- end }}
40+
rules:
41+
{{- range .Values.ingress.hosts }}
42+
- host: {{ .host | quote }}
43+
http:
44+
paths:
45+
{{- range .paths }}
46+
- path: {{ .path }}
47+
{{- if and .pathType (semverCompare ">=1.18-0" $.Capabilities.KubeVersion.GitVersion) }}
48+
pathType: {{ .pathType }}
49+
{{- end }}
50+
backend:
51+
{{- if semverCompare ">=1.19-0" $.Capabilities.KubeVersion.GitVersion }}
52+
service:
53+
name: {{ $svcName }}
54+
port:
55+
number: {{ $svcPort }}
56+
{{- else }}
57+
serviceName: {{ $svcName }}
58+
servicePort: {{ $svcPort }}
59+
{{- end }}
60+
{{- end }}
61+
{{- end }}
62+
{{- end }}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{{ if .Values.environment.sealedSecrets }}
2+
apiVersion: bitnami.com/v1alpha1
3+
kind: SealedSecret
4+
metadata:
5+
name: {{ include "rails-application.fullname" . }}
6+
namespace: {{ .Release.Namespace }}
7+
annotations:
8+
sealedsecrets.bitnami.com/namespace-wide: "true"
9+
labels:
10+
{{- include "rails-application.labels" . | nindent 4 }}
11+
spec:
12+
encryptedData:
13+
{{- range $key, $value := .Values.environment.secret }}
14+
{{ $key }}: {{ $value | quote }}
15+
{{- end -}}
16+
{{ else }}
17+
apiVersion: v1
18+
kind: Secret
19+
metadata:
20+
name: {{ include "rails-application.fullname" . }}
21+
namespace: {{ .Release.Namespace }}
22+
labels:
23+
{{- include "rails-application.labels" . | nindent 4 }}
24+
type: Opaque
25+
data:
26+
{{- range $key, $value := .Values.environment.secret }}
27+
{{ $key }}: {{ $value | b64enc | quote }}
28+
{{- end -}}
29+
{{ end }}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: {{ include "rails-application.fullname" . }}-web
5+
labels:
6+
{{- include "rails-application.labels" . | nindent 4 }}
7+
spec:
8+
type: {{ .Values.service.type }}
9+
ports:
10+
- port: {{ .Values.service.port }}
11+
targetPort: http
12+
protocol: TCP
13+
name: http
14+
selector:
15+
k8s.klaus-meyer.net/deployment-type: web
16+
{{- include "rails-application.selectorLabels" . | nindent 4 }}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{{- if .Values.serviceAccount.create -}}
2+
apiVersion: v1
3+
kind: ServiceAccount
4+
metadata:
5+
name: {{ include "rails-application.serviceAccountName" . }}
6+
labels:
7+
{{- include "rails-application.labels" . | nindent 4 }}
8+
{{- with .Values.serviceAccount.annotations }}
9+
annotations:
10+
{{- toYaml . | nindent 4 }}
11+
{{- end }}
12+
automountServiceAccountToken: {{ .Values.serviceAccount.automount }}
13+
{{- end }}

0 commit comments

Comments
 (0)