refactor: naming, labels and selectors

This commit is contained in:
jon4hz
2022-12-28 15:42:47 +01:00
parent da5800c268
commit 4880cd84dc
6 changed files with 157 additions and 25 deletions

View File

@ -0,0 +1,114 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "infisical.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}
{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "infisical.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{/*
Create unified labels for infisical components
*/}}
{{- define "infisical.common.matchLabels" -}}
app: {{ template "infisical.name" . }}
release: {{ .Release.Name }}
{{- end -}}
{{- define "infisical.common.metaLabels" -}}
chart: {{ template "infisical.chart" . }}
heritage: {{ .Release.Service }}
{{- end -}}
{{- define "infisical.common.labels" -}}
{{ include "infisical.common.matchLabels" . }}
{{ include "infisical.common.metaLabels" . }}
{{- end -}}
{{- define "infisical.backend.labels" -}}
{{ include "infisical.backend.matchLabels" . }}
{{ include "infisical.common.metaLabels" . }}
{{- end -}}
{{- define "infisical.backend.matchLabels" -}}
component: {{ .Values.backend.name | quote }}
{{ include "infisical.common.matchLabels" . }}
{{- end -}}
{{- define "infisical.frontend.labels" -}}
{{ include "infisical.frontend.matchLabels" . }}
{{ include "infisical.common.metaLabels" . }}
{{- end -}}
{{- define "infisical.frontend.matchLabels" -}}
component: {{ .Values.frontend.name | quote }}
{{ include "infisical.common.matchLabels" . }}
{{- end -}}
{{- define "infisical.mongodb.labels" -}}
{{ include "infisical.mongodb.matchLabels" . }}
{{ include "infisical.common.metaLabels" . }}
{{- end -}}
{{- define "infisical.mongodb.matchLabels" -}}
component: {{ .Values.mongodb.name | quote }}
{{ include "infisical.common.matchLabels" . }}
{{- end -}}
{{/*
Create a fully qualified backend proxy name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
*/}}
{{- define "infisical.backend.fullname" -}}
{{- if .Values.backend.fullnameOverride -}}
{{- .Values.backend.fullnameOverride | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- $name := default .Chart.Name .Values.nameOverride -}}
{{- if contains $name .Release.Name -}}
{{- printf "%s-%s" .Release.Name .Values.backend.name | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- printf "%s-%s-%s" .Release.Name $name .Values.backend.name | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{/*
Create a fully qualified frontend manager name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
*/}}
{{- define "infisical.frontend.fullname" -}}
{{- if .Values.frontend.fullnameOverride -}}
{{- .Values.frontend.fullnameOverride | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- $name := default .Chart.Name .Values.nameOverride -}}
{{- if contains $name .Release.Name -}}
{{- printf "%s-%s" .Release.Name .Values.frontend.name | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- printf "%s-%s-%s" .Release.Name $name .Values.frontend.name | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{/*
Create a fully qualified mongodb collector name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
*/}}
{{- define "infisical.mongodb.fullname" -}}
{{- if .Values.mongodb.fullnameOverride -}}
{{- .Values.mongodb.fullnameOverride | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- $name := default .Chart.Name .Values.nameOverride -}}
{{- if contains $name .Release.Name -}}
{{- printf "%s-%s" .Release.Name .Values.mongodb.name | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- printf "%s-%s-%s" .Release.Name $name .Values.mongodb.name | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- end -}}
{{- end -}}

View File

@ -1,22 +1,22 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ .Release.Name }}-backend-deployment
name: {{ include "infisical.backend.fullname" . }}
labels:
app: backend
{{- include "infisical.backend.labels" . | nindent 4 }}
spec:
replicas: {{ .Values.backend.replicaCount }}
selector:
matchLabels:
app: backend
{{- include "infisical.backend.matchLabels" . | nindent 6 }}
template:
metadata:
labels:
app: backend
{{- include "infisical.backend.matchLabels" . | nindent 8 }}
spec:
containers:
- name: backend
image: "{{ .Values.frontend.image.repository }}:{{ .Values.frontend.image.tag | default .Chart.AppVersion }}"
- name: {{ template "infisical.name" . }}-{{ .Values.backend.name }}
image: "{{ .Values.backend.image.repository }}:{{ .Values.backend.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.backend.image.pullPolicy }}
ports:
- containerPort: 4000
@ -38,10 +38,12 @@ spec:
apiVersion: v1
kind: Service
metadata:
name: infisical-backend-service
name: {{ include "infisical.backend.fullname" . }}
labels:
{{- include "infisical.backend.labels" . | nindent 4 }}
spec:
selector:
app: backend
{{- include "infisical.backend.matchLabels" . | nindent 8 }}
ports:
- protocol: TCP
port: 4000

