Skip to content

Commit

Permalink
Merge pull request #6 from nixys/update_v2
Browse files Browse the repository at this point in the history
Update v2
  • Loading branch information
Roman Andreev committed May 30, 2022
2 parents 8ce32fb + bff1853 commit 58c64d1
Show file tree
Hide file tree
Showing 19 changed files with 521 additions and 240 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.idea/
tmp/
test*.yml
2 changes: 1 addition & 1 deletion .helmignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
README.md
.idea/
.gitignore
.git*
tmp
*.tgz
docs/
Expand Down
37 changes: 37 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Changelog

## 2.0.0 - May 30, 2022

* feature: add HPA support
* feature: add PDB support
* using `maps` instead of `list` for declare manifests
* docs update
* samples update

## 1.0.6 - May 6, 2022

* fix nindent for `securityContext`

## 1.0.5 - May 5, 2022

* feature: add template for workloads images
* fix `securityContext` for pod and container levels
* set default protocol TCP for service port
* set default service port name
* doc update

## 1.0.4 - April 15, 2022

* fix Service nodePort

## 1.0.3 - April 12, 2022

* fix helm hooks annotations custom annotations

## 1.0.2 - April 5, 2022

* fix helm hooks annotations for PVC

## 1.0.1 - April 4, 2022

* fix servicemonitor's selector rendering
6 changes: 4 additions & 2 deletions Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
apiVersion: v2
description: Nixys universal Helm chart for deploy your apps to Kubernetes
name: universal-chart
version: 1.0.0
version: 2.0.0
maintainers:
- name: Roman Andreev
email: r.andreev@nixys.ru
- name: Anton Zhideev
email: a.zhideev@nixys.ru
email: a.zhideev@nixys.ru
- name: Evgenii Tereshkov
email: evg.krsk@gmail.com
224 changes: 169 additions & 55 deletions README.md

Large diffs are not rendered by default.

55 changes: 55 additions & 0 deletions samples/cron-jobs.values.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
cronJobs:

mailing:
affinity:
nodeAffinity: {}
podAntiAffinity: {}
podAffinity: {}
schedule: "00 05 * * *"
containers:
- command: send-mail
volumeMounts:
- mountPath: /app/issues-mailing.conf
name: config
subPath: issues-mailing.conf
volumes:
- name: config
type: secret
originalName: app-config
restartPolicy: OnFailure

flush-cache:
affinity:
nodeAffinity: {}
podAntiAffinity: {}
podAffinity: {}
schedule: "00 * * * *"
containers:
- command: flush-cache
volumeMounts:
- mountPath: /app/main.conf
name: config
subPath: main.conf
volumes:
- name: config
type: secret
originalName: app-config
restartPolicy: OnFailure

report:
affinity:
nodeAffinity: {}
podAntiAffinity: {}
podAffinity: {}
schedule: "00 2 7 * *"
containers:
- command: make-report
volumeMounts:
- mountPath: /app/main.conf
name: config
subPath: main.conf
volumes:
- name: config
type: secret
originalName: app-config
restartPolicy: OnFailure
32 changes: 13 additions & 19 deletions samples/web-app.values.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
releasePrefix: "-"

# --set "envs.BAR=foo,envs.TEST=true"
envs:
BAR: foo
Expand Down Expand Up @@ -141,22 +143,14 @@ pvcs:
# foo: foo

