Skip to content

Commit

Permalink
feat: add missing container features. Half-baked json schema
Browse files Browse the repository at this point in the history
  • Loading branch information
Wojciech Międzybrodzki committed Jan 2, 2025
1 parent bc7a6f4 commit 01ff1b2
Show file tree
Hide file tree
Showing 7 changed files with 506 additions and 22 deletions.
2 changes: 1 addition & 1 deletion charts/app/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description: Flexible helm chart to deploy your apps to kubernetes cluster.
type: application

# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.2.1
version: 0.3.0

appVersion: 1.0.0

9 changes: 7 additions & 2 deletions charts/app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,10 @@ TODO:
- [ ] 1st working version
- [x] values-example.yaml file with all possible options used
- [ ] simple stupid test
- [ ] json schema based on values-example.yaml
- [ ] deployment.containers required
- [x] json schema based on values-example.yaml
- [ ] deployment.containers required
- use kubernetes json schema where possible:
```text
https://raw.githubusercontent.com/yannh/kubernetes-json-schema/refs/heads/master/v1.31.3/probe.json
```
76 changes: 60 additions & 16 deletions charts/app/templates/_container.tpl
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
{{- define "platformex.containerFull" }}
name: {{ .name }}
{{- include "platformex.container.volumeMounts" .container }}
{{- include "platformex.container.envFrom" . }}
{{- include "platformex.container.env" . }}
{{- include "platformex.container.image" . }}
{{- include "platformex.container.imagePullPolicy" . }}
{{- /* {{- include "platformex.deployment.command" $initContainer | indent 14 }}*/}}
{{- /* {{- include "platformex.deployment.lifecycle" $initContainer | indent 14 }}*/}}
{{- /* {{- include "platformex.deployment.ports" $initContainer | indent 14 }}*/}}
{{- /* {{- include "platformex.deployment.liveness" $initContainer | indent 14 }}*/}}
{{- /* {{- include "platformex.deployment.readiness" $initContainer | indent 14 }}*/}}
{{- /* {{- include "platformex.deployment.startup" $initContainer | indent 14 }}*/}}
{{- /* {{- include "platformex.deployment.resources" $initContainer | indent 14 }}*/}}
{{- include "platformex.container.command" . }}
{{- include "platformex.container.env" . }}
{{- include "platformex.container.envFrom" . }}
{{- include "platformex.container.volumeMounts" .container }}
{{- include "platformex.container.lifecycle" .container }}
{{- include "platformex.container.ports" .container }}
{{- include "platformex.container.probes" .container }}
{{- include "platformex.container.resources" .container }}
{{- end }}

{{- define "platformex.container.image" }}
Expand All @@ -35,14 +33,12 @@ envFrom:
imagePullPolicy: {{ .container.imagePullPolicy | default "IfNotPresent" }}
{{- end }}


{{- define "platformex.container.env" }}
env:
{{- range $name, $env := .container.env }}
- name: {{ $name }}
{{- if typeIs "string" $env }}
value: {{ $env }}
value: {{ $env }}
{{- else if hasKey $env "valueFrom" }}
valueFrom:
{{- toYaml $env.valueFrom | nindent 4 }}
Expand All @@ -56,8 +52,7 @@ env:
{{- if typeIs "string" $env }}
value: {{ $env }}
{{- else if hasKey $env "valueFrom" }}
valueFrom:
{{- toYaml $env.valueFrom | nindent 4 }}
valueFrom: {{- toYaml $env.valueFrom | nindent 4 }}
{{- end }}
{{- end }}
{{- end }}
Expand All @@ -68,7 +63,56 @@ env:
{{- if .volumeMounts }}
volumeMounts:
{{- range .volumeMounts }}
- {{- toYaml . | nindent 2 }}
- {{- toYaml . | nindent 2}}
{{- end }}
{{- end }}
{{- end }}

{{- define "platformex.container.command" }}
{{- if .container.command }}
command:
{{- range .container.command }}
- {{. | quote}}
{{- end }}
{{- end }}
{{- end }}

{{- define "platformex.container.lifecycle" }}
{{- if .lifecycle }}
lifecycle:
{{- toYaml .lifecycle | nindent 2 }}
{{- end }}
{{- end }}

{{- define "platformex.container.ports" }}
{{- if .ports }}
ports:
{{- range .ports }}
- name: {{ .name }}
containerPort: {{ .containerPort }}
protocol: {{ .protocol }}
{{- end }}
{{- end }}
{{- end }}

{{- define "platformex.container.probes" }}
{{- if .livenessProbe }}
livenessProbe:
{{- toYaml .livenessProbe | nindent 2 }}
{{- end }}
{{- if .readinessProbe }}
readinessProbe:
{{- toYaml .readinessProbe | nindent 2 }}
{{- end }}
{{- if .startupProbe }}
startupProbe:
{{- toYaml .startupProbe | nindent 2 }}
{{- end }}
{{- end }}

{{- define "platformex.container.resources" }}
{{- if .resources }}
resources:
{{- toYaml .resources | nindent 2 }}
{{- end }}
{{- end }}
{{- end }}
2 changes: 1 addition & 1 deletion charts/app/templates/_deployment.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ replicas: {{ .deployment.replicas }}
{{- else }}
replicas: 0
{{- end }}
{{- end }}
{{- end }}
35 changes: 34 additions & 1 deletion charts/app/values-example.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
global:
labels:
ops.kodzik.cloud/chart: "platformex"
defaults:
imagePullSecrets:
- "oci-kodzik"
Expand Down Expand Up @@ -34,6 +36,7 @@ instances:
containers:
xyz:
imageRef: demo
command: ["/bin/sh", "-c", "bin/console app:barize:foos"]
env:
EIP: "false"
envRefs:
Expand All @@ -51,6 +54,7 @@ instances:
replicas: 3
initContainers:
pszemek:
imageRef: demo
volumeMounts:
- mountPath: /var/lib/xyz-conf/.my.cnf
name: sum-volum
Expand All @@ -65,4 +69,33 @@ instances:
secretKeyRef:
key: password
name: app-secret
containers: [ ]
containers:
webapp:
imageRef: demo
lifecycle:
preStop:
exec:
command: [ "/bin/sh", "-c", "sleep 2" ]
resources:
requests:
cpu: "200m"
memory: "256Mi"
livenessProbe:
httpGet:
path: /
port: http
readinessProbe:
httpGet:
path: /
port: http
ports:
- name: web
containerPort: 80
protocol: TCP
envRefs:
- common
envFrom:
- configMapRef:
name: konfigmapa
env:
EIP: "false"
Loading

0 comments on commit 01ff1b2

Please sign in to comment.