View File

@ -1,21 +1,21 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ .Release.Name }}-frontend-deployment
name: {{ include "infisical.frontend.fullname" . }}
labels:
app: frontend
{{- include "infisical.frontend.labels" . | nindent 4 }}
spec:
replicas: {{ .Values.frontend.replicaCount }}
selector:
matchLabels:
app: frontend
{{- include "infisical.frontend.matchLabels" . | nindent 6 }}
template:
metadata:
labels:
app: frontend
{{- include "infisical.frontend.matchLabels" . | nindent 8 }}
spec:
containers:
- name: frontend
- name: {{ template "infisical.name" . }}-{{ .Values.frontend.name }}
image: "{{ .Values.frontend.image.repository }}:{{ .Values.frontend.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.frontend.image.pullPolicy }}
{{- if .Values.frontend.kubeSecretRef }}
@ -39,11 +39,13 @@ spec:
apiVersion: v1
kind: Service
metadata:
name: infisical-frontend-service
name: {{ include "infisical.frontend.fullname" . }}
labels:
{{- include "infisical.frontend.labels" . | nindent 4 }}
spec:
type: {{ .Values.frontend.service.type }}
selector:
app: frontend
{{- include "infisical.frontend.matchLabels" . | nindent 8 }}
ports:
- protocol: TCP
port: 3000 # service

View File

@ -26,14 +26,14 @@ spec:
pathType: {{ .Values.ingress.frontend.pathType }}
backend:
service:
name: infisical-frontend-service
name: {{ include "infisical.frontend.fullname" . }}
port:
number: 3000
- path: {{ .Values.ingress.backend.path }}
pathType: {{ .Values.ingress.backend.pathType }}
backend:
service:
name: infisical-backend-service
name: {{ include "infisical.backend.fullname" . }}
port:
number: 4000
{{ end }}

View File

@ -1,22 +1,23 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: mongodb-deployment
name: {{ include "infisical.mongodb.fullname" . }}
labels:
app: mongodb
{{- include "infisical.mongodb.labels" . | nindent 4 }}
spec:
replicas: 1 # Cannot be scaled. To scale, you must set up Stateful Set
selector:
matchLabels:
app: mongodb
{{- include "infisical.mongodb.matchLabels" . | nindent 6 }}
template:
metadata:
labels:
app: mongodb
{{- include "infisical.mongodb.matchLabels" . | nindent 8 }}
spec:
containers:
- name: mongodb
image: mongo
- name: {{ template "infisical.name" . }}-{{ .Values.mongodb.name }}
image: "{{ .Values.mongodb.image.repository }}:{{ .Values.mongodb.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.mongodb.image.pullPolicy }}
ports:
- containerPort: 27017
env:
@ -28,10 +29,12 @@ spec:
apiVersion: v1
kind: Service
metadata:
name: mongodb-service
name: {{ include "infisical.mongodb.fullname" . }}
labels:
{{- include "infisical.mongodb.labels" . | nindent 4 }}
spec:
selector:
app: mongodb
{{- include "infisical.mongodb.matchLabels" . | nindent 8 }}
ports:
- protocol: TCP
port: 27017

View File

@ -3,7 +3,10 @@
# PLEASE REPLACE VALUES/EDIT AS REQUIRED
#####
nameOverride: ""
frontend:
name: frontend
replicaCount: 1
image:
repository: infisical/frontend
@ -17,6 +20,7 @@ frontend:
# nodePort:
backend:
name: backend
replicaCount: 1
image:
repository: infisical/backend
@ -24,6 +28,13 @@ backend:
tag: "latest"
# kubeSecretRef: some-kube-secret-name
mongodb:
name: mongodb
image:
repository: mongo
pullPolicy: IfNotPresent
tag: "latest"
ingress:
enabled: true
annotations: