Skip to content

Commit

Permalink
Chart refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
sd109 committed Nov 11, 2024
1 parent 5ea88b3 commit fecd477
Show file tree
Hide file tree
Showing 11 changed files with 86 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ __pycache__/
**/.ruff_cache

# Ignore local dev helpers
test-values.y[a]ml
**/dev-values.yml
**venv*/

# Helm chart stuff
Expand Down
2 changes: 1 addition & 1 deletion charts/flux-image-gen/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ version: 0.1.0
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "4339cc5"
appVersion: "02aeef3"
13 changes: 13 additions & 0 deletions charts/flux-image-gen/ci/test-values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
models:
- flux-dev
- flux-schnell
api:
# Run in dev mode so that we skip
# the image gen step and can therefore
# test in a kind cluster
commandOverride:
- fastapi
- dev
- stackhpc-app/api_server.py
- --host
- "0.0.0.0"
10 changes: 9 additions & 1 deletion charts/flux-image-gen/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,20 @@ app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Selector labels
Model selector labels
*/}}
{{- define "flux-image-gen.modelLabels" -}}
app.kubernetes.io/component: {{ . }}-api
{{- end }}

{{/*
UI selector labels
*/}}
{{- define "flux-image-gen.uiLabels" -}}
app.kubernetes.io/component: {{ .Release.Name }}-ui
{{- end }}


{{/*
Create the name of the service account to use
*/}}
Expand Down
6 changes: 6 additions & 0 deletions charts/flux-image-gen/templates/api/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ spec:
{{- toYaml $.Values.api.securityContext | nindent 12 }}
image: "{{ $.Values.image.repository }}:{{ $.Values.image.tag | default $.Chart.AppVersion }}"
imagePullPolicy: {{ $.Values.image.pullPolicy }}
{{- with $.Values.api.commandOverride }}
{{- if . }}
command:
{{- . | toYaml | nindent 12 }}
{{- end }}
{{- end }}
ports:
- name: http
containerPort: {{ $.Values.api.service.port }}
Expand Down
22 changes: 22 additions & 0 deletions charts/flux-image-gen/templates/tests/gradio-api.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
apiVersion: batch/v1
kind: Job
metadata:
name: gradio-client-test
annotations:
"helm.sh/hook": test
spec:
template:
spec:
containers:
- name: gradio-client
image: "{{ $.Values.image.repository }}:{{ $.Values.image.tag | default $.Chart.AppVersion }}"
command:
- python
- stackhpc-app/test_client.py
env:
- name: GRADIO_HOST
value: {{ printf "http://%s-ui.%s.svc:%v" (include "flux-image-gen.fullname" .) .Release.Namespace .Values.ui.service.port }}
- name: FLUX_MODEL
value: {{ .Values.models | first }}
restartPolicy: Never
backoffLimit: 3
15 changes: 0 additions & 15 deletions charts/flux-image-gen/templates/tests/test-connection.yaml

This file was deleted.

14 changes: 14 additions & 0 deletions charts/flux-image-gen/templates/ui/configmap.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Release.Name }}-ui-config
labels:
{{- include "flux-image-gen.labels" . | nindent 4 }}
data:
gradio_config.yaml: |
models:
{{- range $model := .Values.models }}
- name: {{ . }}
address: {{ printf "http://%s.%s.svc:%v" ( printf "%s-%s-api" (include "flux-image-gen.fullname" $) . ) $.Release.Namespace $.Values.api.service.port }}
{{- end -}}
33 changes: 16 additions & 17 deletions charts/flux-image-gen/templates/ui/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ spec:
selector:
matchLabels:
{{- include "flux-image-gen.selectorLabels" . | nindent 6 }}
{{- include "flux-image-gen.uiLabels" . | nindent 6 }}
template:
metadata:
{{- with .Values.ui.podAnnotations }}
Expand All @@ -17,6 +18,7 @@ spec:
{{- end }}
labels:
{{- include "flux-image-gen.labels" . | nindent 8 }}
{{- include "flux-image-gen.uiLabels" . | nindent 8 }}
{{- with .Values.ui.podLabels }}
{{- toYaml . | nindent 8 }}
{{- end }}
Expand All @@ -35,13 +37,7 @@ spec:
imagePullPolicy: {{ .Values.image.pullPolicy }}
command:
- python
- gradio_ui.py
args:
- --models
- {{ .Values.models | join "," }}
{{- if .Values.ui.extraArgs }}
{{- .Values.ui.extraArgs | toYaml | nindent 10 }}
{{- end }}
- stackhpc-app/gradio_ui.py
ports:
- name: http
containerPort: {{ .Values.ui.service.port }}
Expand All @@ -58,26 +54,29 @@ spec:
readinessProbe:
{{- toYaml .Values.ui.readinessProbe | nindent 12 }}
{{- end }}
{{- with .Values.ui.volumeMounts }}
volumeMounts:
- name: app-config
mountPath: /etc/gradio-app/
{{- with .Values.ui.volumeMounts }}
{{- if . -}}
{{- toYaml . | nindent 12 }}
{{- end -}}
{{- end }}
# Make stdout from python visible in k8s logs
tty: true
env:
- name: PYTHONUNBUFFERED
value: "1"
- name: HELM_RELEASE_NAME
value: {{ include "flux-image-gen.fullname" . }}
- name: HELM_RELEASE_NAMESPACE
value: {{ .Release.Namespace }}
{{- with .Values.ui.envFrom }}
envFrom:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with .Values.ui.volumes }}
- name: GRADIO_SERVER_NAME
value: 0.0.0.0
volumes:
- name: app-config
configMap:
name: {{ .Release.Name }}-ui-config
{{- with .Values.ui.volumes }}
{{- if . -}}
{{- toYaml . | nindent 8 }}
{{- end -}}
{{- end }}
{{- with .Values.ui.nodeSelector }}
nodeSelector:
Expand Down
2 changes: 2 additions & 0 deletions charts/flux-image-gen/templates/ui/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ metadata:
name: {{ include "flux-image-gen.fullname" . }}-ui
labels:
{{- include "flux-image-gen.labels" $ | nindent 4 }}
{{- include "flux-image-gen.uiLabels" . | nindent 4 }}
spec:
type: {{ .Values.ui.service.type }}
ports:
Expand All @@ -14,3 +15,4 @@ spec:
name: http
selector:
{{- include "flux-image-gen.selectorLabels" . | nindent 4 }}
{{- include "flux-image-gen.uiLabels" . | nindent 4 }}
5 changes: 2 additions & 3 deletions charts/flux-image-gen/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ nameOverride: ""
fullnameOverride: ""

ui:

extraArgs:

# This is for setting Kubernetes Annotations to a Pod.
# For more information checkout: https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/
podAnnotations: {}
Expand Down Expand Up @@ -132,6 +129,8 @@ api:

affinity: {}

commandOverride:

# This is for setting Kubernetes Annotations to a Pod.
# For more information checkout: https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/
podAnnotations: {}
Expand Down

0 comments on commit fecd477

Please sign in to comment.