Skip to content

Commit

Permalink
Add container helper template
Browse files Browse the repository at this point in the history
  • Loading branch information
htquanq committed Sep 22, 2023
1 parent c0e6883 commit a6d4038
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 3 deletions.
Binary file modified docs/helm-library-0.1.0.tgz
Binary file not shown.
6 changes: 3 additions & 3 deletions docs/index.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ apiVersion: v1
entries:
helm-library:
- apiVersion: v2
created: "2023-09-21T14:48:32.732472+07:00"
created: "2023-09-22T11:58:28.043648+07:00"
description: A common helm library
digest: dbeb5e5997b5c433accef36cab083335e28354e07e3633b7c7c4308c9b65f45e
digest: 6170f0923e3e863495614af377db0699edbcd271d6ab5890386e3ebb4f1f5c22
name: helm-library
type: library
urls:
- https://htquanq.github.io/helm-library/helm-library-0.1.0.tgz
version: 0.1.0
generated: "2023-09-21T14:48:32.731264+07:00"
generated: "2023-09-22T11:58:28.042959+07:00"
117 changes: 117 additions & 0 deletions templates/_container.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
{{- define "helm-library.probe.builder" }}
initialDelaySeconds: {{ .initialDelaySeconds | default 30 }}
periodSeconds: {{ .periodSeconds | default 10 }}
failureThreshold: {{ .failureThreshold | default 3 }}
successThreshold: {{ .successThreshold | default 3 }}
{{- if or .tcp.port .tcp.host .exec .httpGet.livenessPath .httpGet.livenessPort .grpc.service .grpc.port }}
{{- if or .tcp.port .tcp.host }}
tcpSocket:
host: {{ .tcp.host }}
port: {{ .tcp.port }}
{{- end }}
{{- if .exec }}
command: {{ .exec }}
{{- end }}
{{- if or .grpc.service .grpc.port }}
grpc:
service: {{ .grpc.service }}
port: {{ .grpc.port }}
{{- end }}
{{- if or .livenessPath .livenessPort }}
httpGet:
path: {{ .livenessPath | default "/" }}
port: {{ .livenessPort }}
{{- end }}
{{- else }}
httpGet:
path: "/"
port: 80
{{- end }}
{{- end }}

{{- define "helm-library.volumemount.builder" }}
- name: {{ required "Specify name of a volume" .name | quote }}
mountPath: {{ required "Specify mountPath, must not contain ':'" .mountPath | quote }}
readOnly: {{ .readOnly | default false }}
subPath: {{ .subPath | default "" }}
subPathExpr: {{ .subPathExpr | default "" }}
{{- end }}

{{- define "helm-library.container.env.builder" }}
{{- range . }}
{{- range $key,$val := . }}
- name: {{ $key }}
value: {{ $val | quote }}
{{- end }}
{{- end }}
{{- end }}

{{- define "helm-library.container.template" }}
{{- range . }}
- name: {{ .name }}
image: {{ .image }}
imagePullPolicy: {{ .imagePullPolicy | default "IfNotPresent" }}
{{- if .volumeMounts }}
{{- range .volumeMounts }}
{{- include "helm-library.volumemount.builder" . | indent 2}}
{{- end }}
{{- end }}
startupProbe:
{{- include "helm-library.probe.builder" .startupProbe | indent 4 }}
readinessProbe:
{{- include "helm-library.probe.builder" .readinessProbe | indent 4 }}
livenessProbe:
{{- include "helm-library.probe.builder" .livenessProbe | indent 4 }}
{{- if .workingDir }}
workingDir: {{ .workingDir }}
{{- end }}
{{- if .lifecycle }}
postStart: {{ .lifecycle.postStart }}
preStop: {{ .lifecyle.preStop }}
{{- end }}
{{- if .envFrom }}
envFrom:
{{ toYaml .envFrom | indent 2 }}
{{- end }}
{{- if .env }}
env:
{{ include "helm-library.container.env.builder" .env | indent 2 }}
{{- end }}
{{- if .command }}
command: {{ .command }}
{{- end }}
{{- if .args }}
args:
{{- toYaml .args | indent 4 }}
{{- end }}
{{- if or .limits .requests }}
resources:
{{- if .limits }}
limits:
{{- if .limits.memory }}
memory: {{ .limits.memory | quote }}
{{- end }}
{{- if .limits.cpu }}
cpu: {{ .limits.cpu | quote }}
{{- end }}
{{- end }}
{{- if .requests }}
requests:
{{- if .requests.memory }}
memory: {{ .requests.memory | quote }}
{{- end }}
{{- if .requests.cpu }}
cpu: {{ .requests.cpu | quote }}
{{- end }}
{{- end }}
{{- end }}
{{- if .ports }}
ports:
{{- range .ports }}
- containerPort: {{ .containerPort }}
protocol: {{ .protocol | upper }}
name: {{ .name }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}

0 comments on commit a6d4038

Please sign in to comment.