diff --git a/templates/sync-catalog-deployment.yaml b/templates/sync-catalog-deployment.yaml index e463b346d2ff..ad57a0ef0314 100644 --- a/templates/sync-catalog-deployment.yaml +++ b/templates/sync-catalog-deployment.yaml @@ -94,6 +94,9 @@ spec: {{- if .Values.syncCatalog.consulPrefix}} -consul-service-prefix="{{ .Values.syncCatalog.consulPrefix}}" \ {{- end}} + {{- if .Values.syncCatalog.addK8SNamespaceSuffix}} + -add-k8s-namespace-suffix \ + {{- end}} livenessProbe: httpGet: path: /health/ready diff --git a/test/unit/sync-catalog-deployment.bats b/test/unit/sync-catalog-deployment.bats index 5f7179681b6b..306b7074446f 100755 --- a/test/unit/sync-catalog-deployment.bats +++ b/test/unit/sync-catalog-deployment.bats @@ -371,3 +371,27 @@ load _helpers yq -r '.command | any(contains("consul-k8s acl-init"))' | tee /dev/stderr) [ "${actual}" = "true" ] } + +#-------------------------------------------------------------------- +# addK8SNamespaceSuffix + +@test "syncCatalog/Deployment: k8s namespace suffix enabled 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("-add-k8s-namespace-suffix"))' | tee /dev/stderr) + [ "${actual}" = "true" ] +} + +@test "syncCatalog/Deployment: can set addK8SNamespaceSuffix to false" { + cd `chart_dir` + local actual=$(helm template \ + -x templates/sync-catalog-deployment.yaml \ + --set 'syncCatalog.enabled=true' \ + --set 'syncCatalog.addK8SNamespaceSuffix=false' \ + . | tee /dev/stderr | + yq '.spec.template.spec.containers[0].command | any(contains("-add-k8s-namespace-suffix"))' | tee /dev/stderr) + [ "${actual}" = "false" ] +} diff --git a/values.yaml b/values.yaml index 16f41ee67f65..bc14b2587f48 100644 --- a/values.yaml +++ b/values.yaml @@ -25,7 +25,7 @@ global: # to consul-k8s v0.6.0. If using an older consul-k8s version, you may need to # remove these checks to make the sync work. # If using mesh gateways and bootstrapACLs then must be >= 0.9.0. - imageK8S: "hashicorp/consul-k8s:0.9.4" + imageK8S: "hashicorp/consul-k8s:0.9.5" # Datacenter is the name of the datacenter that the agents should register # as. This shouldn't be changed once the Consul cluster is up and running @@ -271,7 +271,7 @@ client: # https://kubernetes.io/docs/tasks/administer-cluster/dns-custom-nameservers/#configure-stub-domain-and-upstream-dns-servers dns: enabled: "-" - + # Set a predefined cluster IP for the DNS service. # Useful if you need to reference the DNS service's IP # address in CoreDNS config. @@ -335,10 +335,22 @@ syncCatalog: # to all namespaces. k8sSourceNamespace: null - # consulPrefix is the service prefix which preprends itself + # addK8SNamespaceSuffix appends Kubernetes namespace suffix to + # each service name synced to Consul, separated by a dash. + # For example, for a service 'foo' in the default namespace, + # the sync process will create a Consul service named 'foo-default'. + # Set this flag to true to avoid registering services with the same name + # but in different namespaces as instances for the same Consul service. + # Namespace suffix is not added if 'annotationServiceName' is provided. + addK8SNamespaceSuffix: true + + # consulPrefix is the service prefix which prepends itself # to Kubernetes services registered within Consul - # For example, "k8s-" will register all services peprended with "k8s-". + # For example, "k8s-" will register all services prepended with "k8s-". # (Kubernetes -> Consul sync) + # consulPrefix is ignored when 'annotationServiceName' is provided. + # NOTE: Updating this property to a non-null value for an existing installation will result in deregistering + # of existing services in Consul and registering them with a new name. consulPrefix: null # k8sTag is an optional tag that is applied to all of the Kubernetes services