Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions charts/sourcegraph-executor/k8s/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,31 +69,38 @@ In addition to the documented values, the `executor` and `private-docker-registr
| executor.image.defaultTag | string | `<appVersion>@sha256:<digest>`, 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.containerSecurityContext | object | `{}` | Security context for job containers, as YAML. e.g. set `allowPrivilegeEscalation: false`, `capabilities: {drop: [ALL]}`, and `seccompProfile: {type: RuntimeDefault}` for Pod Security Admission `restricted` namespaces. |
| 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. |
| executor.kubernetesJob.node.requiredAffinityMatchExpressions | string | `""` | The JSON encoded required affinity match expressions for Kubernetes Jobs. e.g. '[{\"key\":\"foo\",\"operator\":\"In\",\"values\":[\"bar\"]}]' |
| executor.kubernetesJob.node.requiredAffinityMatchFields | string | `""` | The JSON encoded required affinity match fields for Kubernetes Jobs. e.g. '[{\"key\":\"foo\",\"operator\":\"In\",\"values\":[\"bar\"]}]' |
| executor.kubernetesJob.node.requiredAffinityMatchExpressions | list | `""` | Required node affinity match expressions for job pods, as a YAML list. e.g. `[{key: foo, operator: In, values: [bar]}]` |
| executor.kubernetesJob.node.requiredAffinityMatchFields | list | `""` | Required node affinity match fields for job pods, as a YAML list. e.g. `[{key: metadata.name, operator: In, values: [node-1]}]` |
| executor.kubernetesJob.node.selector | string | `""` | A comma separated list of values to use as a node selector for Kubernetes Jobs. e.g. `foo=bar,app=my-app` |
| executor.kubernetesJob.node.tolerations | string | `""` | The JSON encoded tolerations for Kubernetes Jobs. e.g. '[{\"key\":\"foo\",\"operator\":\"Equal\",\"value\":\"bar\",\"effect\":\"NoSchedule\"}]' |
| 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.node.tolerations | list | `""` | Tolerations for job pods, as a YAML list. e.g. `[{key: foo, operator: Equal, value: bar, effect: NoSchedule}]` |
| executor.kubernetesJob.pod.affinity | list | `""` | Required pod affinity terms for job pods, as a YAML list. e.g. `[{labelSelector: {matchExpressions: [{key: foo, operator: In, values: [bar]}]}, topologyKey: kubernetes.io/hostname}]` |
| executor.kubernetesJob.pod.antiAffinity | list | `""` | Required pod anti-affinity terms for job pods, as a YAML list. e.g. `[{labelSelector: {matchExpressions: [{key: foo, operator: In, values: [bar]}]}, topologyKey: kubernetes.io/hostname}]` |
| executor.kubernetesJob.podSecurityContext | object | `{}` | Security context for job pods, as YAML. When set, it replaces `runAsUser`, `runAsGroup`, and `fsGroup`. learn more from the [Kubernetes documentation](https://kubernetes.io/docs/tasks/configure-pod-container/security-context/) |
| 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"` | |
Expand Down
12 changes: 12 additions & 0 deletions charts/sourcegraph-executor/k8s/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,15 @@ deploy: sourcegraph
sourcegraph-resource-requires: no-cluster-admin
app.kubernetes.io/component: executor
{{- end}}

