Skip to content

Commit

Permalink
helm-chart: make backend templates more uniform (#7127)
Browse files Browse the repository at this point in the history
<!-- Raise an issue to propose your change
(https://github.com/opencv/cvat/issues).
It helps to avoid duplication of efforts from multiple independent
contributors.
Discuss your ideas with maintainers to be sure that changes will be
approved and merged.
Read the [Contribution
guide](https://opencv.github.io/cvat/docs/contributing/). -->

<!-- Provide a general summary of your changes in the Title above -->

### Motivation and context
<!-- Why is this change required? What problem does it solve? If it
fixes an open
issue, please link to the issue here. Describe your changes in detail,
add
screenshots. -->
The templates for the various backend service deployments differ in many
ways, but a lot of those differences can be eliminated. That way, it
becomes easier to compare different templates, to create new services,
and to make changes across all templates.

Specific differences which are eliminated are as follows:

* Different sets of values are used for customization. This can be
mitigated by putting the specific set of values in a local variable
once. That way, only the variable assignment needs to differ.

* Containers and volumes are named differently. There's no need for
this, since these names are local to a pod. Just name all analogous
containers/volumes the same thing.

* Some deployments use different values for the `app` label. This just
seems incorrect, since they all belong to the same app. Standardize on
`cvat-app` as the value.

* Some deployments forget to check disableDistinctCachePerService. That
seems like a bug.

* There are minor formatting differences.

Ideally I'd like to reduce these templates to just calling one big
shared template with service-specific parameters, but there are still
enough differences between the templates that I don't feel like doing
that just yet.

### How has this been tested?
<!-- Please describe in detail how you tested your changes.
Include details of your testing environment, and the tests you ran to
see how your change affects other areas of the code, etc. -->
`helm template`

### Checklist
<!-- Go over all the following points, and put an `x` in all the boxes
that apply.
If an item isn't applicable for some reason, then ~~explicitly
strikethrough~~ the whole
line. If you don't do that, GitHub will show incorrect progress for the
pull request.
If you're unsure about any of these, don't hesitate to ask. We're here
to help! -->
- [x] I submit my changes into the `develop` branch
- ~~[ ] I have created a changelog fragment~~ <!-- see top comment in
CHANGELOG.md -->
- ~~[ ] I have updated the documentation accordingly~~
- ~~[ ] I have added tests to cover my changes~~
- ~~[ ] I have linked related issues (see [GitHub docs](

https://help.github.com/en/github/managing-your-work-on-github/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword))~~
- ~~[ ] I have increased versions of npm packages if it is necessary

([cvat-canvas](https://github.com/opencv/cvat/tree/develop/cvat-canvas#versioning),

[cvat-core](https://github.com/opencv/cvat/tree/develop/cvat-core#versioning),

[cvat-data](https://github.com/opencv/cvat/tree/develop/cvat-data#versioning)
and

[cvat-ui](https://github.com/opencv/cvat/tree/develop/cvat-ui#versioning))~~

### License

- [x] I submit _my code changes_ under the same [MIT License](
https://github.com/opencv/cvat/blob/develop/LICENSE) that covers the
project.
  Feel free to contact the maintainers if that's a concern.
  • Loading branch information
SpecLad committed Nov 15, 2023
1 parent 401989d commit 8d2d1b1
Show file tree
Hide file tree
Showing 10 changed files with 188 additions and 163 deletions.
5 changes: 5 additions & 0 deletions changelog.d/20231113_174833_roman_refactor_values.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
### Changed

- \[Helm\] All backend-related deployments now use `cvat-app` as the value
for the `app` label
(<https://github.com/opencv/cvat/pull/7127>)
24 changes: 13 additions & 11 deletions helm-chart/templates/cvat_backend/initializer/job.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{{- $localValues := .Values.cvat.backend.initializer -}}

apiVersion: batch/v1
kind: Job
metadata:
Expand All @@ -12,10 +14,10 @@ metadata:
tier: backend
component: initializer
{{- include "cvat.labels" . | nindent 4 }}
{{- with .Values.cvat.backend.initializer.labels }}
{{- with $localValues.labels }}
{{- toYaml . | nindent 4 }}
{{- end }}
{{- with .Values.cvat.backend.initializer.annotations }}
{{- with $localValues.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
Expand All @@ -27,42 +29,42 @@ spec:
tier: backend
component: initializer
{{- include "cvat.labels" . | nindent 8 }}
{{- with .Values.cvat.backend.initializer.labels }}
{{- with $localValues.labels }}
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.cvat.backend.initializer.annotations }}
{{- with $localValues.annotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
spec:
containers:
- name: cvat-app-backend-initializer-container
- name: cvat-backend
image: {{ .Values.cvat.backend.image }}:{{ .Values.cvat.backend.tag }}
imagePullPolicy: {{ .Values.cvat.backend.imagePullPolicy }}
{{- with .Values.cvat.backend.initializer.resources }}
{{- with $localValues.resources }}
resources:
{{- toYaml . | nindent 12 }}
{{- end }}
args: ["init"]
env:
{{ include "cvat.sharedBackendEnv" . | indent 10 }}
{{- with .Values.cvat.backend.initializer.additionalEnv }}
{{- with $localValues.additionalEnv }}
{{- toYaml . | nindent 10 }}
{{- end }}
{{- with .Values.cvat.backend.initializer.additionalVolumeMounts }}
{{- with $localValues.additionalVolumeMounts }}
volumeMounts:
{{- toYaml . | nindent 10 }}
{{- end }}
restartPolicy: OnFailure
{{- with .Values.cvat.backend.initializer.affinity }}
{{- with $localValues.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.cvat.backend.initializer.tolerations }}
{{- with $localValues.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.cvat.backend.initializer.additionalVolumes }}
{{- with $localValues.additionalVolumes }}
volumes:
{{- toYaml . | nindent 8 }}
{{- end }}
Expand Down
42 changes: 22 additions & 20 deletions helm-chart/templates/cvat_backend/server/deployment.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{{- $localValues := .Values.cvat.backend.server -}}

apiVersion: apps/v1
kind: Deployment
metadata:
Expand All @@ -8,21 +10,21 @@ metadata:
tier: backend
component: server
{{- include "cvat.labels" . | nindent 4 }}
{{- with .Values.cvat.backend.server.labels }}
{{- with $localValues.labels }}
{{- toYaml . | nindent 4 }}
{{- end }}
{{- with .Values.cvat.backend.server.annotations }}
{{- with $localValues.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
replicas: {{ .Values.cvat.backend.server.replicas }}
replicas: {{ $localValues.replicas }}
strategy:
type: Recreate
selector:
matchLabels:
{{- include "cvat.labels" . | nindent 6 }}
{{- with .Values.cvat.backend.server.labels }}
{{- with $localValues.labels }}
{{- toYaml . | nindent 6 }}
{{- end }}
app: cvat-app
Expand All @@ -35,40 +37,40 @@ spec:
tier: backend
component: server
{{- include "cvat.labels" . | nindent 8 }}
{{- with .Values.cvat.backend.server.labels }}
{{- with $localValues.labels }}
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.cvat.backend.server.annotations }}
{{- with $localValues.annotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
spec:
containers:
- name: cvat-app-backend-server-container
- name: cvat-backend
image: {{ .Values.cvat.backend.image }}:{{ .Values.cvat.backend.tag }}
imagePullPolicy: {{ .Values.cvat.backend.imagePullPolicy }}
{{- with .Values.cvat.backend.server.resources }}
{{- with $localValues.resources }}
resources:
{{- toYaml . | nindent 12 }}
{{- end }}
args: ["run", "server"]
env:
- name: ALLOWED_HOSTS
value: {{ .Values.cvat.backend.server.envs.ALLOWED_HOSTS | squote}}
value: {{ $localValues.envs.ALLOWED_HOSTS | squote}}
- name: DJANGO_MODWSGI_EXTRA_ARGS
value: {{ .Values.cvat.backend.server.envs.DJANGO_MODWSGI_EXTRA_ARGS}}
value: {{ $localValues.envs.DJANGO_MODWSGI_EXTRA_ARGS}}
- name: IAM_OPA_BUNDLE
value: "1"
{{ include "cvat.sharedBackendEnv" . | indent 10 }}
{{- with .Values.cvat.backend.server.additionalEnv }}
{{- with $localValues.additionalEnv }}
{{- toYaml . | nindent 10 }}
{{- end }}
ports:
- containerPort: 8080
volumeMounts:
{{- if not .Values.cvat.backend.disableDistinctCachePerService }}
- mountPath: /home/django/data/cache
name: cvat-server-backend-cache
name: cvat-backend-per-service-cache
{{- end }}
- mountPath: /home/django/data
name: cvat-backend-data
Expand All @@ -82,23 +84,23 @@ spec:
- mountPath: /home/django/models
name: cvat-backend-data
subPath: models
{{- with .Values.cvat.backend.server.additionalVolumeMounts }}
{{- with $localValues.additionalVolumeMounts }}
{{- toYaml . | nindent 10 }}
{{- end }}
initContainers:
{{- if .Values.cvat.backend.permissionFix.enabled }}
- name: user-data-permission-fix
image: busybox
command: ["/bin/chmod", "-R", "777", "/home/django"]
{{- with .Values.cvat.backend.server.resources }}
{{- with $localValues.resources }}
resources:
{{- toYaml . | nindent 12 }}
{{- end }}
volumeMounts:
{{- if .Values.cvat.backend.defaultStorage.enabled }}
{{- if not .Values.cvat.backend.disableDistinctCachePerService }}
- mountPath: /home/django/data/cache
name: cvat-server-backend-cache
name: cvat-backend-per-service-cache
{{- end }}
- mountPath: /home/django/data
name: cvat-backend-data
Expand All @@ -113,15 +115,15 @@ spec:
name: cvat-backend-data
subPath: models
{{- end }}
{{- with .Values.cvat.backend.server.additionalVolumeMounts }}
{{- with $localValues.additionalVolumeMounts }}
{{- toYaml . | nindent 10 }}
{{- end }}
{{- end }}
{{- with .Values.cvat.backend.server.affinity }}
{{- with $localValues.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.cvat.backend.server.tolerations }}
{{- with $localValues.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
Expand All @@ -131,11 +133,11 @@ spec:
persistentVolumeClaim:
claimName: "{{ .Release.Name }}-backend-data"
{{- if not .Values.cvat.backend.disableDistinctCachePerService }}
- name: cvat-server-backend-cache
- name: cvat-backend-per-service-cache
emptyDir: {}
{{- end }}
{{- end }}
{{- with .Values.cvat.backend.server.additionalVolumes }}
{{- with $localValues.additionalVolumes }}
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.imagePullSecrets }}
Expand Down
49 changes: 25 additions & 24 deletions helm-chart/templates/cvat_backend/utils/deployment.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{{- $localValues := .Values.cvat.backend.utils -}}

apiVersion: apps/v1
kind: Deployment
metadata:
Expand All @@ -8,62 +10,62 @@ metadata:
tier: backend
component: utils
{{- include "cvat.labels" . | nindent 4 }}
{{- with .Values.cvat.backend.utils.labels }}
{{- with $localValues.labels }}
{{- toYaml . | nindent 4 }}
{{- end }}
{{- with .Values.cvat.backend.utils.annotations }}
{{- with $localValues.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
replicas: {{ .Values.cvat.backend.utils.replicas }}
replicas: {{ $localValues.replicas }}
strategy:
type: Recreate
selector:
matchLabels:
{{- include "cvat.labels" . | nindent 6 }}
{{- with .Values.cvat.backend.utils.labels }}
{{- with $localValues.labels }}
{{- toYaml . | nindent 6 }}
{{- end }}
app: cvat-app-utils
app: cvat-app
tier: backend
component: utils
template:
metadata:
labels:
app: cvat-app-utils
app: cvat-app
tier: backend
component: utils
{{- include "cvat.labels" . | nindent 8 }}
{{- with .Values.cvat.backend.utils.labels }}
{{- with $localValues.labels }}
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.cvat.backend.utils.annotations }}
{{- with $localValues.annotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
spec:
containers:
- name: cvat-app-backend-utils-container
- name: cvat-backend
image: {{ .Values.cvat.backend.image }}:{{ .Values.cvat.backend.tag }}
imagePullPolicy: {{ .Values.cvat.backend.imagePullPolicy }}
{{- with .Values.cvat.backend.utils.resources }}
{{- with $localValues.resources }}
resources:
{{- toYaml . | nindent 12 }}
{{- end }}
args: ["run", "utils"]
env:
{{ include "cvat.sharedBackendEnv" . | indent 10 }}
{{- with .Values.cvat.backend.utils.additionalEnv }}
{{- with $localValues.additionalEnv }}
{{- toYaml . | nindent 10 }}
{{- end }}
ports:
- containerPort: 8080
volumeMounts:
{{- if not .Values.cvat.backend.disableDistinctCachePerService }}
{{- if not .Values.cvat.backend.disableDistinctCachePerService }}
- mountPath: /home/django/data/cache
name: cvat-utils-backend-cache
{{- end }}
name: cvat-backend-per-service-cache
{{- end }}
- mountPath: /home/django/data
name: cvat-backend-data
subPath: data
Expand All @@ -76,24 +78,24 @@ spec:
- mountPath: /home/django/models
name: cvat-backend-data
subPath: models
{{- with .Values.cvat.backend.utils.additionalVolumeMounts }}
{{- with $localValues.additionalVolumeMounts }}
{{- toYaml . | nindent 10 }}
{{- end }}
initContainers:
{{- if .Values.cvat.backend.permissionFix.enabled }}
- name: user-data-permission-fix
image: busybox
command: ["/bin/chmod", "-R", "777", "/home/django"]
{{- with .Values.cvat.backend.utils.resources }}
{{- with $localValues.resources }}
resources:
{{- toYaml . | nindent 12 }}
{{- end }}
volumeMounts:
{{- if .Values.cvat.backend.defaultStorage.enabled }}
{{- if not .Values.cvat.backend.disableDistinctCachePerService }}
- mountPath: /home/django/data/cache
name: cvat-utils-backend-cache
{{- end }}
name: cvat-backend-per-service-cache
{{- end }}
- mountPath: /home/django/data
name: cvat-backend-data
subPath: data
Expand All @@ -107,15 +109,15 @@ spec:
name: cvat-backend-data
subPath: models
{{- end }}
{{- with .Values.cvat.backend.utils.additionalVolumeMounts }}
{{- with $localValues.additionalVolumeMounts }}
{{- toYaml . | nindent 10 }}
{{- end }}
{{- end }}
{{- with .Values.cvat.backend.utils.affinity }}
{{- with $localValues.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.cvat.backend.utils.tolerations }}
{{- with $localValues.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
Expand All @@ -124,13 +126,12 @@ spec:
- name: cvat-backend-data
persistentVolumeClaim:
claimName: "{{ .Release.Name }}-backend-data"

{{- if not .Values.cvat.backend.disableDistinctCachePerService }}
- name: cvat-utils-backend-cache
- name: cvat-backend-per-service-cache
emptyDir: {}
{{- end }}
{{- end }}
{{- with .Values.cvat.backend.utils.additionalVolumes }}
{{- with $localValues.additionalVolumes }}
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.imagePullSecrets }}
Expand Down
Loading

0 comments on commit 8d2d1b1

Please sign in to comment.