-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[DEV-802] Helm chart to deploy agents #10319
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ff1a617
[DEV-802] Helm chart to deploy agents
072b831
Added exit code 0 for deregistration if FUNCTION_ID is missing to pre…
c381a62
removed unnecessary shell call
d575e23
small logic refactor in helpers.tpl
932fab4
Merge branch 'develop' into DEV-802
yaizkazani File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| apiVersion: v2 | ||
| name: cvat-sam2-agent | ||
| description: A chart to deploy CVAT SAM2 Agent. | ||
| type: application | ||
| version: 0.1.0 | ||
| appVersion: "1.0.4" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| === CVAT SAM2 Agent === | ||
|
|
||
| Agent deployed with {{ .Values.agent.replicaCount }} replica(s). | ||
| CVAT URL: {{ .Values.agent.cvat_base_url }} | ||
| Model: {{ .Values.agent.model_id }} | ||
|
|
||
| The function registration job runs as a pre-install/pre-upgrade hook. | ||
| Check its status: | ||
| kubectl get jobs -n {{ .Release.Namespace }} -l app.kubernetes.io/instance={{ .Release.Name }} | ||
|
|
||
| View agent logs: | ||
| kubectl logs -n {{ .Release.Namespace }} -l app.kubernetes.io/name={{ .Chart.Name }},app.kubernetes.io/component!=job -f | ||
|
|
||
| {{- if .Values.agent.cvat_access_token }} | ||
| WARNING: You are using a hardcoded CVAT access token in plain text. This token WILL be visible in the Helm release history and in pod definition. | ||
| Consider using .Values.agent.secret_env to store the token in a Kubernetes Secret for better security. | ||
| NB! this token overrides the value from .Values.agent.secret_env if both are set. | ||
| {{- end }} | ||
38 changes: 38 additions & 0 deletions
38
ai-models/agents_deployment/helm/templates/deployment.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| apiVersion: apps/v1 | ||
| kind: Deployment | ||
| metadata: | ||
| name: {{ include "agent.fullname" . }} | ||
| labels: | ||
| {{- include "agent.labels" . | nindent 4 }} | ||
| spec: | ||
| replicas: {{ .Values.agent.replicaCount }} | ||
| selector: | ||
| matchLabels: | ||
| {{- include "agent.selectorLabels" . | nindent 6 }} | ||
| template: | ||
| metadata: | ||
| labels: | ||
| {{- include "agent.selectorLabels" . | nindent 8 }} | ||
| spec: | ||
| securityContext: | ||
| {{- include "agent.podSecurityContext" . | nindent 8 }} | ||
| containers: | ||
| - name: {{ .Chart.Name }} | ||
| securityContext: | ||
| allowPrivilegeEscalation: false | ||
| {{- include "agent.image" . | nindent 10 }} | ||
| #NB! configMap is created by job.yaml | ||
| envFrom: | ||
| - configMapRef: | ||
| optional: true | ||
SpecLad marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| name: {{ include "agent.fullname" . }}-config | ||
| env: | ||
| {{- include "agent.commonEnv" . | nindent 12 }} | ||
| - name: USE_CUDA | ||
| value: {{ .Values.agent.use_cuda | default "false" | quote }} | ||
| {{- range .Values.agent.envVars }} | ||
| - name: {{ .name }} | ||
| value: {{ .value | quote }} | ||
| {{- end }} | ||
| resources: | ||
| {{- toYaml .Values.agent.resources | nindent 12 }} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| {{/* | ||
| Fully qualified app name (truncated to 63 chars). | ||
| */}} | ||
| {{- define "agent.fullname" -}} | ||
| {{- if .Values.fullnameOverride }} | ||
| {{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} | ||
| {{- else }} | ||
| {{- printf "%s-%s" .Release.Name .Chart.Name | trunc 63 | trimSuffix "-" }} | ||
| {{- end }} | ||
| {{- end }} | ||
|
|
||
| {{/* | ||
| Common labels | ||
| */}} | ||
| {{- define "agent.labels" -}} | ||
| app.kubernetes.io/name: {{ .Chart.Name }} | ||
| app.kubernetes.io/instance: {{ .Release.Name }} | ||
| app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} | ||
| app.kubernetes.io/managed-by: {{ .Release.Service }} | ||
| {{- end }} | ||
|
|
||
| {{/* | ||
| Selector labels | ||
| */}} | ||
| {{- define "agent.selectorLabels" -}} | ||
| app.kubernetes.io/name: {{ .Chart.Name }} | ||
| app.kubernetes.io/instance: {{ .Release.Name }} | ||
| {{- end }} | ||
|
|
||
| {{/* | ||
| Job selector labels | ||
| */}} | ||
| {{- define "agent.jobSelectorLabels" -}} | ||
| app.kubernetes.io/name: {{ .Chart.Name }} | ||
| app.kubernetes.io/instance: {{ .Release.Name }} | ||
| app.kubernetes.io/component: job | ||
| {{- end }} | ||
|
|
||
| {{/* | ||
| Common environment variables | ||
| */}} | ||
| {{- define "agent.commonEnv" -}} | ||
| - name: CVAT_BASE_URL | ||
| value: {{ .Values.agent.cvat_base_url | default "https://app.cvat.ai" | quote }} | ||
| {{- if .Values.agent.cvat_access_token }} | ||
| - name: CVAT_ACCESS_TOKEN | ||
| value: {{ .Values.agent.cvat_access_token | quote }} | ||
| {{- end }} | ||
| {{- if not .Values.agent.cvat_access_token }} | ||
yaizkazani marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| {{- range .Values.agent.secret_env }} | ||
| - name: {{ .name }} | ||
| valueFrom: | ||
| secretKeyRef: | ||
| name: {{ .secretName }} | ||
| key: {{ .secretKey }} | ||
| {{- end }} | ||
| {{- end }} | ||
| - name: MODEL_ID | ||
| value: {{ .Values.agent.model_id | quote }} | ||
| - name: NAMESPACE | ||
| value: {{ .Release.Namespace }} | ||
| - name: CONFIGMAP_NAME | ||
| value: {{ include "agent.fullname" . }}-config | ||
| - name: ORG_SLUG | ||
| value: {{ .Values.agent.org_slug | quote }} | ||
| {{- end }} | ||
|
|
||
| {{/* | ||
| Common image/imagePullPolicy | ||
| */}} | ||
|
|
||
| {{- define "agent.image" -}} | ||
| image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" | ||
| imagePullPolicy: {{ .Values.image.pullPolicy }} | ||
| {{- end }} | ||
|
|
||
| {{- define "agent.podSecurityContext" -}} | ||
| runAsNonRoot: true | ||
| runAsUser: 1000 | ||
| runAsGroup: 1000 | ||
SpecLad marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| {{- end }} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| apiVersion: batch/v1 | ||
| kind: Job | ||
| metadata: | ||
| name: {{ include "agent.fullname" . }}-function-registration | ||
| labels: | ||
| {{- include "agent.labels" . | nindent 4 }} | ||
| annotations: | ||
| "helm.sh/hook": pre-install, pre-upgrade | ||
| "helm.sh/hook-delete-policy": before-hook-creation | ||
| "helm.sh/hook-weight": "0" | ||
| spec: | ||
| backoffLimit: {{ .Values.job.backoffLimit | default 3 }} | ||
| ttlSecondsAfterFinished: {{ .Values.job.ttlSecondsAfterFinished | default 300 }} | ||
| template: | ||
| metadata: | ||
| labels: | ||
| {{- include "agent.jobSelectorLabels" . | nindent 8 }} | ||
| spec: | ||
| securityContext: | ||
| {{- include "agent.podSecurityContext" . | nindent 8 }} | ||
| serviceAccountName: {{ include "agent.fullname" . }}-job-sa | ||
| restartPolicy: Never | ||
| containers: | ||
| - name: function-registration | ||
| securityContext: | ||
| allowPrivilegeEscalation: false | ||
| {{- include "agent.image" . | nindent 10 }} | ||
| command: ["./function_registration.sh"] | ||
| env: | ||
| {{- include "agent.commonEnv" . | nindent 12 }} | ||
| {{- range .Values.job.envVars }} | ||
| - name: {{ .name }} | ||
| value: {{ .value | quote }} | ||
| {{- end }} | ||
| resources: | ||
| {{- toYaml .Values.job.resources | nindent 12 }} |
40 changes: 40 additions & 0 deletions
40
ai-models/agents_deployment/helm/templates/job_cleanup.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| apiVersion: batch/v1 | ||
| kind: Job | ||
| metadata: | ||
| name: {{ include "agent.fullname" . }}-function-deregistration | ||
| labels: | ||
| {{- include "agent.labels" . | nindent 4 }} | ||
| annotations: | ||
| "helm.sh/hook": pre-delete | ||
| "helm.sh/hook-delete-policy": before-hook-creation | ||
| "helm.sh/hook-weight": "0" | ||
| spec: | ||
| backoffLimit: {{ .Values.job.backoffLimit | default 3 }} | ||
| ttlSecondsAfterFinished: {{ .Values.job.ttlSecondsAfterFinished | default 300 }} | ||
| template: | ||
| metadata: | ||
| labels: | ||
| {{- include "agent.jobSelectorLabels" . | nindent 8 }} | ||
| spec: | ||
| securityContext: | ||
| {{- include "agent.podSecurityContext" . | nindent 8 }} | ||
| serviceAccountName: {{ include "agent.fullname" . }}-job-sa | ||
| restartPolicy: Never | ||
| containers: | ||
| - name: function-deregistration | ||
| securityContext: | ||
| allowPrivilegeEscalation: false | ||
| {{- include "agent.image" . | nindent 10 }} | ||
| command: ["./function_deregistration.sh"] | ||
| envFrom: | ||
| - configMapRef: | ||
| optional: true | ||
| name: {{ include "agent.fullname" . }}-config | ||
| env: | ||
| {{- include "agent.commonEnv" . | nindent 12 }} | ||
| {{- range .Values.job.envVars }} | ||
| - name: {{ .name }} | ||
| value: {{ .value | quote }} | ||
| {{- end }} | ||
| resources: | ||
| {{- toYaml .Values.job.resources | nindent 12 }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| apiVersion: rbac.authorization.k8s.io/v1 | ||
| kind: Role | ||
| metadata: | ||
| name: {{ include "agent.fullname" . }}-job-role | ||
| labels: | ||
| {{- include "agent.labels" . | nindent 4 }} | ||
| annotations: | ||
| "helm.sh/hook": pre-install, pre-upgrade, pre-delete | ||
| "helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded | ||
| "helm.sh/hook-weight": "-5" | ||
| rules: | ||
| - apiGroups: [""] | ||
| resources: ["configmaps"] | ||
| verbs: ["create", "get", "update", "patch"] | ||
| - apiGroups: [""] | ||
| resources: ["configmaps"] | ||
| resourceNames: ["{{ include "agent.fullname" . }}-config"] | ||
| verbs: ["delete"] | ||
|
|
||
| # You cannot restrict [...] or top-level create requests by resource name. | ||
| # For create, this limitation is because the name of the new object may not be known at authorization time. | ||
| # https://kubernetes.io/docs/reference/access-authn-authz/rbac/ |
18 changes: 18 additions & 0 deletions
18
ai-models/agents_deployment/helm/templates/job_rolebinding.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| apiVersion: rbac.authorization.k8s.io/v1 | ||
| kind: RoleBinding | ||
| metadata: | ||
| name: {{ include "agent.fullname" . }}-job-rolebinding | ||
| labels: | ||
| {{- include "agent.labels" . | nindent 4 }} | ||
| annotations: | ||
| "helm.sh/hook": pre-install, pre-upgrade, pre-delete | ||
| "helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded | ||
| "helm.sh/hook-weight": "-5" | ||
| roleRef: | ||
| apiGroup: rbac.authorization.k8s.io | ||
| kind: Role | ||
| name: {{ include "agent.fullname" . }}-job-role | ||
| subjects: | ||
| - kind: ServiceAccount | ||
| name: {{ include "agent.fullname" . }}-job-sa | ||
| namespace: {{ .Release.Namespace }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| apiVersion: v1 | ||
| kind: ServiceAccount | ||
| metadata: | ||
| name: {{ include "agent.fullname" . }}-job-sa | ||
| labels: | ||
| {{- include "agent.labels" . | nindent 4 }} | ||
| annotations: | ||
| "helm.sh/hook": pre-install, pre-upgrade, pre-delete | ||
| "helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded | ||
| "helm.sh/hook-weight": "-5" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| fullnameOverride: "sam2-agent" | ||
|
|
||
| # Please replace with your Docker image URL that contains the SAM2 agent implementation. | ||
| # TODO replace with our actual public image URL once it's available. | ||
| image: | ||
| repository: "" | ||
| tag: "" | ||
| pullPolicy: IfNotPresent | ||
|
|
||
| agent: | ||
| # Please replace with your actual CVAT instance URL. | ||
| cvat_base_url: "https://app.cvat.ai" | ||
| # You can provide the CVAT access token directly here, but it's recommended to use Kubernetes Secrets for better security. | ||
| # If you choose to use a secret, make sure to create it in your cluster and reference it in the `secret_env` section below. | ||
| # Token takes precedence over the secret, so if both are provided, the value here will be used. | ||
| cvat_access_token: "" | ||
| # Please specify the model ID you want to use. You can find available models on Hugging Face, ex: https://huggingface.co/models?search=facebook%2Fsam2. | ||
| model_id: "facebook/sam2-hiera-tiny" | ||
| # Please specify the number of agent replicas you want to deploy. | ||
| replicaCount: 1 | ||
| org_slug: "" | ||
| use_cuda: false | ||
| # TODO need to find out optimal recommended resources. | ||
| resources: | ||
| limits: | ||
| cpu: 1 | ||
| # memory: 1.5Gi | ||
| requests: | ||
| cpu: 200m | ||
| memory: 256Mi | ||
| envVars: [] | ||
| # - name: EXAMPLE_ENV_VAR | ||
yaizkazani marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # value: true | ||
| secret_env: | ||
| - name: CVAT_ACCESS_TOKEN | ||
| secretName: cvat-agent | ||
| secretKey: token | ||
|
|
||
| job: | ||
| resources: | ||
| limits: | ||
| cpu: 1 | ||
| memory: 1Gi | ||
| requests: | ||
| cpu: 400m | ||
| memory: 256Mi | ||
| envVars: [] | ||
| # - name: EXAMPLE_ENV_VAR | ||
| # value: true | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.