Skip to content

Commit

Permalink
feat(helm): refactoring Kubernetes recommended labels
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas Lamirault <[email protected]>
  • Loading branch information
nlamirault committed Dec 12, 2024
1 parent f9c3afb commit 3ae39f9
Show file tree
Hide file tree
Showing 25 changed files with 72 additions and 31 deletions.
3 changes: 2 additions & 1 deletion charts/keep/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ helm.sh/chart: {{ include "keep.chart" . }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/part-of: keep
{{- end }}

{{/*
Expand Down Expand Up @@ -186,4 +187,4 @@ Helper function for KEEP_API_URL that handles both relative and absolute URLs
{{- else -}}
{{- include "keep.fullUrl" . -}}{{- $apiUrlClient -}}
{{- end -}}
{{- end -}}
{{- end -}}
1 change: 1 addition & 0 deletions charts/keep/templates/backend-hpa.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ metadata:
name: {{ include "keep.fullname" . }}-backend
labels:
{{- include "keep.labels" . | nindent 4 }}
app.kubernetes.io/component: backend
spec:
scaleTargetRef:
apiVersion: apps/v1
Expand Down
10 changes: 6 additions & 4 deletions charts/keep/templates/backend-route.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@ apiVersion: route.openshift.io/v1
kind: Route
metadata:
name: {{ $fullName }}
labels: {{- include "keep.labels" . | nindent 4 }}
labels:
{{- include "keep.labels" . | nindent 4 }}
app.kubernetes.io/component: backend
spec:
host: {{ .Values.backend.route.host }}
to:
kind: Service
name: {{ $fullName }}-backend
weight: 100
port:
port:
targetPort: {{ .Values.backend.service.port }}
wildcardPolicy: {{ .Values.backend.route.wildcardPolicy }}
tls:
{{ toYaml .Values.backend.route.tls | indent 4 }}
tls:
{{ toYaml .Values.backend.route.tls | indent 4 }}
{{- end}}
3 changes: 2 additions & 1 deletion charts/keep/templates/backend-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ metadata:
name: {{ include "keep.fullname" . }}-backend
labels:
{{- include "keep.labels" . | nindent 4 }}
keep-component: backend-service
app.kubernetes.io/component: backend
keep-component: backend
annotations:
{{- if .Values.isGKE }}
cloud.google.com/backend-config: '{"default": "{{ include "keep.fullname" . }}-backend-backendconfig"}'
Expand Down
4 changes: 3 additions & 1 deletion charts/keep/templates/backend.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ metadata:
name: {{ include "keep.fullname" . }}-backend
labels:
{{- include "keep.labels" . | nindent 4 }}
app.kubernetes.io/component: backend
keep-component: backend
spec:
{{- if not .Values.backend.autoscaling.enabled }}
Expand All @@ -27,7 +28,8 @@ spec:
{{- end }}
{{- end }}
labels:
{{- include "keep.selectorLabels" . | nindent 8 }}
{{- include "keep.labels" . | nindent 8 }}
app.kubernetes.io/component: backend
keep-component: backend
spec:
{{- with .Values.backend.imagePullSecrets }}
Expand Down
3 changes: 3 additions & 0 deletions charts/keep/templates/db-pv.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
apiVersion: v1
kind: PersistentVolume
metadata:
labels:
{{- include "keep.labels" . | nindent 4 }}
app.kubernetes.io/component: database
name: {{ include "keep.fullname" . }}-pv
spec:
capacity:
Expand Down
5 changes: 4 additions & 1 deletion charts/keep/templates/db-pvc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ metadata:
{{- if .Values.database.pvc.retain }}
helm.sh/resource-policy: keep
{{- end }}
labels:
{{- include "keep.labels" . | nindent 4 }}
app.kubernetes.io/component: database
spec:
{{- if $existingPvc }}
# Use existing PVC spec
Expand All @@ -25,4 +28,4 @@ spec:
requests:
storage: {{ .Values.database.pvc.size }}
{{- end }}
{{- end }}
{{- end }}
3 changes: 2 additions & 1 deletion charts/keep/templates/db-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ metadata:
name: {{ include "keep.name" . }}-database
labels:
{{- include "keep.labels" . | nindent 4 }}
keep-component: database-service
app.kubernetes.io/component: database
keep-component: database
spec:
type: {{ .Values.database.service.type }}
ports:
Expand Down
4 changes: 3 additions & 1 deletion charts/keep/templates/db.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ metadata:
name: {{ include "keep.fullname" . }}-database
labels:
{{- include "keep.labels" . | nindent 4 }}
app.kubernetes.io/component: database
keep-component: database
spec:
{{- if not .Values.database.autoscaling.enabled }}
Expand All @@ -21,7 +22,8 @@ spec:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "keep.selectorLabels" . | nindent 8 }}
{{- include "keep.labels" . | nindent 8 }}
app.kubernetes.io/component: database
keep-component: database
spec:
{{- with .Values.database.imagePullSecrets }}
Expand Down
3 changes: 3 additions & 0 deletions charts/keep/templates/delete-secret-job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ metadata:
annotations:
"helm.sh/hook": pre-delete
"helm.sh/hook-delete-policy": hook-succeeded,hook-failed
labels:
{{- include "keep.labels" . | nindent 4 }}
app.kubernetes.io/component: secrets
spec:
template:
spec:
Expand Down
1 change: 1 addition & 0 deletions charts/keep/templates/frontend-hpa.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ metadata:
name: {{ include "keep.fullname" . }}-frontend
labels:
{{- include "keep.labels" . | nindent 4 }}
app.kubernetes.io/component: frontend
spec:
scaleTargetRef:
apiVersion: apps/v1
Expand Down
10 changes: 6 additions & 4 deletions charts/keep/templates/frontend-route.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@ apiVersion: route.openshift.io/v1
kind: Route
metadata:
name: {{ $fullName }}
labels: {{- include "keep.labels" . | nindent 4 }}
labels:
{{- include "keep.labels" . | nindent 4 }}
app.kubernetes.io/component: frontend
spec:
host: {{ .Values.frontend.route.host }}
to:
kind: Service
name: {{ $fullName }}-frontend
weight: 100
port:
port:
targetPort: {{ .Values.frontend.service.port }}
wildcardPolicy: {{ .Values.frontend.route.wildcardPolicy }}
tls:
{{ toYaml .Values.frontend.route.tls | indent 4 }}
tls:
{{ toYaml .Values.frontend.route.tls | indent 4 }}
{{- end}}
3 changes: 2 additions & 1 deletion charts/keep/templates/frontend-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ metadata:
name: {{ include "keep.fullname" . }}-frontend
labels:
{{- include "keep.labels" . | nindent 4 }}
keep-component: frontend-service
app.kubernetes.io/component: frontend
keep-component: frontend
annotations:
{{- if .Values.isGKE }}
cloud.google.com/backend-config: '{"default": "{{ include "keep.fullname" . }}-frontend-backendconfig"}'
Expand Down
14 changes: 8 additions & 6 deletions charts/keep/templates/frontend.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ metadata:
name: {{ include "keep.fullname" . }}-frontend
labels:
{{- include "keep.labels" . | nindent 4 }}
app.kubernetes.io/component: frontend
keep-component: frontend
spec:
{{- if not .Values.frontend.autoscaling.enabled }}
Expand All @@ -21,7 +22,8 @@ spec:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "keep.selectorLabels" . | nindent 8 }}
{{- include "keep.labels" . | nindent 8 }}
app.kubernetes.io/component: frontend
keep-component: frontend
spec:
{{- with .Values.frontend.imagePullSecrets }}
Expand Down Expand Up @@ -51,10 +53,10 @@ spec:
- name: NEXTAUTH_URL
value: {{ include "keep.nextAuthUrl" . | quote }}
{{- range .Values.frontend.env }}
{{- if and
(ne .name "PUSHER_HOST")
(ne .name "API_URL_CLIENT")
(ne .name "API_URL")
{{- if and
(ne .name "PUSHER_HOST")
(ne .name "API_URL_CLIENT")
(ne .name "API_URL")
(ne .name "NEXTAUTH_URL") }}
- name: {{ .name }}
value: {{ .value | quote }}
Expand Down Expand Up @@ -87,4 +89,4 @@ spec:
volumes:
- name: state-volume
emptyDir: {}
{{- end }}
{{- end }}
5 changes: 3 additions & 2 deletions charts/keep/templates/ingress-haproxy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ metadata:
name: {{ $fullName }}-ingress
labels:
{{- include "keep.labels" . | nindent 4 }}
app.kubernetes.io/component: networking
annotations:
kubernetes.io/ingress.class: "haproxy"
# HAProxy timeout configurations
Expand All @@ -14,7 +15,7 @@ metadata:
haproxy-ingress.github.io/timeout-connect: "3600s"
haproxy-ingress.github.io/timeout-tunnel: "3600s"
haproxy-ingress.github.io/ssl-redirect: "false"

# Backend configurations for path rewrites + # WebSocket support
haproxy-ingress.github.io/config-backend: |
acl path_v2 path_beg {{ .Values.global.ingress.backendPrefix }}/
Expand Down Expand Up @@ -98,4 +99,4 @@ spec:
port:
number: {{ $.Values.frontend.service.port }}
{{- end }}
{{- end }}
{{- end }}
3 changes: 2 additions & 1 deletion charts/keep/templates/ingress-nginx.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ metadata:
name: {{ $fullName }}-ingress
labels:
{{- include "keep.labels" . | nindent 4 }}
app.kubernetes.io/component: networking
annotations:
{{- if or (eq .Values.global.ingress.className "nginx") (eq .Values.global.ingress.classType "nginx") }}
kubernetes.io/ingress.class: "nginx"
Expand Down Expand Up @@ -115,4 +116,4 @@ spec:
port:
number: {{ $.Values.frontend.service.port }}
{{- end }}
{{- end }}
{{- end }}
3 changes: 2 additions & 1 deletion charts/keep/templates/ingress-traefik-middleware.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ metadata:
namespace: {{ .Release.Namespace }}
labels:
{{- include "keep.labels" . | nindent 4 }}
app.kubernetes.io/component: networking
spec:
stripPrefix:
prefixes:
- {{ .Values.global.ingress.backendPrefix }}
- {{ .Values.global.ingress.websocketPrefix }}
{{- end }}
{{- end }}
5 changes: 3 additions & 2 deletions charts/keep/templates/ingress-traefik.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ metadata:
name: {{ $fullName }}-ingress
labels:
{{- include "keep.labels" . | nindent 4 }}
app.kubernetes.io/component: networking
annotations:
traefik.ingress.kubernetes.io/router.middlewares: {{ .Release.Namespace }}-strip-prefix@kubernetescrd
traefik.ingress.kubernetes.io/router.entrypoints: web
traefik.ingress.kubernetes.io/timeouts.idle: "3600s"
traefik.ingress.kubernetes.io/timeouts.connect: "3600s"
traefik.ingress.kubernetes.io/timeouts.read: "3600s"
traefik.ingress.kubernetes.io/timeouts.write: "3600s"

# WebSocket configuration
traefik.ingress.kubernetes.io/websockets.enabled: "true"
{{- with .Values.global.ingress.annotations }}
Expand Down Expand Up @@ -93,4 +94,4 @@ spec:
port:
number: {{ $.Values.frontend.service.port }}
{{- end }}
{{- end }}
{{- end }}
3 changes: 3 additions & 0 deletions charts/keep/templates/role-binding-secret-manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ kind: RoleBinding
metadata:
name: secret-manager-rolebinding
namespace: {{ include "keep.namespace" . }}
labels:
{{- include "keep.labels" . | nindent 4 }}
app.kubernetes.io/component: secrets
subjects:
- kind: ServiceAccount
name: {{ include "keep.serviceAccountName" . }}
Expand Down
3 changes: 3 additions & 0 deletions charts/keep/templates/role-secret-manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ kind: Role
metadata:
name: secret-manager-role
namespace: {{ include "keep.namespace" . }}
labels:
{{- include "keep.labels" . | nindent 4 }}
app.kubernetes.io/component: secrets
rules:
- apiGroups: [""]
resources: ["secrets"]
Expand Down
1 change: 1 addition & 0 deletions charts/keep/templates/serviceaccount.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ metadata:
name: {{ include "keep.serviceAccountName" . }}
labels:
{{- include "keep.labels" . | nindent 4 }}
app.kubernetes.io/component: rbac
{{- with .Values.serviceAccount.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
Expand Down
1 change: 1 addition & 0 deletions charts/keep/templates/websocket-hpa.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ metadata:
name: {{ include "keep.fullname" . }}-websocket
labels:
{{- include "keep.labels" . | nindent 4 }}
app.kubernetes.io/component: websocket
spec:
scaleTargetRef:
apiVersion: apps/v1
Expand Down
7 changes: 4 additions & 3 deletions charts/keep/templates/websocket-route.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ metadata:
name: {{ $fullName }}-websocket
labels:
{{- include "keep.labels" . | nindent 4 }}
app.kubernetes.io/component: websocket
spec:
host: {{ .Values.websocket.route.host }}
to:
kind: Service
name: {{ $fullName }}-websocket
weight: 100
port:
port:
targetPort: {{ .Values.websocket.service.port }}
wildcardPolicy: {{ .Values.websocket.route.wildcardPolicy }}
tls:
{{ toYaml .Values.websocket.route.tls | indent 4 }}
tls:
{{ toYaml .Values.websocket.route.tls | indent 4 }}
{{- end }}
1 change: 1 addition & 0 deletions charts/keep/templates/websocket-server-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ metadata:
name: {{ include "keep.fullname" . }}-websocket
labels:
{{- include "keep.labels" . | nindent 4 }}
app.kubernetes.io/component: websocket
keep-component: websocket-service
spec:
type: {{ .Values.websocket.service.type }}
Expand Down
4 changes: 3 additions & 1 deletion charts/keep/templates/websocket-server.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ metadata:
name: {{ include "keep.fullname" . }}-websocket
labels:
{{- include "keep.labels" . | nindent 4 }}
app.kubernetes.io/component: websocket
keep-component: websocket
spec:
{{- if not .Values.websocket.autoscaling.enabled }}
Expand All @@ -21,7 +22,8 @@ spec:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "keep.selectorLabels" . | nindent 8 }}
{{- include "keep.labels" . | nindent 8 }}
app.kubernetes.io/component: websocket
keep-component: websocket
spec:
{{- with .Values.websocket.imagePullSecrets }}
Expand Down

0 comments on commit 3ae39f9

Please sign in to comment.