{{/*
Renders a JSON-encoded ConfigMap value. Lists and maps are encoded with toJson.
Strings are inserted as before, so existing overrides with escaped JSON keep working.
*/}}
{{- define "executor.jsonValue" -}}
{{- if kindIs "string" . -}}
"{{ . }}"
{{- else -}}
{{ toJson . | quote }}
{{- end -}}
{{- end }}
28 changes: 23 additions & 5 deletions charts/sourcegraph-executor/k8s/templates/executor.ConfigMap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,43 @@ 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 }}"
EXECUTOR_KUBERNETES_NODE_TOLERATIONS: "{{ .Values.executor.kubernetesJob.node.tolerations }}"
EXECUTOR_KUBERNETES_NODE_REQUIRED_AFFINITY_MATCH_EXPRESSIONS: "{{ .Values.executor.kubernetesJob.node.requiredAffinityMatchExpressions }}"
EXECUTOR_KUBERNETES_NODE_REQUIRED_AFFINITY_MATCH_FIELDS: "{{ .Values.executor.kubernetesJob.node.requiredAffinityMatchFields }}"
EXECUTOR_KUBERNETES_NODE_TOLERATIONS: {{ include "executor.jsonValue" .Values.executor.kubernetesJob.node.tolerations }}
EXECUTOR_KUBERNETES_NODE_REQUIRED_AFFINITY_MATCH_EXPRESSIONS: {{ include "executor.jsonValue" .Values.executor.kubernetesJob.node.requiredAffinityMatchExpressions }}
EXECUTOR_KUBERNETES_NODE_REQUIRED_AFFINITY_MATCH_FIELDS: {{ include "executor.jsonValue" .Values.executor.kubernetesJob.node.requiredAffinityMatchFields }}

EXECUTOR_KUBERNETES_POD_AFFINITY: "{{ .Values.executor.kubernetesJob.pod.affinity }}"
EXECUTOR_KUBERNETES_POD_ANTI_AFFINITY: "{{ .Values.executor.kubernetesJob.pod.antiAffinity }}"
EXECUTOR_KUBERNETES_POD_AFFINITY: {{ include "executor.jsonValue" .Values.executor.kubernetesJob.pod.affinity }}
EXECUTOR_KUBERNETES_POD_ANTI_AFFINITY: {{ include "executor.jsonValue" .Values.executor.kubernetesJob.pod.antiAffinity }}

EXECUTOR_KUBERNETES_RESOURCE_REQUEST_CPU: "{{ .Values.executor.kubernetesJob.resources.requests.cpu }}"
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 }}"
KUBERNETES_RUN_AS_GROUP: "{{ .Values.executor.kubernetesJob.runAsGroup }}"
KUBERNETES_FS_GROUP: "{{ .Values.executor.kubernetesJob.fsGroup }}"
{{- with .Values.executor.kubernetesJob.podSecurityContext }}
KUBERNETES_EXECUTOR_POD_SECURITY_CONTEXT: {{ toJson . | quote }}
{{- end }}
{{- with .Values.executor.kubernetesJob.containerSecurityContext }}
KUBERNETES_EXECUTOR_CONTAINER_SECURITY_CONTEXT: {{ toJson . | quote }}
{{- end }}

EXECUTOR_DOCKER_ADD_HOST_GATEWAY: "{{.Values.executor.dockerAddHostGateway }}"
KUBERNETES_KEEP_JOBS: "{{ .Values.executor.debug.keepJobs }}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
108 changes: 108 additions & 0 deletions charts/sourcegraph-executor/k8s/tests/executor_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,111 @@ 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

- it: should render job scheduling and security contexts given as YAML as JSON
template: executor.ConfigMap.yaml
set:
executor:
queueName: "test"
kubernetesJob:
podSecurityContext:
runAsNonRoot: true
fsGroup: 1000
containerSecurityContext:
allowPrivilegeEscalation: false
capabilities:
drop: [ALL]
node:
tolerations:
- key: dedicated
operator: Equal
value: executor-jobs
effect: NoSchedule
pod:
antiAffinity:
- labelSelector:
matchLabels:
app: foo
topologyKey: kubernetes.io/hostname
asserts:
- equal:
path: data.KUBERNETES_EXECUTOR_POD_SECURITY_CONTEXT
value: '{"fsGroup":1000,"runAsNonRoot":true}'
- equal:
path: data.KUBERNETES_EXECUTOR_CONTAINER_SECURITY_CONTEXT
value: '{"allowPrivilegeEscalation":false,"capabilities":{"drop":["ALL"]}}'
- equal:
path: data.EXECUTOR_KUBERNETES_NODE_TOLERATIONS
value: '[{"effect":"NoSchedule","key":"dedicated","operator":"Equal","value":"executor-jobs"}]'
- equal:
path: data.EXECUTOR_KUBERNETES_POD_ANTI_AFFINITY
value: '[{"labelSelector":{"matchLabels":{"app":"foo"}},"topologyKey":"kubernetes.io/hostname"}]'

