Skip to content

Commit

Permalink
Standard kubernetes labels (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
plumdog authored Apr 21, 2021
1 parent b5f586a commit 8a7244f
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 52 deletions.
2 changes: 1 addition & 1 deletion charts/flagsmith/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: v2
name: flagsmith
description: Flagsmith
type: application
version: 0.1.8
version: 0.2.0
appVersion: 2.6.0
dependencies:
- name: postgresql
Expand Down
27 changes: 27 additions & 0 deletions charts/flagsmith/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,33 @@ If release name contains chart name it will be used as a full name.
{{- end -}}
{{- end -}}

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

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

{{/*
Selector labels
*/}}
{{- define "flagsmith.selectorLabels" -}}
app.kubernetes.io/name: {{ include "flagsmith.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- 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).
Expand Down
16 changes: 6 additions & 10 deletions charts/flagsmith/templates/deployment-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@ kind: Deployment
metadata:
name: {{ template "flagsmith.fullname" . }}-api
labels:
app: {{ template "flagsmith.fullname" . }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}"
release: "{{ .Release.Name }}"
heritage: "{{ .Release.Service }}"
{{- include "flagsmith.labels" . | nindent 4 }}
app.kubernetes.io/component: api
spec:
selector:
matchLabels:
app: {{ template "flagsmith.fullname" . }}
release: "{{ .Release.Name }}"
role: api
{{- include "flagsmith.selectorLabels" . | nindent 6 }}
app.kubernetes.io/component: api
replicas: {{ .Values.api.replicacount }}
template:
metadata:
Expand All @@ -21,9 +18,8 @@ spec:
{{ toYaml .Values.api.podAnnotations | indent 8 }}
{{- end }}
labels:
app: {{ template "flagsmith.fullname" . }}
release: "{{ .Release.Name }}"
role: api
{{- include "flagsmith.selectorLabels" . | nindent 8 }}
app.kubernetes.io/component: api
{{- if .Values.api.podLabels }}
{{ toYaml .Values.api.podLabels | indent 8 }}
{{- end }}
Expand Down
16 changes: 6 additions & 10 deletions charts/flagsmith/templates/deployment-frontend.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@ kind: Deployment
metadata:
name: {{ template "flagsmith.fullname" . }}
labels:
app: {{ template "flagsmith.fullname" . }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}"
release: "{{ .Release.Name }}"
heritage: "{{ .Release.Service }}"
{{- include "flagsmith.labels" . | nindent 4 }}
app.kubernetes.io/component: frontend
spec:
selector:
matchLabels:
app: {{ template "flagsmith.fullname" . }}
release: "{{ .Release.Name }}"
role: frontend
{{- include "flagsmith.selectorLabels" . | nindent 6 }}
app.kubernetes.io/component: frontend
replicas: {{ .Values.frontend.replicacount }}
template:
metadata:
Expand All @@ -21,9 +18,8 @@ spec:
{{ toYaml .Values.frontend.podAnnotations | indent 8 }}
{{- end }}
labels:
app: {{ template "flagsmith.fullname" . }}
release: "{{ .Release.Name }}"
role: frontend
{{- include "flagsmith.selectorLabels" . | nindent 8 }}
app.kubernetes.io/component: frontend
{{- if .Values.frontend.podLabels }}
{{ toYaml .Values.frontend.podLabels | indent 8 }}
{{- end }}
Expand Down
6 changes: 2 additions & 4 deletions charts/flagsmith/templates/ingress-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ kind: Ingress
metadata:
name: {{ $fullName }}-api
labels:
app: {{ template "flagsmith.fullname" . }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}"
release: "{{ .Release.Name }}"
heritage: "{{ .Release.Service }}"
{{- include "flagsmith.labels" . | nindent 4 }}
app.kubernetes.io/component: api
{{- with .Values.ingress.api.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
Expand Down
6 changes: 2 additions & 4 deletions charts/flagsmith/templates/ingress-frontend.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ kind: Ingress
metadata:
name: {{ $fullName }}-frontend
labels:
app: {{ template "flagsmith.fullname" . }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}"
release: "{{ .Release.Name }}"
heritage: "{{ .Release.Service }}"
{{- include "flagsmith.labels" . | nindent 4 }}
app.kubernetes.io/component: frontend
{{- with .Values.ingress.frontend.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
Expand Down
8 changes: 3 additions & 5 deletions charts/flagsmith/templates/routes-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ kind: Route
metadata:
name: flagsmith-api
labels:
app: {{ template "flagsmith.fullname" . }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}"
release: "{{ .Release.Name }}"
heritage: "{{ .Release.Service }}"
{{- include "flagsmith.labels" . | nindent 4 }}
app.kubernetes.io/component: api
spec:
host: flagsmith-api-{{ .Release.Namespace }}.{{ .Values.openshiftdomain }}
port:
Expand All @@ -27,4 +25,4 @@ status:
routerCanonicalHostname: <host>
routerName: default
wildcardPolicy: None
{{- end }}
{{- end }}
8 changes: 3 additions & 5 deletions charts/flagsmith/templates/routes-frontend.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ kind: Route
metadata:
name: flagsmith-frontend
labels:
app: {{ template "flagsmith.fullname" . }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}"
release: "{{ .Release.Name }}"
heritage: "{{ .Release.Service }}"
{{- include "flagsmith.labels" . | nindent 4 }}
app.kubernetes.io/component: frontend
spec:
host: flagsmith-{{ .Release.Namespace }}.{{ .Values.openshiftdomain }}
port:
Expand All @@ -27,4 +25,4 @@ status:
routerCanonicalHostname: <host>
routerName: default
wildcardPolicy: None
{{- end }}
{{- end }}
8 changes: 3 additions & 5 deletions charts/flagsmith/templates/secrets-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ kind: Secret
metadata:
name: {{ template "flagsmith.fullname" . }}
labels:
app: {{ template "flagsmith.fullname" . }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}"
release: "{{ .Release.Name }}"
heritage: "{{ .Release.Service }}"
{{- include "flagsmith.labels" . | nindent 4 }}
app.kubernetes.io/component: api
type: Opaque
data:
{{ if or (not .Values.postgresql.enabled) (.Values.postgresql.postgresqlUsername) }}
Expand All @@ -17,4 +15,4 @@ data:
{{ end }}
{{ if or (not .Values.postgresql.enabled) (.Values.postgresql.postgresqlDatabase) }}
dbname: {{ .Values.postgresql.postgresqlDatabase | default "" | b64enc | quote }}
{{ end }}
{{ end }}
6 changes: 2 additions & 4 deletions charts/flagsmith/templates/service-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ kind: Service
metadata:
name: {{ include "flagsmith.fullname" . }}-api
labels:
app: {{ template "flagsmith.fullname" . }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}"
release: "{{ .Release.Name }}"
heritage: "{{ .Release.Service }}"
{{- include "flagsmith.labels" . | nindent 4 }}
app.kubernetes.io/component: api
spec:
type: {{ .Values.service.api.type }}
ports:
Expand Down
6 changes: 2 additions & 4 deletions charts/flagsmith/templates/service-frontend.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ kind: Service
metadata:
name: {{ include "flagsmith.fullname" . }}-frontend
labels:
app: {{ template "flagsmith.fullname" . }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}"
release: "{{ .Release.Name }}"
heritage: "{{ .Release.Service }}"
{{- include "flagsmith.labels" . | nindent 4 }}
app.kubernetes.io/component: frontend
spec:
type: {{ .Values.service.frontend.type }}
ports:
Expand Down

0 comments on commit 8a7244f

Please sign in to comment.