diff --git a/charts/sourcegraph-executor/dind/templates/_helpers.tpl b/charts/sourcegraph-executor/dind/templates/_helpers.tpl index d2797759..e3fc4362 100644 --- a/charts/sourcegraph-executor/dind/templates/_helpers.tpl +++ b/charts/sourcegraph-executor/dind/templates/_helpers.tpl @@ -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 }} diff --git a/charts/sourcegraph-executor/dind/templates/executor/executor.Deployment.yaml b/charts/sourcegraph-executor/dind/templates/executor/executor.Deployment.yaml index ab058fab..85145ab9 100644 --- a/charts/sourcegraph-executor/dind/templates/executor/executor.Deployment.yaml +++ b/charts/sourcegraph-executor/dind/templates/executor/executor.Deployment.yaml @@ -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 diff --git a/charts/sourcegraph-executor/dind/templates/executor/executor.Service.yaml b/charts/sourcegraph-executor/dind/templates/executor/executor.Service.yaml index 579af804..c4ef6e01 100644 --- a/charts/sourcegraph-executor/dind/templates/executor/executor.Service.yaml +++ b/charts/sourcegraph-executor/dind/templates/executor/executor.Service.yaml @@ -2,6 +2,7 @@ apiVersion: v1 kind: Service metadata: + name: {{ include "executor.name" . }} annotations: prometheus.io/port: "6060" sourcegraph.prometheus/scrape: "true" @@ -13,7 +14,6 @@ metadata: {{- if .Values.executor.serviceLabels }} {{- toYaml .Values.executor.serviceLabels | nindent 4 }} {{- end }} - name: executor spec: ports: - name: debug diff --git a/charts/sourcegraph-executor/dind/tests/executor_test.yaml b/charts/sourcegraph-executor/dind/tests/executor_test.yaml index 8c972552..8f05b8fa 100644 --- a/charts/sourcegraph-executor/dind/tests/executor_test.yaml +++ b/charts/sourcegraph-executor/dind/tests/executor_test.yaml @@ -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: @@ -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 diff --git a/charts/sourcegraph-executor/dind/tests/privateDockerRegistry_test.yaml b/charts/sourcegraph-executor/dind/tests/privateDockerRegistry_test.yaml index ac3f7138..98622771 100644 --- a/charts/sourcegraph-executor/dind/tests/privateDockerRegistry_test.yaml +++ b/charts/sourcegraph-executor/dind/tests/privateDockerRegistry_test.yaml @@ -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: @@ -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: @@ -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 diff --git a/charts/sourcegraph-executor/k8s/templates/executor.Deployment.yaml b/charts/sourcegraph-executor/k8s/templates/executor.Deployment.yaml index a755dd08..9898b3ae 100644 --- a/charts/sourcegraph-executor/k8s/templates/executor.Deployment.yaml +++ b/charts/sourcegraph-executor/k8s/templates/executor.Deployment.yaml @@ -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: diff --git a/charts/sourcegraph-executor/k8s/tests/executor_test.yaml b/charts/sourcegraph-executor/k8s/tests/executor_test.yaml index b9ef5e6a..8c2af444 100644 --- a/charts/sourcegraph-executor/k8s/tests/executor_test.yaml +++ b/charts/sourcegraph-executor/k8s/tests/executor_test.yaml @@ -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 diff --git a/scripts/ci/validate-schema.sh b/scripts/ci/validate-schema.sh index 62913a25..b85c5f5e 100755 --- a/scripts/ci/validate-schema.sh +++ b/scripts/ci/validate-schema.sh @@ -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"