- it: should still accept escaped JSON strings for job scheduling values
template: executor.ConfigMap.yaml
set:
executor:
queueName: "test"
kubernetesJob:
node:
tolerations: '[{\"key\":\"dedicated\",\"operator\":\"Exists\"}]'
asserts:
- equal:
path: data.EXECUTOR_KUBERNETES_NODE_TOLERATIONS
value: '[{"key":"dedicated","operator":"Exists"}]'
- notExists:
path: data.KUBERNETES_EXECUTOR_POD_SECURITY_CONTEXT
33 changes: 27 additions & 6 deletions charts/sourcegraph-executor/k8s/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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.
Expand All @@ -103,34 +113,45 @@ executor:
runAsGroup:
# -- The group ID which is set on the job PVC file system.
fsGroup: "1000"
# -- Security context for job pods, as YAML.
# When set, it replaces `runAsUser`, `runAsGroup`, and `fsGroup`.
# learn more from the [Kubernetes documentation](https://kubernetes.io/docs/tasks/configure-pod-container/security-context/)
podSecurityContext: {}
# -- Security context for job containers, as YAML.
# e.g. set `allowPrivilegeEscalation: false`, `capabilities: {drop: [ALL]}`, and `seccompProfile: {type: RuntimeDefault}` for Pod Security Admission `restricted` namespaces.
containerSecurityContext: {}
resources:
requests:
# -- The requested CPU for a job.
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.
name: ""
# -- A comma separated list of values to use as a node selector for Kubernetes Jobs. e.g. `foo=bar,app=my-app`
selector: ""
# -- The JSON encoded tolerations for Kubernetes Jobs. e.g. '[{\"key\":\"foo\",\"operator\":\"Equal\",\"value\":\"bar\",\"effect\":\"NoSchedule\"}]'
# -- (list) Tolerations for job pods, as a YAML list. e.g. `[{key: foo, operator: Equal, value: bar, effect: NoSchedule}]`
tolerations: ""
# -- The JSON encoded required affinity match expressions for Kubernetes Jobs. e.g. '[{\"key\":\"foo\",\"operator\":\"In\",\"values\":[\"bar\"]}]'
# -- (list) Required node affinity match expressions for job pods, as a YAML list. e.g. `[{key: foo, operator: In, values: [bar]}]`
requiredAffinityMatchExpressions: ""
# -- The JSON encoded required affinity match fields for Kubernetes Jobs. e.g. '[{\"key\":\"foo\",\"operator\":\"In\",\"values\":[\"bar\"]}]'
# -- (list) Required node affinity match fields for job pods, as a YAML list. e.g. `[{key: metadata.name, operator: In, values: [node-1]}]`
requiredAffinityMatchFields: ""

pod:
# -- The JSON encoded pod affinity for Kubernetes Jobs. e.g. '[{\"labelSelector\": {\"matchExpressions\": [{\"key\": \"foo\",\"operator\": \"In\",\"values\": [\"bar\"]}]},\"topologyKey\": \"kubernetes.io/hostname\"}]'
# -- (list) Required pod affinity terms for job pods, as a YAML list. e.g. `[{labelSelector: {matchExpressions: [{key: foo, operator: In, values: [bar]}]}, topologyKey: kubernetes.io/hostname}]`
affinity: ""
# -- The JSON encoded pod anti-affinity for Kubernetes Jobs. e.g. '[{\"labelSelector\": {\"matchExpressions\": [{\"key\": \"foo\",\"operator\": \"In\",\"values\": [\"bar\"]}]},\"topologyKey\": \"kubernetes.io/hostname\"}]'
# -- (list) Required pod anti-affinity terms for job pods, as a YAML list. e.g. `[{labelSelector: {matchExpressions: [{key: foo, operator: In, values: [bar]}]}, topologyKey: kubernetes.io/hostname}]`
antiAffinity: ""

debug:
Expand Down
Loading
Loading