Skip to content

Commit

Permalink
Rework labels in Opensearch chart to match standard recommendations (#37
Browse files Browse the repository at this point in the history
)

* feat: rework labels to match standard recommendations

https://helm.sh/docs/chart_best_practices/labels/#standard-labels
https://kubernetes.io/docs/concepts/overview/working-with-objects/common-labels/

Signed-off-by: Scott Leggett <[email protected]>

* chore: bump opensearch chart version

Signed-off-by: Scott Leggett <[email protected]>
  • Loading branch information
smlx authored Oct 19, 2021
1 parent 00c507f commit 09f1b4c
Show file tree
Hide file tree
Showing 13 changed files with 74 additions and 73 deletions.
2 changes: 1 addition & 1 deletion charts/opensearch/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type: application
# 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: 1.1.0
version: 1.2.0

# 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
Expand Down
45 changes: 40 additions & 5 deletions charts/opensearch/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,52 @@
Expand the name of the chart.
*/}}
{{- define "opensearch.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- 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).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "opensearch.fullname" -}}
{{- $name := default .Chart.Name .Values.nameOverride -}}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- if contains .Chart.Name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name .Chart.Name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "opensearch.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "opensearch.labels" -}}
helm.sh/chart: {{ include "opensearch.chart" . }}
{{ include "opensearch.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/component: {{ include "opensearch.uname" . }}
{{- with .Values.labels }}
{{ toYaml . }}
{{- end }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "opensearch.selectorLabels" -}}
app.kubernetes.io/name: {{ include "opensearch.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{- define "opensearch.uname" -}}
{{- if empty .Values.fullnameOverride -}}
Expand Down
5 changes: 1 addition & 4 deletions charts/opensearch/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ kind: ConfigMap
metadata:
name: {{ template "opensearch.uname" . }}-config
labels:
heritage: {{ .Release.Service | quote }}
release: {{ .Release.Name | quote }}
chart: "{{ .Chart.Name }}"
app: "{{ template "opensearch.uname" . }}"
{{- include "opensearch.labels" . | nindent 4 }}
data:
{{- range $configName, $configYaml := .Values.config }}
{{ $configName }}: |
Expand Down
4 changes: 1 addition & 3 deletions charts/opensearch/templates/ingress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ kind: Ingress
metadata:
name: {{ $fullName }}
labels:
app: {{ .Chart.Name }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
{{- include "opensearch.labels" . | nindent 4 }}
{{- with .Values.ingress.annotations }}
annotations:
{{ toYaml . | indent 4 }}
Expand Down
2 changes: 2 additions & 0 deletions charts/opensearch/templates/networkpolicy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: {{ template "opensearch.uname" . }}-opensearch-net
labels:
{{- include "opensearch.labels" . | nindent 4 }}
spec:
ingress:
- from:
Expand Down
4 changes: 3 additions & 1 deletion charts/opensearch/templates/poddisruptionbudget.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ apiVersion: policy/v1beta1
kind: PodDisruptionBudget
metadata:
name: "{{ template "opensearch.uname" . }}-pdb"
labels:
{{- include "opensearch.labels" . | nindent 4 }}
spec:
maxUnavailable: {{ .Values.maxUnavailable }}
selector:
matchLabels:
app: "{{ template "opensearch.uname" . }}"
{{- include "opensearch.selectorLabels" . | nindent 6 }}
{{- end }}
5 changes: 1 addition & 4 deletions charts/opensearch/templates/podsecuritypolicy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ kind: PodSecurityPolicy
metadata:
name: {{ default $fullName .Values.podSecurityPolicy.name | quote }}
labels:
heritage: {{ .Release.Service | quote }}
release: {{ .Release.Name | quote }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
app: {{ $fullName | quote }}
{{- include "opensearch.labels" . | nindent 4 }}
spec:
{{ toYaml .Values.podSecurityPolicy.spec | indent 2 }}
{{- if .Values.sysctl.enabled }}
Expand Down
6 changes: 1 addition & 5 deletions charts/opensearch/templates/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: {{ $fullName | quote }}
labels:
heritage: {{ .Release.Service | quote }}
release: {{ .Release.Name | quote }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
app: {{ $fullName | quote }}
{{- include "opensearch.labels" . | nindent 4 }}
rules:
- apiGroups:
- extensions
Expand Down
5 changes: 1 addition & 4 deletions charts/opensearch/templates/rolebinding.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ kind: RoleBinding
metadata:
name: {{ $fullName | quote }}
labels:
heritage: {{ .Release.Service | quote }}
release: {{ .Release.Name | quote }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
app: {{ $fullName | quote }}
{{- include "opensearch.labels" . | nindent 4 }}
subjects:
- kind: ServiceAccount
{{- if eq .Values.rbac.serviceAccountName "" }}
Expand Down
4 changes: 1 addition & 3 deletions charts/opensearch/templates/securityconfig.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ metadata:
name: {{ include "opensearch.uname" . }}-securityconfig
namespace: {{ .Release.Namespace }}
labels:
app: {{ .Chart.Name }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
{{- include "opensearch.labels" . | nindent 4 }}
type: Opaque
stringData:
{{- range $key, $val := .Values.securityConfig.config.data }}
Expand Down
16 changes: 4 additions & 12 deletions charts/opensearch/templates/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ metadata:
name: {{ template "opensearch.uname" . }}
{{- end }}
labels:
heritage: {{ .Release.Service | quote }}
release: {{ .Release.Name | quote }}
chart: "{{ .Chart.Name }}"
app: "{{ template "opensearch.uname" . }}"
{{- include "opensearch.labels" . | nindent 4 }}
{{- if .Values.service.labels }}
{{ toYaml .Values.service.labels | indent 4}}
{{- end }}
Expand All @@ -20,9 +17,7 @@ metadata:
spec:
type: {{ .Values.service.type }}
selector:
release: {{ .Release.Name | quote }}
chart: "{{ .Chart.Name }}"
app: "{{ template "opensearch.uname" . }}"
{{- include "opensearch.selectorLabels" . | nindent 4 }}
ports:
- name: {{ .Values.service.httpPortName | default "http" }}
protocol: TCP
Expand Down Expand Up @@ -53,10 +48,7 @@ metadata:
name: {{ template "opensearch.uname" . }}-headless
{{- end }}
labels:
heritage: {{ .Release.Service | quote }}
release: {{ .Release.Name | quote }}
chart: "{{ .Chart.Name }}"
app: "{{ template "opensearch.uname" . }}"
{{- include "opensearch.labels" . | nindent 4 }}
{{- if .Values.service.labelsHeadless }}
{{ toYaml .Values.service.labelsHeadless | indent 4 }}
{{- end }}
Expand All @@ -67,7 +59,7 @@ spec:
# Create endpoints also if the related pod isn't ready
publishNotReadyAddresses: true
selector:
app: "{{ template "opensearch.uname" . }}"
{{- include "opensearch.selectorLabels" . | nindent 4 }}
ports:
- name: {{ .Values.service.httpPortName | default "http" }}
port: {{ .Values.httpPort }}
Expand Down
7 changes: 2 additions & 5 deletions charts/opensearch/templates/serviceaccount.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,10 @@ metadata:
{{- else }}
name: {{ .Values.rbac.serviceAccountName | quote }}
{{- end }}
labels:
{{- include "opensearch.labels" . | nindent 4 }}
annotations:
{{- with .Values.rbac.serviceAccountAnnotations }}
{{- toYaml . | nindent 4 }}
{{- end }}
labels:
heritage: {{ .Release.Service | quote }}
release: {{ .Release.Name | quote }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
app: {{ $fullName | quote }}
{{- end -}}
42 changes: 16 additions & 26 deletions charts/opensearch/templates/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,14 @@ kind: StatefulSet
metadata:
name: {{ template "opensearch.uname" . }}
labels:
heritage: {{ .Release.Service | quote }}
release: {{ .Release.Name | quote }}
chart: "{{ .Chart.Name }}"
app: "{{ template "opensearch.uname" . }}"
{{- range $key, $value := .Values.labels }}
{{ $key }}: {{ $value | quote }}
{{- end }}
{{- include "opensearch.labels" . | nindent 4 }}
annotations:
majorVersion: "{{ include "opensearch.majorVersion" . }}"
spec:
serviceName: {{ template "opensearch.uname" . }}-headless
selector:
matchLabels:
release: {{ .Release.Name | quote }}
chart: "{{ .Chart.Name }}"
app: "{{ template "opensearch.uname" . }}"
{{- include "opensearch.selectorLabels" . | nindent 6 }}
replicas: {{ .Values.replicas }}
podManagementPolicy: {{ .Values.podManagementPolicy }}
updateStrategy:
Expand All @@ -30,12 +22,7 @@ spec:
name: {{ template "opensearch.uname" . }}
{{- if .Values.persistence.labels.enabled }}
labels:
release: {{ .Release.Name | quote }}
chart: "{{ .Chart.Name }}"
app: "{{ template "opensearch.uname" . }}"
{{- range $key, $value := .Values.labels }}
{{ $key }}: {{ $value | quote }}
{{- end }}
{{- include "opensearch.labels" . | nindent 8 }}
{{- end }}
{{- with .Values.persistence.annotations }}
annotations:
Expand All @@ -61,12 +48,7 @@ spec:
metadata:
name: "{{ template "opensearch.uname" . }}"
labels:
release: {{ .Release.Name | quote }}
chart: "{{ .Chart.Name }}"
app: "{{ template "opensearch.uname" . }}"
{{- range $key, $value := .Values.labels }}
{{ $key }}: {{ $value | quote }}
{{- end }}
{{- include "opensearch.labels" . | nindent 8 }}
annotations:
{{- range $key, $value := .Values.podAnnotations }}
{{ $key }}: {{ $value | quote }}
Expand Down Expand Up @@ -113,10 +95,14 @@ spec:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: app
- key: app.kubernetes.io/instance
operator: In
values:
- "{{ template "opensearch.uname" .}}"
- {{ .Release.Name }}
- key: app.kubernetes.io/name
operator: In
values:
- {{ include "opensearch.name" . }}
topologyKey: {{ .Values.antiAffinityTopologyKey }}
{{- else if eq .Values.antiAffinity "soft" }}
podAntiAffinity:
Expand All @@ -126,10 +112,14 @@ spec:
topologyKey: {{ .Values.antiAffinityTopologyKey }}
labelSelector:
matchExpressions:
- key: app
- key: app.kubernetes.io/instance
operator: In
values:
- {{ .Release.Name }}
- key: app.kubernetes.io/name
operator: In
values:
- "{{ template "opensearch.uname" . }}"
- {{ include "opensearch.name" . }}
{{- end }}
{{- with .Values.nodeAffinity }}
nodeAffinity:
Expand Down

0 comments on commit 09f1b4c

Please sign in to comment.