Skip to content
This repository has been archived by the owner on May 16, 2023. It is now read-only.

Prefixed helper functions with chart name #407

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion elasticsearch/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
1. Watch all cluster members come up.
$ kubectl get pods --namespace={{ .Release.Namespace }} -l app={{ template "uname" . }} -w
$ kubectl get pods --namespace={{ .Release.Namespace }} -l app={{ template "elasticsearch.uname" . }} -w
2. Test cluster health using Helm test.
$ helm test {{ .Release.Name }}
12 changes: 6 additions & 6 deletions elasticsearch/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,40 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "name" -}}
{{- define "elasticsearch.name" -}}
{{- default .Chart.Name .Values.nameOverride | 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).
*/}}
{{- define "fullname" -}}
{{- define "elasticsearch.fullname" -}}
{{- $name := default .Chart.Name .Values.nameOverride -}}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{- define "uname" -}}
{{- define "elasticsearch.uname" -}}
{{ .Values.clusterName }}-{{ .Values.nodeGroup }}
{{- end -}}

{{- define "masterService" -}}
{{- define "elasticsearch.masterService" -}}
{{- if empty .Values.masterService -}}
{{ .Values.clusterName }}-master
{{- else -}}
{{ .Values.masterService }}
{{- end -}}
{{- end -}}

{{- define "endpoints" -}}
{{- define "elasticsearch.endpoints" -}}
{{- $replicas := int (toString (.Values.replicas)) }}
{{- $uname := printf "%s-%s" .Values.clusterName .Values.nodeGroup }}
{{- range $i, $e := untilStep 0 $replicas 1 -}}
{{ $uname }}-{{ $i }},
{{- end -}}
{{- end -}}

