Skip to content

Commit

Permalink
syncCatalog: expose add-k8s-namespace-suffix flag (hashicorp#280)
Browse files Browse the repository at this point in the history
* syncCatalog: add `addK8SNamespaceSuffix` property and set it to true by default.
   This is a breaking change because an upgrade to this version will unregister all services 
   in Consul and register them with a new name.
  • Loading branch information
ishustava authored Dec 6, 2019
1 parent f589822 commit 11b76fb
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
3 changes: 3 additions & 0 deletions templates/sync-catalog-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions test/unit/sync-catalog-deployment.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
}
20 changes: 16 additions & 4 deletions values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 11b76fb

Please sign in to comment.