From 0b7f183a038fc84d29a5a92e62b963ac61f34973 Mon Sep 17 00:00:00 2001 From: duhow Date: Mon, 19 Feb 2024 22:23:36 +0100 Subject: [PATCH] add labels and selectors --- kubernetes/helm/templates/_helpers.tpl | 36 +++++++++++++++++++ kubernetes/helm/templates/ollama-service.yaml | 13 ++++--- .../helm/templates/ollama-statefulset.yaml | 12 ++++--- .../helm/templates/webui-deployment.yaml | 10 +++--- kubernetes/helm/templates/webui-ingress.yaml | 6 ++-- kubernetes/helm/templates/webui-pvc.yaml | 2 +- kubernetes/helm/templates/webui-service.yaml | 19 ++++++---- 7 files changed, 75 insertions(+), 23 deletions(-) diff --git a/kubernetes/helm/templates/_helpers.tpl b/kubernetes/helm/templates/_helpers.tpl index 16a6f947..0ed9ddea 100644 --- a/kubernetes/helm/templates/_helpers.tpl +++ b/kubernetes/helm/templates/_helpers.tpl @@ -5,3 +5,39 @@ {{- define "ollama.name" -}} ollama {{- end -}} + +{{- define "chart.name" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{- define "base.labels" -}} +helm.sh/chart: {{ include "chart.name" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{- define "base.selectorLabels" -}} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end -}} + +{{- define "open-webui.selectorLabels" -}} +{{ include "base.selectorLabels" . }} +app.kubernetes.io/component: {{ .Chart.Name }} +{{- end }} + +{{- define "open-webui.labels" -}} +{{ include "base.labels" . }} +{{ include "open-webui.selectorLabels" . }} +{{- end }} + +{{- define "ollama.selectorLabels" -}} +{{ include "base.selectorLabels" . }} +app.kubernetes.io/component: {{ include "ollama.name" . }} +{{- end }} + +{{- define "ollama.labels" -}} +{{ include "base.labels" . }} +{{ include "ollama.selectorLabels" . }} +{{- end }} diff --git a/kubernetes/helm/templates/ollama-service.yaml b/kubernetes/helm/templates/ollama-service.yaml index a8459b52..f1512c5a 100644 --- a/kubernetes/helm/templates/ollama-service.yaml +++ b/kubernetes/helm/templates/ollama-service.yaml @@ -2,11 +2,16 @@ apiVersion: v1 kind: Service metadata: name: {{ include "ollama.name" . }} + labels: + {{- include "ollama.labels" . | nindent 4 }} spec: - type: {{ .Values.ollama.service.type }} selector: - app: ollama + {{- include "ollama.selectorLabels" . | nindent 4 }} +{{- with .Values.ollama.service }} + type: {{ .type }} ports: - protocol: TCP - port: {{ .Values.ollama.servicePort }} - targetPort: {{ .Values.ollama.servicePort }} + name: http + port: {{ .port }} + targetPort: {{ .containerPort }} +{{- end }} diff --git a/kubernetes/helm/templates/ollama-statefulset.yaml b/kubernetes/helm/templates/ollama-statefulset.yaml index dfbf5ba4..cc37a231 100644 --- a/kubernetes/helm/templates/ollama-statefulset.yaml +++ b/kubernetes/helm/templates/ollama-statefulset.yaml @@ -2,19 +2,21 @@ apiVersion: apps/v1 kind: StatefulSet metadata: name: {{ include "ollama.name" . }} + labels: + {{- include "ollama.labels" . | nindent 4 }} spec: serviceName: {{ include "ollama.name" . }} replicas: {{ .Values.ollama.replicaCount }} selector: matchLabels: - app: ollama + {{- include "ollama.selectorLabels" . | nindent 6 }} template: metadata: labels: - app: ollama + {{- include "ollama.selectorLabels" . | nindent 8 }} spec: containers: - - name: ollama + - name: {{ include "ollama.name" . }} image: {{ .Values.ollama.image }} ports: - containerPort: {{ .Values.ollama.servicePort }} @@ -27,8 +29,8 @@ spec: - name: NVIDIA_DRIVER_CAPABILITIES value: compute,utility {{- end}} - {{- if .Values.ollama.resources }} - resources: {{- toYaml .Values.ollama.resources | nindent 10 }} + {{- with .Values.ollama.resources }} + resources: {{- toYaml . | nindent 10 }} {{- end }} volumeMounts: - name: ollama-volume diff --git a/kubernetes/helm/templates/webui-deployment.yaml b/kubernetes/helm/templates/webui-deployment.yaml index e6242129..4b08da78 100644 --- a/kubernetes/helm/templates/webui-deployment.yaml +++ b/kubernetes/helm/templates/webui-deployment.yaml @@ -2,23 +2,25 @@ apiVersion: apps/v1 kind: Deployment metadata: name: {{ include "open-webui.name" . }} + labels: + {{- include "open-webui.labels" . | nindent 4 }} spec: replicas: 1 selector: matchLabels: - app: open-webui + {{- include "open-webui.selectorLabels" . | nindent 6 }} template: metadata: labels: - app: open-webui + {{- include "open-webui.selectorLabels" . | nindent 8 }} spec: containers: - name: {{ .Chart.Name }} image: {{ .Values.webui.image }} ports: - containerPort: 8080 - {{- if .Values.webui.resources }} - resources: {{- toYaml .Values.webui.resources | nindent 10 }} + {{- with .Values.webui.resources }} + resources: {{- toYaml . | nindent 10 }} {{- end }} volumeMounts: - name: webui-volume diff --git a/kubernetes/helm/templates/webui-ingress.yaml b/kubernetes/helm/templates/webui-ingress.yaml index 18fcd6cc..9d943c07 100644 --- a/kubernetes/helm/templates/webui-ingress.yaml +++ b/kubernetes/helm/templates/webui-ingress.yaml @@ -3,9 +3,11 @@ apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: {{ include "open-webui.name" . }} -{{- if .Values.webui.ingress.annotations }} + labels: + {{- include "open-webui.labels" . | nindent 4 }} +{{- with .Values.webui.ingress.annotations }} annotations: -{{ toYaml .Values.webui.ingress.annotations | trimSuffix "\n" | indent 4 }} + {{- toYaml . | nindent 4 }} {{- end }} spec: rules: diff --git a/kubernetes/helm/templates/webui-pvc.yaml b/kubernetes/helm/templates/webui-pvc.yaml index 2b8d7d1c..711117fb 100644 --- a/kubernetes/helm/templates/webui-pvc.yaml +++ b/kubernetes/helm/templates/webui-pvc.yaml @@ -3,7 +3,7 @@ kind: PersistentVolumeClaim metadata: name: {{ include "open-webui.name" . }} labels: - app: open-webui + {{- include "open-webui.labels" . | nindent 4 }} spec: accessModes: [ "ReadWriteOnce" ] resources: diff --git a/kubernetes/helm/templates/webui-service.yaml b/kubernetes/helm/templates/webui-service.yaml index 7ecf796d..d126968d 100644 --- a/kubernetes/helm/templates/webui-service.yaml +++ b/kubernetes/helm/templates/webui-service.yaml @@ -2,13 +2,18 @@ apiVersion: v1 kind: Service metadata: name: {{ include "open-webui.name" . }} + labels: + {{- include "open-webui.labels" . | nindent 4 }} spec: - type: {{ .Values.webui.service.type }} # Default: NodePort # Use LoadBalancer if you're on a cloud that supports it selector: - app: open-webui + {{- include "open-webui.selectorLabels" . | nindent 4 }} +{{- with .Values.webui.service }} + type: {{ .type }} ports: - - protocol: TCP - port: {{ .Values.webui.servicePort }} - targetPort: {{ .Values.webui.servicePort }} - # If using NodePort, you can optionally specify the nodePort: - # nodePort: 30000 + - protocol: TCP + port: {{ .port }} + targetPort: {{ .containerPort }} + {{- if .nodePort }} + nodePort: {{ .nodePort }} + {{- end }} +{{- end }}