{{- define "esMajorVersion" -}}
{{- define "elasticsearch.esMajorVersion" -}}
{{- if .Values.esMajorVersion -}}
{{ .Values.esMajorVersion }}
{{- else -}}
Expand Down
4 changes: 2 additions & 2 deletions elasticsearch/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ template "uname" . }}-config
name: {{ template "elasticsearch.uname" . }}-config
labels:
heritage: {{ .Release.Service | quote }}
release: {{ .Release.Name | quote }}
chart: "{{ .Chart.Name }}"
app: "{{ template "uname" . }}"
app: "{{ template "elasticsearch.uname" . }}"
data:
{{- range $path, $config := .Values.esConfig }}
{{ $path }}: |
Expand Down
2 changes: 1 addition & 1 deletion elasticsearch/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{- if .Values.ingress.enabled -}}
{{- $fullName := include "uname" . -}}
{{- $fullName := include "elasticsearch.uname" . -}}
{{- $servicePort := .Values.httpPort -}}
{{- $ingressPath := .Values.ingress.path -}}
apiVersion: {{ template "elasticsearch.ingress.apiVersion" . }}
Expand Down
4 changes: 2 additions & 2 deletions elasticsearch/templates/poddisruptionbudget.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
apiVersion: policy/v1beta1
kind: PodDisruptionBudget
metadata:
name: "{{ template "uname" . }}-pdb"
name: "{{ template "elasticsearch.uname" . }}-pdb"
spec:
maxUnavailable: {{ .Values.maxUnavailable }}
selector:
matchLabels:
app: "{{ template "uname" . }}"
app: "{{ template "elasticsearch.uname" . }}"
{{- end }}
2 changes: 1 addition & 1 deletion elasticsearch/templates/podsecuritypolicy.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{- if .Values.podSecurityPolicy.create -}}
{{- $fullName := include "uname" . -}}
{{- $fullName := include "elasticsearch.uname" . -}}
apiVersion: policy/v1beta1
kind: PodSecurityPolicy
metadata:
Expand Down
2 changes: 1 addition & 1 deletion elasticsearch/templates/role.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{- if .Values.rbac.create -}}
{{- $fullName := include "uname" . -}}
{{- $fullName := include "elasticsearch.uname" . -}}
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
Expand Down
2 changes: 1 addition & 1 deletion elasticsearch/templates/rolebinding.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{- if .Values.rbac.create -}}
{{- $fullName := include "uname" . -}}
{{- $fullName := include "elasticsearch.uname" . -}}
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
Expand Down
12 changes: 6 additions & 6 deletions elasticsearch/templates/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
kind: Service
apiVersion: v1
metadata:
name: {{ template "uname" . }}
name: {{ template "elasticsearch.uname" . }}
labels:
heritage: {{ .Release.Service | quote }}
release: {{ .Release.Name | quote }}
chart: "{{ .Chart.Name }}"
app: "{{ template "uname" . }}"
app: "{{ template "elasticsearch.uname" . }}"
{{- if .Values.service.labels }}
{{ toYaml .Values.service.labels | indent 4}}
{{- end }}
Expand All @@ -19,7 +19,7 @@ spec:
heritage: {{ .Release.Service | quote }}
release: {{ .Release.Name | quote }}
chart: "{{ .Chart.Name }}"
app: "{{ template "uname" . }}"
app: "{{ template "elasticsearch.uname" . }}"
ports:
- name: {{ .Values.service.httpPortName | default "http" }}
protocol: TCP
Expand All @@ -34,12 +34,12 @@ spec:
kind: Service
apiVersion: v1
metadata:
name: {{ template "uname" . }}-headless
name: {{ template "elasticsearch.uname" . }}-headless
labels:
heritage: {{ .Release.Service | quote }}
release: {{ .Release.Name | quote }}
chart: "{{ .Chart.Name }}"
app: "{{ template "uname" . }}"
app: "{{ template "elasticsearch.uname" . }}"
{{- if .Values.service.labelsHeadless }}
{{ toYaml .Values.service.labelsHeadless | indent 4 }}
{{- end }}
Expand All @@ -50,7 +50,7 @@ spec:
# Create endpoints also if the related pod isn't ready
publishNotReadyAddresses: true
selector:
app: "{{ template "uname" . }}"
app: "{{ template "elasticsearch.uname" . }}"
ports:
- name: {{ .Values.service.httpPortName | default "http" }}
port: {{ .Values.httpPort }}
Expand Down
2 changes: 1 addition & 1 deletion elasticsearch/templates/serviceaccount.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{- if .Values.rbac.create -}}
{{- $fullName := include "uname" . -}}
{{- $fullName := include "elasticsearch.uname" . -}}
apiVersion: v1
kind: ServiceAccount
metadata:
Expand Down
43 changes: 22 additions & 21 deletions elasticsearch/templates/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,30 @@
apiVersion: {{ template "elasticsearch.statefulset.apiVersion" . }}
kind: StatefulSet
metadata:
name: {{ template "uname" . }}
name: {{ template "elasticsearch.uname" . }}
labels:
heritage: {{ .Release.Service | quote }}
release: {{ .Release.Name | quote }}
chart: "{{ .Chart.Name }}"
app: "{{ template "uname" . }}"
app: "{{ template "elasticsearch.uname" . }}"
{{- range $key, $value := .Values.labels }}
{{ $key }}: {{ $value | quote }}
{{- end }}
annotations:
esMajorVersion: "{{ include "esMajorVersion" . }}"
esMajorVersion: "{{ include "elasticsearch.esMajorVersion" . }}"
spec:
serviceName: {{ template "uname" . }}-headless
serviceName: {{ template "elasticsearch.uname" . }}-headless
selector:
matchLabels:
app: "{{ template "uname" . }}"
app: "{{ template "elasticsearch.uname" . }}"
replicas: {{ .Values.replicas }}
podManagementPolicy: {{ .Values.podManagementPolicy }}
updateStrategy:
type: {{ .Values.updateStrategy }}
{{- if .Values.persistence.enabled }}
volumeClaimTemplates:
- metadata:
name: {{ template "uname" . }}
name: {{ template "elasticsearch.uname" . }}
{{- with .Values.persistence.annotations }}
annotations:
{{ toYaml . | indent 8 }}
Expand All @@ -35,15 +35,16 @@ spec:
{{- end }}
template:
metadata:
name: "{{ template "uname" . }}"
name: "{{ template "elasticsearch.uname" . }}"
labels:
heritage: {{ .Release.Service | quote }}
release: {{ .Release.Name | quote }}
chart: "{{ .Chart.Name }}"
app: "{{ template "uname" . }}"
app: "{{ template "elasticsearch.uname" . }}"
{{- range $key, $value := .Values.labels }}
{{ $key }}: {{ $value | quote }}
{{- end }}
app: "{{ template "elasticsearch.uname" . }}"
annotations:
{{- range $key, $value := .Values.podAnnotations }}
{{ $key }}: {{ $value | quote }}
Expand All @@ -62,7 +63,7 @@ spec:
fsGroup: {{ .Values.fsGroup }} # Deprecated value, please use .Values.podSecurityContext.fsGroup
{{- end }}
{{- if .Values.rbac.create }}
serviceAccountName: "{{ template "uname" . }}"
serviceAccountName: "{{ template "elasticsearch.uname" . }}"
{{- else if not (eq .Values.rbac.serviceAccountName "") }}
serviceAccountName: {{ .Values.rbac.serviceAccountName | quote }}
{{- end }}
Expand All @@ -88,7 +89,7 @@ spec:
- key: app
operator: In
values:
- "{{ template "uname" .}}"
- "{{ template "elasticsearch.uname" .}}"
topologyKey: {{ .Values.antiAffinityTopologyKey }}
{{- else if eq .Values.antiAffinity "soft" }}
podAntiAffinity:
Expand All @@ -101,7 +102,7 @@ spec:
- key: app
operator: In
values:
- "{{ template "uname" . }}"
- "{{ template "elasticsearch.uname" . }}"
{{- end }}
{{- with .Values.nodeAffinity }}
nodeAffinity:
Expand All @@ -117,7 +118,7 @@ spec:
{{- if .Values.esConfig }}
- name: esconfig
configMap:
name: {{ template "uname" . }}-config
name: {{ template "elasticsearch.uname" . }}-config
{{- end }}
{{- if .Values.keystore }}
- name: keystore
Expand Down Expand Up @@ -186,7 +187,7 @@ spec:
{{ tpl .Values.extraInitContainers . | indent 6 }}
{{- end }}
containers:
- name: "{{ template "name" . }}"
- name: "{{ template "elasticsearch.name" . }}"
securityContext:
{{ toYaml .Values.securityContext | indent 10 }}
image: "{{ .Values.image }}:{{ .Values.imageTag }}"
Expand Down Expand Up @@ -239,20 +240,20 @@ spec:
fieldRef:
fieldPath: metadata.name
{{- if eq .Values.roles.master "true" }}
{{- if ge (int (include "esMajorVersion" .)) 7 }}
{{- if ge (int (include "elasticsearch.esMajorVersion" .)) 7 }}
- name: cluster.initial_master_nodes
value: "{{ template "endpoints" . }}"
value: "{{ template "elasticsearch.endpoints" . }}"
{{- else }}
- name: discovery.zen.minimum_master_nodes
value: "{{ .Values.minimumMasterNodes }}"
{{- end }}
{{- end }}
{{- if lt (int (include "esMajorVersion" .)) 7 }}
{{- if lt (int (include "elasticsearch.esMajorVersion" .)) 7 }}
- name: discovery.zen.ping.unicast.hosts
value: "{{ template "masterService" . }}-headless"
value: "{{ template "elasticsearch.masterService" . }}-headless"
{{- else }}
- name: discovery.seed_hosts
value: "{{ template "masterService" . }}-headless"
value: "{{ template "elasticsearch.masterService" . }}-headless"
{{- end }}
- name: cluster.name
value: "{{ .Values.clusterName }}"
Expand All @@ -269,7 +270,7 @@ spec:
{{- end }}
volumeMounts:
{{- if .Values.persistence.enabled }}
- name: "{{ template "uname" . }}"
- name: "{{ template "elasticsearch.uname" . }}"
mountPath: /usr/share/elasticsearch/data
{{- end }}
{{ if .Values.keystore }}
Expand Down Expand Up @@ -313,13 +314,13 @@ spec:
else
BASIC_AUTH=''
fi
curl -XGET -s -k --fail ${BASIC_AUTH} {{ .Values.protocol }}://{{ template "masterService" . }}:{{ .Values.httpPort }}${path}
curl -XGET -s -k --fail ${BASIC_AUTH} {{ .Values.protocol }}://{{ template "elasticsearch.masterService" . }}:{{ .Values.httpPort }}${path}
}

