From 50da1d60b52216b189ae94032600196172c15d06 Mon Sep 17 00:00:00 2001 From: Marc LeBlanc <7050295+marcleblanc2@users.noreply.github.com> Date: Mon, 23 Nov 2026 19:50:13 -0500 Subject: [PATCH 1/3] executor/k8s: Restore replicas, add Kubernetes client limits and job ephemeral storage The chart hardcoded replicas: 1 with a comment saying executor pods pin job pods to their node and contend for a ReadWriteOnce PVC. Neither is true: the chart never sets EXECUTOR_KUBERNETES_NODE_NAME by default, and #911 removed that PVC. Executors dequeue with SKIP LOCKED, have unique names, and give each job its own pod and workspace volume, so several executor pods can serve the same queues. - executor.replicas, default 1 - executor.kubernetesClient.qps / burst, rendered only when set, for EXECUTOR_KUBERNETES_CLIENT_QPS / BURST - executor.kubernetesJob.resources.{requests,limits}.ephemeralStorage, rendered only when set Amp-Thread-ID: https://ampcode.com/threads/T-01a20ade-0ba8-7364-b673-ac2197c102c9 Co-authored-by: Amp --- charts/sourcegraph-executor/k8s/README.md | 7 ++- .../k8s/templates/executor.ConfigMap.yaml | 12 +++++ .../k8s/templates/executor.Deployment.yaml | 5 +- .../k8s/tests/executor_test.yaml | 54 +++++++++++++++++++ charts/sourcegraph-executor/k8s/values.yaml | 16 +++++- charts/sourcegraph/CHANGELOG.md | 3 ++ 6 files changed, 91 insertions(+), 6 deletions(-) diff --git a/charts/sourcegraph-executor/k8s/README.md b/charts/sourcegraph-executor/k8s/README.md index 67bae6cc3..b88e58541 100644 --- a/charts/sourcegraph-executor/k8s/README.md +++ b/charts/sourcegraph-executor/k8s/README.md @@ -69,6 +69,8 @@ In addition to the documented values, the `executor` and `private-docker-registr | executor.image.defaultTag | string | `@sha256:`, pinned by each release | Docker image tag for the `executor-kubernetes` image | | executor.image.name | string | `"executor-kubernetes"` | | | executor.kubeconfigPath | string | `""` | The path to the kubeconfig file. If not specified, the in-cluster config is used. | +| executor.kubernetesClient.burst | int | `100`, the executor's default | The maximum burst of queries from each executor pod to the Kubernetes API, above `qps`. | +| executor.kubernetesClient.qps | number | `50`, the executor's default | The maximum queries per second from each executor pod to the Kubernetes API, shared by all of its jobs. Each job makes about 10 API calls. | | executor.kubernetesJob.deadline | string | `"1200"` | The number of seconds after which a Kubernetes job will be terminated. | | executor.kubernetesJob.fsGroup | string | `"1000"` | The group ID which is set on the job PVC file system. | | executor.kubernetesJob.node.name | string | `""` | The name of the Kubernetes Node to create job pods on. If not specified, the pods are created on the first available node. | @@ -79,21 +81,24 @@ In addition to the documented values, the `executor` and `private-docker-registr | executor.kubernetesJob.pod.affinity | string | `""` | The JSON encoded pod affinity for Kubernetes Jobs. e.g. '[{\"labelSelector\": {\"matchExpressions\": [{\"key\": \"foo\",\"operator\": \"In\",\"values\": [\"bar\"]}]},\"topologyKey\": \"kubernetes.io/hostname\"}]' | | executor.kubernetesJob.pod.antiAffinity | string | `""` | The JSON encoded pod anti-affinity for Kubernetes Jobs. e.g. '[{\"labelSelector\": {\"matchExpressions\": [{\"key\": \"foo\",\"operator\": \"In\",\"values\": [\"bar\"]}]},\"topologyKey\": \"kubernetes.io/hostname\"}]' | | executor.kubernetesJob.resources.limits.cpu | string | `""` | The maximum CPU for a job. | +| executor.kubernetesJob.resources.limits.ephemeralStorage | string | `""` | The maximum ephemeral storage for a job. | | executor.kubernetesJob.resources.limits.memory | string | `"12Gi"` | The maximum memory for a job. | | executor.kubernetesJob.resources.requests.cpu | string | `""` | The requested CPU for a job. | +| executor.kubernetesJob.resources.requests.ephemeralStorage | string | `""` | The requested ephemeral storage for a job. With the default `emptyDir` job volume, set this to at least the job volume size (`KUBERNETES_JOB_VOLUME_SIZE`, default `5Gi`), so the scheduler counts the job volume against the node's disk. | | executor.kubernetesJob.resources.requests.memory | string | `"1Gi"` | The requested memory for a job. | | executor.kubernetesJob.runAsGroup | int | `nil`; accepts [0, 2147483647] | The group ID to run Kubernetes jobs as. | | executor.kubernetesJob.runAsUser | int | `nil`; accepts [0, 2147483647] | The user ID to run Kubernetes jobs as. | | executor.log.format | string | `"condensed"` | | | executor.log.level | string | `"warn"` | Possible values are `dbug`, `info`, `warn`, `eror`, `crit`. | | executor.log.trace | string | `"false"` | | -| executor.maximumNumJobs | int | `10` | The maximum amount of jobs that can be executed concurrently. | +| executor.maximumNumJobs | int | `10` | The maximum amount of jobs that each executor pod can execute concurrently. | | executor.maximumRuntimePerJob | string | `"30m"` | | | executor.namespace | string | `"default"` | The namespace in which jobs are generated by the executor. | | executor.nodeSelector | object | `{}` | NodeSelector, learn more from the [Kubernetes documentation](https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#nodeselector) | | executor.podSecurityContext | object | `{}` | Security context for the pod, learn more from the [Kubernetes documentation](https://kubernetes.io/docs/tasks/configure-pod-container/security-context/#set-the-security-context-for-a-pod) | | executor.queueName | string | `""` | The name of the queue to pull jobs from to. Possible values: batches and codeintel. **Either this or queueNames is required.** | | executor.queueNames | list | `[]` | The names of multiple queues to pull jobs from to. Possible values: batches and codeintel. **Either this or queueName is required.** | +| executor.replicas | int | `1` | Number of executor pods. Each pod dequeues jobs from the same queues and runs up to `maximumNumJobs` of them, so the most jobs that run at once is `replicas` x `maximumNumJobs`. Each pod has its own Kubernetes API rate limit (`kubernetesClient`). | | executor.resources.limits.cpu | string | `"1"` | | | executor.resources.limits.memory | string | `"4Gi"` | | | executor.resources.requests.cpu | string | `"500m"` | | diff --git a/charts/sourcegraph-executor/k8s/templates/executor.ConfigMap.yaml b/charts/sourcegraph-executor/k8s/templates/executor.ConfigMap.yaml index 6e773607b..9c694e16d 100644 --- a/charts/sourcegraph-executor/k8s/templates/executor.ConfigMap.yaml +++ b/charts/sourcegraph-executor/k8s/templates/executor.ConfigMap.yaml @@ -18,6 +18,12 @@ data: EXECUTOR_KUBERNETES_NAMESPACE: "{{ .Values.executor.namespace }}" EXECUTOR_KUBERNETES_CONFIG_PATH: "{{ .Values.executor.kubeconfigPath }}" + {{- with .Values.executor.kubernetesClient.qps }} + EXECUTOR_KUBERNETES_CLIENT_QPS: {{ . | quote }} + {{- end }} + {{- with .Values.executor.kubernetesClient.burst }} + EXECUTOR_KUBERNETES_CLIENT_BURST: {{ . | quote }} + {{- end }} EXECUTOR_KUBERNETES_NODE_NAME: "{{ .Values.executor.kubernetesJob.node.name }}" EXECUTOR_KUBERNETES_NODE_SELECTOR: "{{ .Values.executor.kubernetesJob.node.selector }}" @@ -32,6 +38,12 @@ data: EXECUTOR_KUBERNETES_RESOURCE_REQUEST_MEMORY: "{{ .Values.executor.kubernetesJob.resources.requests.memory }}" EXECUTOR_KUBERNETES_RESOURCE_LIMIT_CPU: "{{ .Values.executor.kubernetesJob.resources.limits.cpu }}" EXECUTOR_KUBERNETES_RESOURCE_LIMIT_MEMORY: "{{ .Values.executor.kubernetesJob.resources.limits.memory }}" + {{- with .Values.executor.kubernetesJob.resources.requests.ephemeralStorage }} + EXECUTOR_KUBERNETES_RESOURCE_REQUEST_EPHEMERAL_STORAGE: {{ . | quote }} + {{- end }} + {{- with .Values.executor.kubernetesJob.resources.limits.ephemeralStorage }} + EXECUTOR_KUBERNETES_RESOURCE_LIMIT_EPHEMERAL_STORAGE: {{ . | quote }} + {{- end }} KUBERNETES_JOB_DEADLINE: "{{ .Values.executor.kubernetesJob.deadline }}" KUBERNETES_RUN_AS_USER: "{{ .Values.executor.kubernetesJob.runAsUser }}" diff --git a/charts/sourcegraph-executor/k8s/templates/executor.Deployment.yaml b/charts/sourcegraph-executor/k8s/templates/executor.Deployment.yaml index 1cb35d2c4..1dbd4d48d 100644 --- a/charts/sourcegraph-executor/k8s/templates/executor.Deployment.yaml +++ b/charts/sourcegraph-executor/k8s/templates/executor.Deployment.yaml @@ -16,10 +16,7 @@ spec: {{- include "sourcegraph.selectorLabels" . | nindent 6 }} app: {{ include "executor.name" . }} minReadySeconds: 10 - # The executor controller is a singleton: it pins Job pods to its own node - # via EXECUTOR_KUBERNETES_NODE_NAME, so running more than one replica does not - # work (replicas contend for the same ReadWriteOnce PVC). Do not make this configurable. - replicas: 1 + replicas: {{ .Values.executor.replicas }} revisionHistoryLimit: 10 strategy: rollingUpdate: diff --git a/charts/sourcegraph-executor/k8s/tests/executor_test.yaml b/charts/sourcegraph-executor/k8s/tests/executor_test.yaml index 256638deb..7d006d973 100644 --- a/charts/sourcegraph-executor/k8s/tests/executor_test.yaml +++ b/charts/sourcegraph-executor/k8s/tests/executor_test.yaml @@ -125,3 +125,57 @@ tests: path: spec.template.spec.securityContext.runAsUser - isNull: path: spec.template.spec.securityContext.runAsGroup + + - it: should render executor.replicas + template: executor.Deployment.yaml + set: + executor: + queueName: "test" + replicas: 3 + asserts: + - equal: + path: spec.replicas + value: 3 + + - it: should leave Kubernetes client limits and ephemeral storage to the executor's defaults when unset + template: executor.ConfigMap.yaml + set: + executor: + queueName: "test" + asserts: + - notExists: + path: data.EXECUTOR_KUBERNETES_CLIENT_QPS + - notExists: + path: data.EXECUTOR_KUBERNETES_CLIENT_BURST + - notExists: + path: data.EXECUTOR_KUBERNETES_RESOURCE_REQUEST_EPHEMERAL_STORAGE + - notExists: + path: data.EXECUTOR_KUBERNETES_RESOURCE_LIMIT_EPHEMERAL_STORAGE + + - it: should render Kubernetes client limits and ephemeral storage when set + template: executor.ConfigMap.yaml + set: + executor: + queueName: "test" + kubernetesClient: + qps: 12.5 + burst: 25 + kubernetesJob: + resources: + requests: + ephemeralStorage: 6Gi + limits: + ephemeralStorage: 8Gi + asserts: + - equal: + path: data.EXECUTOR_KUBERNETES_CLIENT_QPS + value: "12.5" + - equal: + path: data.EXECUTOR_KUBERNETES_CLIENT_BURST + value: "25" + - equal: + path: data.EXECUTOR_KUBERNETES_RESOURCE_REQUEST_EPHEMERAL_STORAGE + value: 6Gi + - equal: + path: data.EXECUTOR_KUBERNETES_RESOURCE_LIMIT_EPHEMERAL_STORAGE + value: 8Gi diff --git a/charts/sourcegraph-executor/k8s/values.yaml b/charts/sourcegraph-executor/k8s/values.yaml index b55767725..8d7564925 100644 --- a/charts/sourcegraph-executor/k8s/values.yaml +++ b/charts/sourcegraph-executor/k8s/values.yaml @@ -66,7 +66,10 @@ executor: queueName: "" # -- The names of multiple queues to pull jobs from to. Possible values: batches and codeintel. **Either this or queueName is required.** queueNames: [ ] - # -- The maximum amount of jobs that can be executed concurrently. + # -- Number of executor pods. Each pod dequeues jobs from the same queues and runs up to `maximumNumJobs` of them, + # so the most jobs that run at once is `replicas` x `maximumNumJobs`. Each pod has its own Kubernetes API rate limit (`kubernetesClient`). + replicas: 1 + # -- The maximum amount of jobs that each executor pod can execute concurrently. maximumNumJobs: 10 # - The maximum wall time that can be spent on a single job. maximumRuntimePerJob: "30m" @@ -81,6 +84,13 @@ executor: namespace: "default" # -- The path to the kubeconfig file. If not specified, the in-cluster config is used. kubeconfigPath: "" + kubernetesClient: + # -- (number) The maximum queries per second from each executor pod to the Kubernetes API, shared by all of its jobs. Each job makes about 10 API calls. + # @default -- `50`, the executor's default + qps: + # -- (int) The maximum burst of queries from each executor pod to the Kubernetes API, above `qps`. + # @default -- `100`, the executor's default + burst: # -- DEPRECATED: Use `executor.containerSecurityContext` or `executor.podSecurityContext` instead. securityContext: # -- DEPRECATED: Use `executor.containerSecurityContext` or `executor.podSecurityContext` instead. @@ -109,11 +119,15 @@ executor: cpu: "" # -- The requested memory for a job. memory: "1Gi" + # -- The requested ephemeral storage for a job. With the default `emptyDir` job volume, set this to at least the job volume size (`KUBERNETES_JOB_VOLUME_SIZE`, default `5Gi`), so the scheduler counts the job volume against the node's disk. + ephemeralStorage: "" limits: # -- The maximum CPU for a job. cpu: "" # -- The maximum memory for a job. memory: "12Gi" + # -- The maximum ephemeral storage for a job. + ephemeralStorage: "" node: # -- The name of the Kubernetes Node to create job pods on. If not specified, the pods are created on the first available node. diff --git a/charts/sourcegraph/CHANGELOG.md b/charts/sourcegraph/CHANGELOG.md index a8b444320..7de38ae48 100644 --- a/charts/sourcegraph/CHANGELOG.md +++ b/charts/sourcegraph/CHANGELOG.md @@ -8,6 +8,9 @@ Use `**BREAKING**:` to denote a breaking change ## Unreleased +- Added `executor.replicas` back to the Kubernetes-native executor chart (`sourcegraph-executor/k8s`), default `1`. Executor pods share their queues safely: each dequeues its own jobs, and job pods run on any node with their own workspace volume, so more replicas run more jobs at once, each pod with its own dequeue loop and Kubernetes API rate limit. The earlier claim that the controller is a singleton dated from the removed shared `/data` PVC. +- Added `executor.kubernetesClient.qps` and `executor.kubernetesClient.burst` to the Kubernetes-native executor chart, which set `EXECUTOR_KUBERNETES_CLIENT_QPS` and `EXECUTOR_KUBERNETES_CLIENT_BURST`. Executors before this release used client-go's limit of 5 requests per second, shared by all of an executor pod's jobs, which slowed every job once dozens ran at once. Unset, they keep the executor's defaults. +- Added `executor.kubernetesJob.resources.requests.ephemeralStorage` and `limits.ephemeralStorage` to the Kubernetes-native executor chart, so the scheduler counts each job's `emptyDir` workspace against the node's disk. Unset by default. - The `correct-data-dir-permissions` init containers of `pgsql`, `codeintel-db`, and `codeinsights-db` now run the database's own image instead of `sourcegraph/alpine-3.14`, which was based on an end-of-life Alpine release. The chart no longer pulls `alpine-3.14`, so private registries no longer need to mirror it. `alpine.image` has been removed and is ignored if set; `alpine.containerSecurityContext`, `alpine.resources`, and `codeInsightsDB.init.containerSecurityContext` still apply. - Added `sourcegraph.selectorLabelsOverride`, `.extraSelectorLabels`, and `storageLabels` on `gitserver`, `grafana`, `indexedSearch`, and `searcher`, so the chart can render the selectors and volume claim templates of workloads created outside it, such as with Kustomize, and a Helm release can take them over without deleting them. All default to empty, so existing releases render the same selectors. Never change them on an installed release: Kubernetes does not allow changing these fields. See [Adopting existing workloads](README.md#adopting-existing-workloads). - Fixed `frontend.command` and `migrator.command` rendering a list as a single element, e.g. `["sh", "-c", "