hooks:
- name: migration-up
kind: "pre-install,pre-upgrade"
weight: "5"
deletePolicy: "before-hook-creation"
affinity:
nodeAffinity: {}
podAntiAffinity: {}
podAffinity: {}
containers:
- name: migration-up
image: registry.app.ru/app-migration
nodeSelector:
kind: infrastructure-apps
args:
- migrate
- up
envFrom:
- secretRef:
name: nixy-server-env
migration-up:
containers:
- image: registry.app.ru/app-migration
nodeSelector:
kind: infrastructure-apps
args:
- migrate
- up
envFrom:
- secretRef:
name: server-env
68 changes: 34 additions & 34 deletions templates/cronjob.yml
Original file line number Diff line number Diff line change
@@ -1,36 +1,13 @@
{{- $CJ := list -}}
{{- if .Values.cronJobs -}}
{{- $general := $.Values.cronJobsGeneral -}}
{{- $cronJobs := list -}}
{{- if kindIs "string" .Values.cronJobs -}}
{{- $CJ = fromYaml (printf "cronJobs:\n%s" .Values.cronJobs) -}}
{{- else if kindIs "slice" .Values.cronJobs -}}
{{- $CJ = .Values.cronJobs -}}
{{- $cronJobs = fromYaml .Values.cronJobs -}}
{{- else if kindIs "map" .Values.cronJobs -}}
{{- $cronJobs = .Values.cronJobs -}}
{{- end -}}
{{- $general := $.Values.cronJobsGeneral -}}
{{- range $i, $job := $CJ }}
{{- $cjName := include "helpers.app.fullname" (dict "name" .name "context" $) }}
{{- if .commandDurationAlert }}
---
apiVersion: monitoring.coreos.com/v1
kind: PrometheusRule
metadata:
name: cronjob-{{ $cjName }}
labels:
prometheus: k8s
role: alert-rules
namespace: nxs-monitoring
spec:
groups:
- name: "cronJobs_rules"
interval: 1m # period check for alerts
rules:
- alert: "cronjob-{{ $cjName }}-too-long-execution"
expr: '((time() - kube_job_status_start_time{namespace="{{ $.Release.Namespace }}", job_name=~"{{ $cjName }}-.*"}) and kube_job_status_active{namespace="{{ $.Release.Namespace }}", job_name=~"{{ $cjName }}-.*"} == 1) > {{ .commandDurationAlert }}'
for: 3m
labels:
severity: warning
annotations:
message: "CronJob {{ $.Release.Namespace }}/{{ $cjName }} is taking more than {{ .commandDurationAlert }} to complete"
{{- end }}
{{- range $name, $job := $cronJobs }}
{{- $cjName := include "helpers.app.fullname" (dict "name" $name "context" $) }}
---
apiVersion: {{ include "helpers.capabilities.cronJob.apiVersion" $ }}
kind: CronJob
Expand Down Expand Up @@ -153,12 +130,12 @@ spec:
{{- with .securityContext }}
securityContext: {{- include "helpers.tplvalues.render" ( dict "value" . "context" $) | nindent 14 }}
{{- end }}
{{- if $.Values.diagnosticMode.enbled }}
{{- if $.Values.diagnosticMode.enabled }}
args: {{- include "helpers.tplvalues.render" ( dict "value" $.Values.diagnosticMode.args "context" $) | nindent 12 }}
{{- else if and .args (not $job.commandMaxDuration) }}
args: {{- include "helpers.tplvalues.render" ( dict "value" .args "context" $) | nindent 12 }}
{{- end }}
{{- if $.Values.diagnosticMode.enbled }}
{{- if $.Values.diagnosticMode.enabled }}
command: {{- include "helpers.tplvalues.render" ( dict "value" $.Values.diagnosticMode.command "context" $) | nindent 12 }}
{{- else if .command }}
{{- if $job.commandMaxDuration }}
Expand Down Expand Up @@ -201,12 +178,12 @@ spec:
{{- with .securityContext }}
securityContext: {{- include "helpers.tplvalues.render" ( dict "value" . "context" $) | nindent 14 }}
{{- end }}
{{- if $.Values.diagnosticMode.enbled }}
{{- if $.Values.diagnosticMode.enabled }}
args: {{- include "helpers.tplvalues.render" ( dict "value" $.Values.diagnosticMode.args "context" $) | nindent 12 }}
{{- else if and .args (not $job.commandMaxDuration) }}
args: {{- include "helpers.tplvalues.render" ( dict "value" .args "context" $) | nindent 12 }}
{{- end }}
{{- if $.Values.diagnosticMode.enbled }}
{{- if $.Values.diagnosticMode.enabled }}
command: {{- include "helpers.tplvalues.render" ( dict "value" $.Values.diagnosticMode.command "context" $) | nindent 12 }}
{{- else if .command }}
{{- if $job.commandMaxDuration }}
Expand Down Expand Up @@ -239,5 +216,28 @@ spec:
{{- end }}
volumes: {{- include "helpers.volumes.renderVolume" (dict "value" . "general" $general "context" $) | indent 10}}
restartPolicy: {{ .restartPolicy | default "Never" }}
{{- if .commandDurationAlert }}
---
apiVersion: monitoring.coreos.com/v1
kind: PrometheusRule
metadata:
name: cronjob-{{ $cjName }}
labels:
prometheus: k8s
role: alert-rules
namespace: nxs-monitoring
spec:
groups:
- name: "cronJobs_rules"
interval: 1m # period check for alerts
rules:
- alert: "cronjob-{{ $cjName }}-too-long-execution"
expr: '((time() - kube_job_status_start_time{namespace="{{ $.Release.Namespace }}", job_name=~"{{ $cjName }}-.*"}) and kube_job_status_active{namespace="{{ $.Release.Namespace }}", job_name=~"{{ $cjName }}-.*"} == 1) > {{ .commandDurationAlert }}'
for: 3m
labels:
severity: warning
annotations:
message: "CronJob {{ $.Release.Namespace }}/{{ $cjName }} is taking more than {{ .commandDurationAlert }} to complete"
{{- end }}
{{- end }}
{{- end }}
8 changes: 4 additions & 4 deletions templates/deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ spec:
{{- with .securityContext }}
securityContext: {{- include "helpers.tplvalues.render" ( dict "value" . "context" $) | nindent 10 }}
{{- end }}
{{- if $.Values.diagnosticMode.enbled }}
{{- if $.Values.diagnosticMode.enabled }}
args: {{- include "helpers.tplvalues.render" ( dict "value" $.Values.diagnosticMode.args "context" $) | nindent 8 }}
{{- else if .args }}
args: {{- include "helpers.tplvalues.render" ( dict "value" .args "context" $) | nindent 8 }}
{{- end }}
{{- if $.Values.diagnosticMode.enbled }}
{{- if $.Values.diagnosticMode.enabled }}
command: {{- include "helpers.tplvalues.render" ( dict "value" $.Values.diagnosticMode.command "context" $) | nindent 8 }}
{{- else if .command }}
{{- if typeIs "string" .command }}
Expand Down Expand Up @@ -130,12 +130,12 @@ spec:
{{- with .securityContext }}
securityContext: {{- include "helpers.tplvalues.render" ( dict "value" . "context" $) | nindent 10 }}
{{- end }}
{{- if $.Values.diagnosticMode.enbled }}
{{- if $.Values.diagnosticMode.enabled }}
args: {{- include "helpers.tplvalues.render" ( dict "value" $.Values.diagnosticMode.args "context" $) | nindent 8 }}
{{- else if .args }}
args: {{- include "helpers.tplvalues.render" ( dict "value" .args "context" $) | nindent 8 }}
{{- end }}
{{- if $.Values.diagnosticMode.enbled }}
{{- if $.Values.diagnosticMode.enabled }}
command: {{- include "helpers.tplvalues.render" ( dict "value" $.Values.diagnosticMode.command "context" $) | nindent 8 }}
{{- else if .command }}
{{- if typeIs "string" .command }}
Expand Down
4 changes: 2 additions & 2 deletions templates/extra.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- range .Values.extraDeploy }}
{{- range $key, $val := .Values.extraDeploy }}
---
{{ include "helpers.tplvalues.render" (dict "value" . "context" $) }}
{{ include "helpers.tplvalues.render" (dict "value" $val "context" $) }}
{{- end }}
23 changes: 11 additions & 12 deletions templates/helm-hooks.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
{{- $hooks := list -}}
{{- if .Values.hooks -}}
{{- $general := $.Values.hooksGeneral -}}
{{- $hooks := list -}}
{{- if kindIs "string" .Values.hooks -}}
{{- $HD := fromYaml (printf "hooks:\n%s" .Values.hooks) -}}
{{- $hooks = $HD.hooks -}}
{{- else if kindIs "slice" .Values.hooks -}}
{{- $hooks = fromYaml .Values.hooks -}}
{{- else if kindIs "map" .Values.hooks -}}
{{- $hooks = .Values.hooks -}}
{{- end -}}
{{- end -}}
{{- $general := $.Values.hooksGeneral -}}
{{- range $hooks }}
{{- $hookName := include "helpers.app.fullname" (dict "name" .name "context" $) }}
{{- range $name, $hook := $hooks }}
{{- $hookName := include "helpers.app.fullname" (dict "name" $name "context" $) }}
---
apiVersion: batch/v1
kind: Job
Expand Down Expand Up @@ -114,12 +112,12 @@ spec:
{{- with .securityContext }}
securityContext: {{- include "helpers.tplvalues.render" ( dict "value" . "context" $) | nindent 8 }}
{{- end }}
{{- if $.Values.diagnosticMode.enbled }}
{{- if $.Values.diagnosticMode.enabled }}
args: {{- include "helpers.tplvalues.render" ( dict "value" $.Values.diagnosticMode.args "context" $) | nindent 8 }}
{{- else if .args }}
args: {{- include "helpers.tplvalues.render" ( dict "value" .args "context" $) | nindent 8 }}
{{- end }}
{{- if $.Values.diagnosticMode.enbled }}
{{- if $.Values.diagnosticMode.enabled }}
command: {{- include "helpers.tplvalues.render" ( dict "value" $.Values.diagnosticMode.command "context" $) | nindent 8 }}
{{- else if .command }}
{{- if typeIs "string" .command }}
Expand Down Expand Up @@ -159,12 +157,12 @@ spec:
{{- with .securityContext }}
securityContext: {{- include "helpers.tplvalues.render" ( dict "value" . "context" $) | nindent 8 }}
{{- end }}
{{- if $.Values.diagnosticMode.enbled }}
{{- if $.Values.diagnosticMode.enabled }}
args: {{- include "helpers.tplvalues.render" ( dict "value" $.Values.diagnosticMode.args "context" $) | nindent 8 }}
{{- else if .args }}
args: {{- include "helpers.tplvalues.render" ( dict "value" .args "context" $) | nindent 8 }}
{{- end }}
{{- if $.Values.diagnosticMode.enbled }}
{{- if $.Values.diagnosticMode.enabled }}
command: {{- include "helpers.tplvalues.render" ( dict "value" $.Values.diagnosticMode.command "context" $) | nindent 8 }}
{{- else if .command }}
{{- if typeIs "string" .command }}
Expand Down Expand Up @@ -194,4 +192,5 @@ spec:
{{- end }}
volumes: {{- include "helpers.volumes.renderVolume" (dict "value" . "general" $general "context" $) | indent 6}}
restartPolicy: {{ .restartPolicy | default "Never" }}
{{- end -}}
{{- end -}}
8 changes: 8 additions & 0 deletions templates/helpers/_capabilities.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,11 @@
{{- print "networking.k8s.io/v1" -}}
{{- end }}
{{- end -}}

{{- define "helpers.capabilities.pdb.apiVersion" -}}
{{- if semverCompare "<1.21-0" (include "helpers.capabilities.kubeVersion" $) -}}
{{- print "policy/v1beta1" -}}
{{- else -}}
{{- print "policy/v1" -}}
{{- end -}}
{{- end -}}
2 changes: 1 addition & 1 deletion templates/helpers/_configmaps.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{{- end -}}
{{- range $key, $value := $v }}
{{- if eq (typeOf $value) "float64" }}
{{ printf "%s: %s" $key (toString $value) }}
{{ printf "%s: %s" $key (toString $value | quote) }}
{{- else if empty $value }}
{{ printf "%s: %s" $key ("" | quote) }}
{{- else if kindIs "string" $value }}
Expand Down
Loading

0 comments on commit 58c64d1

Please sign in to comment.