Skip to content

Commit

Permalink
Fix selectors in charts for service and hpa (#26)
Browse files Browse the repository at this point in the history
* Fix hpa targets

* Fix service selector labels

* Add PYTHONUNBUFFERED to worker

* Separate labels by pod type
  • Loading branch information
Rizato committed Jul 6, 2021
1 parent 48a044b commit 5f3da77
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 13 deletions.
40 changes: 40 additions & 0 deletions chart/templates/_helpers.tpl
Expand Up @@ -50,6 +50,46 @@ app.kubernetes.io/name: {{ include "microengine-webhooks-py.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

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

{{/*
Nginx selector labels
*/}}
{{- define "microengine-webhooks-py.nginx.selectorLabels" -}}
app.kubernetes.io/name: {{ include "microengine-webhooks-py.name" . }}-nginx
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

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

{{/*
Worker selector labels
*/}}
{{- define "microengine-webhooks-py.worker.selectorLabels" -}}
app.kubernetes.io/name: {{ include "microengine-webhooks-py.name" . }}-worker
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
Expand Down
6 changes: 3 additions & 3 deletions chart/templates/nginx.deployment.yaml
Expand Up @@ -3,22 +3,22 @@ kind: Deployment
metadata:
name: {{ include "microengine-webhooks-py.fullname" . }}-nginx
labels:
{{- include "microengine-webhooks-py.labels" . | nindent 4 }}
{{- include "microengine-webhooks-py.nginx.labels" . | nindent 4 }}
spec:
{{- if not .Values.nginx.autoscaling.enabled }}
replicas: {{ .Values.nginx.replicaCount }}
{{- end }}
selector:
matchLabels:
{{- include "microengine-webhooks-py.selectorLabels" . | nindent 6 }}
{{- include "microengine-webhooks-py.nginx.selectorLabels" . | nindent 6 }}
template:
metadata:
{{- with .Values.nginx.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "microengine-webhooks-py.selectorLabels" . | nindent 8 }}
{{- include "microengine-webhooks-py.nginx.selectorLabels" . | nindent 8 }}
spec:
{{- with .Values.nginx.imagePullSecrets }}
imagePullSecrets:
Expand Down
4 changes: 2 additions & 2 deletions chart/templates/nginx.hpa.yaml
Expand Up @@ -4,12 +4,12 @@ kind: HorizontalPodAutoscaler
metadata:
name: {{ include "microengine-webhooks-py.fullname" . }}-nginx
labels:
{{- include "microengine-webhooks-py.labels" . | nindent 4 }}
{{- include "microengine-webhooks-py.nginx.labels" . | nindent 4 }}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ include "microengine-webhooks-py.fullname" . }}
name: {{ include "microengine-webhooks-py.fullname" . }}-nginx
minReplicas: {{ .Values.nginx.autoscaling.minReplicas }}
maxReplicas: {{ .Values.nginx.autoscaling.maxReplicas }}
metrics:
Expand Down
2 changes: 1 addition & 1 deletion chart/templates/nginx.ingress.yaml
Expand Up @@ -10,7 +10,7 @@ kind: Ingress
metadata:
name: {{ $fullName }}-nginx
labels:
{{- include "microengine-webhooks-py.labels" . | nindent 4 }}
{{- include "microengine-webhooks-py.nginx.labels" . | nindent 4 }}
{{- with .Values.nginx.ingress.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
Expand Down
4 changes: 2 additions & 2 deletions chart/templates/nginx.service.yaml
Expand Up @@ -3,7 +3,7 @@ kind: Service
metadata:
name: {{ include "microengine-webhooks-py.fullname" . }}-nginx
labels:
{{- include "microengine-webhooks-py.labels" . | nindent 4 }}
{{- include "microengine-webhooks-py.nginx.labels" . | nindent 4 }}
spec:
type: {{ .Values.nginx.service.type }}
ports:
Expand All @@ -12,4 +12,4 @@ spec:
protocol: TCP
name: http
selector:
{{- include "microengine-webhooks-py.selectorLabels" . | nindent 4 }}
{{- include "microengine-webhooks-py.nginx.selectorLabels" . | nindent 4 }}
8 changes: 5 additions & 3 deletions chart/templates/worker.deployment.yaml
Expand Up @@ -3,22 +3,22 @@ kind: Deployment
metadata:
name: {{ include "microengine-webhooks-py.fullname" . }}-worker
labels:
{{- include "microengine-webhooks-py.labels" . | nindent 4 }}
{{- include "microengine-webhooks-py.worker.labels" . | nindent 4 }}
spec:
{{- if not .Values.worker.autoscaling.enabled }}
replicas: {{ .Values.worker.replicaCount }}
{{- end }}
selector:
matchLabels:
{{- include "microengine-webhooks-py.selectorLabels" . | nindent 6 }}
{{- include "microengine-webhooks-py.worker.selectorLabels" . | nindent 6 }}
template:
metadata:
{{- with .Values.worker.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "microengine-webhooks-py.selectorLabels" . | nindent 8 }}
{{- include "microengine-webhooks-py.worker.selectorLabels" . | nindent 8 }}
spec:
{{- with .Values.worker.imagePullSecrets }}
imagePullSecrets:
Expand All @@ -34,6 +34,8 @@ spec:
image: "{{ .Values.worker.image.repository }}:{{ .Values.worker.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.worker.image.pullPolicy }}
env:
- name: PYTHONUNBUFFERED
value: "1"
- name: CELERY_BROKER_URL
valueFrom:
secretKeyRef:
Expand Down
4 changes: 2 additions & 2 deletions chart/templates/worker.hpa.yaml
Expand Up @@ -4,12 +4,12 @@ kind: HorizontalPodAutoscaler
metadata:
name: {{ include "microengine-webhooks-py.fullname" . }}-worker
labels:
{{- include "microengine-webhooks-py.labels" . | nindent 4 }}
{{- include "microengine-webhooks-py.worker.labels" . | nindent 4 }}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ include "microengine-webhooks-py.fullname" . }}
name: {{ include "microengine-webhooks-py.fullname" . }}-worker
minReplicas: {{ .Values.worker.autoscaling.minReplicas }}
maxReplicas: {{ .Values.worker.autoscaling.maxReplicas }}
metrics:
Expand Down

0 comments on commit 5f3da77

Please sign in to comment.