From 560c461c9bd818d618e1f08e66d4c721c5a00d94 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 25 Sep 2018 09:10:05 -0500 Subject: [PATCH] ability to specify prefix for catalog sync --- templates/sync-catalog-deployment.yaml | 3 +++ test/unit/sync-catalog-deployment.bats | 24 ++++++++++++++++++++++++ values.yaml | 5 +++++ 3 files changed, 32 insertions(+) diff --git a/templates/sync-catalog-deployment.yaml b/templates/sync-catalog-deployment.yaml index 6568cb9..0eb863b 100644 --- a/templates/sync-catalog-deployment.yaml +++ b/templates/sync-catalog-deployment.yaml @@ -50,5 +50,8 @@ spec: -to-k8s=false \ {{- end }} -consul-domain={{ .Values.global.domain }} \ + {{- if .Values.syncCatalog.k8sPrefix }} + -k8s-service-prefix="{{ .Values.syncCatalog.k8sPrefix}}" \ + {{- end }} -k8s-write-namespace=${NAMESPACE} {{- end }} diff --git a/test/unit/sync-catalog-deployment.bats b/test/unit/sync-catalog-deployment.bats index 17c0f58..b623543 100755 --- a/test/unit/sync-catalog-deployment.bats +++ b/test/unit/sync-catalog-deployment.bats @@ -99,3 +99,27 @@ load _helpers yq '.spec.template.spec.containers[0].command | any(contains("-to-consul"))' | tee /dev/stderr) [ "${actual}" = "false" ] } + +#-------------------------------------------------------------------- +# k8sPrefix + +@test "syncCatalog/Deployment: no k8sPrefix by default" { + cd `chart_dir` + local actual=$(helm template \ + -x templates/sync-catalog-deployment.yaml \ + --set 'syncCatalog.enabled=true' \ + . | tee /dev/stderr | + yq '.spec.template.spec.containers[0].command | any(contains("-k8s-service-prefix"))' | tee /dev/stderr) + [ "${actual}" = "false" ] +} + +@test "syncCatalog/Deployment: can specify k8sPrefix" { + cd `chart_dir` + local actual=$(helm template \ + -x templates/sync-catalog-deployment.yaml \ + --set 'syncCatalog.enabled=true' \ + --set 'syncCatalog.k8sPrefix=foo-' \ + . | tee /dev/stderr | + yq '.spec.template.spec.containers[0].command | any(contains("-k8s-service-prefix=\"foo-\""))' | tee /dev/stderr) + [ "${actual}" = "true" ] +} diff --git a/values.yaml b/values.yaml index 897f77d..f88d989 100644 --- a/values.yaml +++ b/values.yaml @@ -143,6 +143,11 @@ syncCatalog: toConsul: true toK8S: true + # k8sPrefix is the service prefix to prepend to services before registering + # with Kubernetes. For example "consul-" will register all services + # prepended with "consul-". + k8sPrefix: null + # ConnectInject will enable the automatic Connect sidecar injector. connectInject: enabled: false # "-" disable this by default for now until the image is public