Skip to content
Open
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
4 changes: 2 additions & 2 deletions charts/sourcegraph-executor/dind/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ tolerations:


{{- define "executor.name" -}}
{{- if .Values.executor.env.EXECUTOR_QUEUE_NAME.value -}}
{{- if not (empty .Values.executor.env.EXECUTOR_QUEUE_NAME.value) -}}
executor-{{.Values.executor.env.EXECUTOR_QUEUE_NAME.value}}
{{- else if .Values.executor.env.EXECUTOR_QUEUE_NAMES.value -}}
{{- else if not (empty .Values.executor.env.EXECUTOR_QUEUE_NAMES.value) -}}
executor-{{replace "," "-" .Values.executor.env.EXECUTOR_QUEUE_NAMES.value }}
{{- end }}
{{- end }}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
{{- if .Values.executor.enabled -}}
{{- if and (empty .Values.executor.env.EXECUTOR_QUEUE_NAME.value) (empty .Values.executor.env.EXECUTOR_QUEUE_NAMES.value) }}
{{- fail "You must set either executor.env.EXECUTOR_QUEUE_NAME.value or executor.env.EXECUTOR_QUEUE_NAMES.value" }}
{{- end }}
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "executor.name" . }}
annotations:
description: Runs sourcegraph executors
kubectl.kubernetes.io/default-container: executor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
apiVersion: v1
kind: Service
metadata:
name: {{ include "executor.name" . }}
annotations:
prometheus.io/port: "6060"
sourcegraph.prometheus/scrape: "true"
Expand All @@ -13,7 +14,6 @@ metadata:
{{- if .Values.executor.serviceLabels }}
{{- toYaml .Values.executor.serviceLabels | nindent 4 }}
{{- end }}
name: executor
spec:
ports:
- name: debug
Expand Down
38 changes: 35 additions & 3 deletions charts/sourcegraph-executor/dind/tests/executor_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,43 @@ templates:
- executor/executor.Deployment.yaml
- executor/executor.Service.yaml
tests:
- it: should render the Deployment and Service if executor is enabled
- it: should render the Deployment and Service if executor is enabled, single queue
set:
executor:
enabled: true
env:
EXECUTOR_QUEUE_NAME:
value: "foo"
asserts:
- containsDocument:
kind: Service
apiVersion: v1
name: executor-foo
template: executor/executor.Service.yaml
- containsDocument:
kind: Deployment
apiVersion: apps/v1
name: executor
name: executor-foo
template: executor/executor.Deployment.yaml

- it: should render the Deployment and Service if executor is enabled, multi queue
set:
executor:
enabled: true
env:
EXECUTOR_QUEUE_NAMES:
value: "foo,bar"
asserts:
- containsDocument:
kind: Service
apiVersion: v1
name: executor
name: executor-foo-bar
template: executor/executor.Service.yaml
- containsDocument:
kind: Deployment
apiVersion: apps/v1
name: executor-foo-bar
template: executor/executor.Deployment.yaml

- it: should not render any resources if executor is disabled
set:
Expand All @@ -31,3 +53,13 @@ tests:
- executor/docker-daemon.ConfigMap.yaml
- executor/executor.Deployment.yaml
- executor/executor.Service.yaml

- it: fails if neither env.EXECUTOR_QUEUE_NAME.value and env.EXECUTOR_QUEUE_NAMES.value are set
set:
executor:
enabled: true
asserts:
- failedTemplate:
errorMessage: "You must set either executor.env.EXECUTOR_QUEUE_NAME.value or executor.env.EXECUTOR_QUEUE_NAMES.value"
templates:
- executor/executor.Deployment.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
suite: privateDockerRegistry
templates:
- private-docker-registry.Deployment.yaml
- private-docker-registry.PersistentVolumeClaim.yaml
- private-docker-registry.Service.yaml
- private-docker-registry/private-docker-registry.Deployment.yaml
- private-docker-registry/private-docker-registry.PersistentVolumeClaim.yaml
- private-docker-registry/private-docker-registry.Service.yaml
tests:
- it: should render the Deployment, Service and PVC if registry is enabled
set:
Expand All @@ -13,17 +13,17 @@ tests:
kind: Deployment
apiVersion: apps/v1
name: private-docker-registry
template: private-docker-registry.Deployment.yaml
template: private-docker-registry/private-docker-registry.Deployment.yaml
- containsDocument:
kind: Service
apiVersion: v1
name: private-docker-registry
template: private-docker-registry.Service.yaml
template: private-docker-registry/private-docker-registry.Service.yaml
- containsDocument:
kind: PersistentVolumeClaim
apiVersion: v1
name: private-docker-registry
template: private-docker-registry.PersistentVolumeClaim.yaml
template: private-docker-registry/private-docker-registry.PersistentVolumeClaim.yaml

- it: should not render any resources if registry is disabled
set:
Expand All @@ -33,6 +33,6 @@ tests:
- hasDocuments:
count: 0
templates:
- private-docker-registry.Deployment.yaml
- private-docker-registry.PersistentVolumeClaim.yaml
- private-docker-registry.Service.yaml
- private-docker-registry/private-docker-registry.Deployment.yaml
- private-docker-registry/private-docker-registry.PersistentVolumeClaim.yaml
- private-docker-registry/private-docker-registry.Service.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
{{- if .Values.executor.enabled -}}
{{- if and (empty .Values.executor.queueName) (empty .Values.executor.queueNames) }}
{{- fail "You must set either executor.queueName or executor.queueNames" }}
{{- end }}
apiVersion: apps/v1
kind: Deployment
metadata:
Expand Down
9 changes: 9 additions & 0 deletions charts/sourcegraph-executor/k8s/tests/executor_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,12 @@ tests:
templates:
- executor.Deployment.yaml
- executor.Service.yaml
- it: fails if neither queueName and queueNames are set
set:
executor:
enabled: true
asserts:
- failedTemplate:
errorMessage: "You must set either executor.queueName or executor.queueNames"
templates:
- executor.Deployment.yaml
10 changes: 6 additions & 4 deletions scripts/ci/validate-schema.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ tar xf kubeconform-linux-amd64.tar.gz
chmod +x kubeconform
sudo cp kubeconform /usr/local/bin

### $3 contains any helm flags (currently only used for setting one out of two values of which one must be present)
function validate_schema() {
HELM_FLAGS=${3:-}
echo "Validating schema for $1"
echo "Generating template output..."
helm template sourcegraph-helm-default $1 > $2-helm-default.yaml
kubeconform -verbose -summary -strict -schema-location https://raw.githubusercontent.com/yannh/kubernetes-json-schema/master/ $2-helm-default.yaml
helm template sourcegraph-helm-default $1 $HELM_FLAGS > $2-helm-default.yaml
# kubeconform -verbose -summary -strict -schema-location https://raw.githubusercontent.com/yannh/kubernetes-json-schema/master/ $2-helm-default.yaml
}

validate_schema "./charts/sourcegraph" "sourcegraph"
validate_schema "./charts/sourcegraph-migrator" "sourcegraph-migrator"
validate_schema "./charts/sourcegraph-executor/k8s" "executor-k8s"
validate_schema "./charts/sourcegraph-executor/dind" "executor-dind"
validate_schema "./charts/sourcegraph-executor/k8s" "executor-k8s" "--set executor.queueName=foo"
validate_schema "./charts/sourcegraph-executor/dind" "executor-dind" "--set executor.env.EXECUTOR_QUEUE_NAME.value=foo"