cleanup () {
while true ; do
local master="$(http "/_cat/master?h=node" || echo "")"
if [[ $master == "{{ template "masterService" . }}"* && $master != "${NODE_NAME}" ]]; then
if [[ $master == "{{ template "elasticsearch.masterService" . }}"* && $master != "${NODE_NAME}" ]]; then
echo "This node is not master."
break
fi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ spec:
- "-c"
- |
#!/usr/bin/env bash -e
curl -XGET --fail '{{ template "uname" . }}:{{ .Values.httpPort }}/_cluster/health?{{ .Values.clusterHealthCheckParams }}'
curl -XGET --fail '{{ template "elasticsearch.uname" . }}:{{ .Values.httpPort }}/_cluster/health?{{ .Values.clusterHealthCheckParams }}'
restartPolicy: Never
2 changes: 1 addition & 1 deletion filebeat/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
1. Watch all containers come up.
$ kubectl get pods --namespace={{ .Release.Namespace }} -l app={{ template "fullname" . }} -w
$ kubectl get pods --namespace={{ .Release.Namespace }} -l app={{ template "filebeat.fullname" . }} -w
6 changes: 3 additions & 3 deletions filebeat/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "name" -}}
{{- define "filebeat.name" -}}
{{- default .Chart.Name .Values.nameOverride | 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).
*/}}
{{- define "fullname" -}}
{{- define "filebeat.fullname" -}}
{{- if .Values.fullnameOverride -}}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
{{- else -}}
Expand All @@ -22,7 +22,7 @@ We truncate at 63 chars because some Kubernetes name fields are limited to this
{{/*
Use the fullname if the serviceAccount value is not set
*/}}
{{- define "serviceAccount" -}}
{{- define "filebeat.serviceAccount" -}}
{{- if .Values.serviceAccount }}
{{- .Values.serviceAccount -}}
{{- else }}
Expand Down
4 changes: 2 additions & 2 deletions filebeat/templates/clusterrole.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRole
metadata:
name: {{ template "serviceAccount" . }}-cluster-role
name: {{ template "filebeat.serviceAccount" . }}-cluster-role
labels:
app: "{{ template "fullname" . }}"
app: "{{ template "filebeat.fullname" . }}"
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
heritage: {{ .Release.Service | quote }}
release: {{ .Release.Name | quote }}
Expand Down
8 changes: 4 additions & 4 deletions filebeat/templates/clusterrolebinding.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
name: {{ template "serviceAccount" . }}-cluster-role-binding
name: {{ template "filebeat.serviceAccount" . }}-cluster-role-binding
labels:
app: "{{ template "fullname" . }}"
app: "{{ template "filebeat.fullname" . }}"
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
heritage: {{ .Release.Service | quote }}
release: {{ .Release.Name | quote }}
roleRef:
kind: ClusterRole
name: {{ template "serviceAccount" . }}-cluster-role
name: {{ template "filebeat.serviceAccount" . }}-cluster-role
apiGroup: rbac.authorization.k8s.io
subjects:
- kind: ServiceAccount
name: {{ template "serviceAccount" . }}
name: {{ template "filebeat.serviceAccount" . }}
namespace: {{ .Release.Namespace }}
{{- end -}}
Loading