Skip to content

Commit

Permalink
Merge pull request #13 from devopshobbies/refactor/chart
Browse files Browse the repository at this point in the history
refactor: refactored everything in this chart
  • Loading branch information
mehdi-ra authored Jul 24, 2023
2 parents cd66940 + 9eb998a commit 1324827
Show file tree
Hide file tree
Showing 38 changed files with 3,913 additions and 550 deletions.
38 changes: 19 additions & 19 deletions Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
apiVersion: v2
name: helm-template
description: A Helm chart for Kubernetes
name: helm-generic
description: Generic helm chart for all kind of applications

# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application
version: 0.1.1

# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: "0.1.0"
keywords:
- java
- node
- dotnet
- kubernetes
- stakater
- application

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "1.16.0"
home: https://github.com/stakater/application
maintainers:
- name: Ahmad Ali Bagheri
email: [email protected]

- name: Mehdi Rahimi
email: [email protected]

icon: https://github.com/stakater/ForecastleIcons/blob/master/stakater.png
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ This chart is created to be used inside devopshobbies & kaiser-io devops operati

## How it works:

The use-case is pretty simple and you can start using this by fetching the chart. Also, there is one `values`.example.yaml` defined for you which you can check and have a look at to find out how to set the variables.
The use-case is pretty simple and you can start using this by fetching the chart. Also, there is one `values.example.yaml` defined for you which you can check and have a look at to find out how to set the variables.

## How release and versioning work:

Expand Down
27 changes: 0 additions & 27 deletions templates/NOTES.txt

This file was deleted.

196 changes: 35 additions & 161 deletions templates/_helpers.tpl
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,188 +1,62 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "helm-template.name" -}}
{{- default .Chart.Name .Values.name | trunc 63 | trimSuffix "-" }}
{{- end }}

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


{{- define "helm-template.namespace" -}}
{{- default .Values.namespace | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "helm-template.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}
{{/* vim: set filetype=mustache: */}}

{{/*
Common labels
Define the name of the chart/application.
*/}}
{{- define "helm-template.labels" -}}
helm.sh/chart: {{ include "helm-template.chart" . }}
{{ include "helm-template.selectorLabels" . }}
{{- $labellist := list -}}
{{- range $key := .Values.Affinity }}
{{- range $value := $key.values }}
{{- $label := cat $key.key ":" $value -}}
{{- if not (has $label $labellist) }}
{{ $key.key }}: {{ $value }}
{{- end }}
{{- $labellist = append $labellist $label -}}
{{- end }}
{{- end }}

app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}
{{- define "application.name" -}}
{{- default .Chart.Name .Values.applicationName | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Selector labels
Define the name of the chart/application.
*/}}

{{- define "helm-template.selectorLabels" -}}
app: {{ include "helm-template.name" . }}
{{- end }}
{{- define "application.version" -}}
{{- $version := default "" .Values.deployment.image.tag -}}
{{- regexReplaceAll "[^a-zA-Z0-9_\\.\\-]" $version "-" | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Pars Affinity
Renders a value that contains template.
Usage:
{{ include "application.tplvalues.render" ( dict "value" .Values.path.to.the.Value "context" $) }}
*/}}
{{- define "helm-template.affinity" -}}
{{- range $typelist := (list "nodeAffinity" "nodeAntiAffinity" "podAntiAffinity" "podAffinity") -}}
{{- $afflag := list 1 -}}
{{- range $rulelist := (list "required" "preferred") -}}
{{- range $Affinities := $.Values.Affinity -}}
{{- if eq $typelist $Affinities.type -}}
{{- if not (has $typelist $afflag ) -}}
{{- $typelist | nindent 0 -}}:
{{- $afflag = append $afflag $Affinities.type -}}
{{- end -}}
{{- if eq $rulelist $Affinities.rule -}}
{{- if and (not (has $Affinities.rule $afflag)) (eq $Affinities.rule "required") }}
requiredDuringSchedulingIgnoredDuringExecution:
{{- if contains "node" $Affinities.type }}
nodeSelectorTerms:
- matchExpressions:
{{- else if contains "pod" $Affinities.type }}
- labelSelector:
matchExpressions:
{{- end }}
{{- $afflag = append $afflag $Affinities.rule -}}
{{- end }}
{{- if eq $Affinities.rule "required" }}
- key: {{ $Affinities.key }}
operator: {{ $Affinities.operator }}
values:
{{- toYaml $Affinities.values | nindent 10 }}
{{- end }}
{{- if and (not (has $Affinities.rule $afflag)) (eq $Affinities.rule "preferred") }}
preferredDuringSchedulingIgnoredDuringExecution:
{{- $afflag = append $afflag $Affinities.rule -}}
{{- end }}
{{- if eq $Affinities.rule "preferred" }}
{{- if contains "node" $Affinities.type }}
- weight: {{ $Affinities.weight | default "100" }}
preference:
matchExpressions:
- key: {{ $Affinities.key }}
operator: {{ $Affinities.operator }}
values:
{{- toYaml $Affinities.values | nindent 8 }}
{{- else if contains "pod" $Affinities.type }}
- weight: {{ $Affinities.weight | default "100" }}
podAffinityTerm:
labelSelector:
matchExpressions:
- key: {{ $Affinities.key }}
operator: {{ $Affinities.operator }}
values:
{{- toYaml $Affinities.values | nindent 12 }}
{{- end }}
{{- end }}
{{- if and (contains "pod" $Affinities.type) (eq $Affinities.rule "preferred") }}
topologyKey: "kubernetes.io/hostname"
{{- $afflag = append $afflag "topology" -}}
{{- define "application.tplvalues.render" -}}
{{- if typeIs "string" .value }}
{{- tpl .value .context }}
{{- else }}
{{- tpl (.value | toYaml) .context }}
{{- end }}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}


{{/*
ENV Secret
Create chart name and version as used by the chart label.
*/}}

{{- define "helm-template.envsecrets" -}}
{{- range $key, $val := .Values.secretdata }}
- name: {{ $key | replace "." "_" | upper }}
valueFrom:
configMapKeyRef:
key: {{ $key }}
name: {{ include "helm-template.name" $ }}-secrets
{{- end }}
{{- define "application.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Secret Data
Common labels
*/}}
{{- define "helm-template.secretdata" -}}
{{- range $key, $val := .Values.secretdata }}
{{ $key | indent 2}}: {{ $val | quote }}
{{- define "application.labels" -}}
helm.sh/chart: {{ include "application.chart" . }}
{{- with include "application.version" . }}
app.kubernetes.io/version: {{ quote . }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/part-of: {{ include "application.name" . }}
{{- end }}

{{/*
Volume Mounts
Selector labels
*/}}

{{- define "helm-template.volumemount" -}}
{{- if .Values.volumes }}
volumeMounts:
{{- end }}
{{- range $vol := .Values.volumes }}
- mountPath: /opt/{{ $vol.name }}
name: {{ $vol.name }}
{{- end }}
{{- define "application.selectorLabels" -}}
app.kubernetes.io/name: {{ include "application.name" . }}
{{- end }}

{{/*
Create the name of the service account to use
Allow the release namespace to be overridden
*/}}
{{- define "helm-template.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "helm-template.name" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}


{{ define "render-value" }}
{{- if kindIs "string" .value }}
{{- tpl .value .context }}
{{- else }}
{{- tpl (.value | toYaml) .context }}
{{- end }}
{{- end }}
{{- define "application.namespace" -}}
{{- default .Release.Namespace .Values.namespaceOverride -}}
{{- end -}}
22 changes: 22 additions & 0 deletions templates/alertmanagerconfig.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{{- if and (.Values.alertmanagerConfig).enabled (.Capabilities.APIVersions.Has "monitoring.coreos.com/v1alpha1") -}}
apiVersion: monitoring.coreos.com/v1alpha1
kind: AlertmanagerConfig
metadata:
name: {{ template "application.name" . }}
namespace: {{ include "application.namespace" . }}
labels:
{{- include "application.labels" . | nindent 4 }}
{{ toYaml .Values.alertmanagerConfig.selectionLabels | indent 4 }}
spec:
{{- if .Values.alertmanagerConfig.spec.route }}
route:
{{ toYaml .Values.alertmanagerConfig.spec.route | indent 6 }}
{{- end -}}
{{- if .Values.alertmanagerConfig.spec.receivers }}
receivers:
{{ toYaml .Values.alertmanagerConfig.spec.receivers | indent 6 }}
{{- end -}}
{{- if .Values.alertmanagerConfig.spec.inhibitRules }}
inhibitRules: {{ toYaml .Values.alertmanagerConfig.spec.inhibitRules | nindent 6 }}
{{- end -}}
{{- end -}}
Loading

0 comments on commit 1324827

Please sign in to comment.