Skip to content

Commit

Permalink
Merge pull request hashicorp#1024 from hashicorp/apigateway-namespace…
Browse files Browse the repository at this point in the history
…-mirroring

Add support for api gateway + consul namespaces
  • Loading branch information
Jeff-Apple authored Feb 22, 2022
2 parents 06ab056 + ba33055 commit 9daaeba
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ IMPROVEMENTS:
* Vault: Allow passing arbitrary annotations to the vault agent. [[GH-1015](https://github.com/hashicorp/consul-k8s/pull/1015)]
* Vault: Add support for customized IP and DNS SANs for server cert in Vault. [[GH-1020](https://github.com/hashicorp/consul-k8s/pull/1020)]
* Vault: Add support for Enterprise License to be configured in Vault. [[GH-1032](https://github.com/hashicorp/consul-k8s/pull/1032)]
* API Gateway: Allow Kubernetes namespace to Consul enterprise namespace mapping for deployed gateways and mesh services. [[GH-1024](https://github.com/hashicorp/consul-k8s/pull/1024)]

BUG FIXES:
* API Gateway
Expand Down
11 changes: 11 additions & 0 deletions charts/consul/templates/api-gateway-controller-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,17 @@ spec:
consul-api-gateway server \
-sds-server-host {{ template "consul.fullname" . }}-api-gateway-controller.{{ .Release.Namespace }}.svc \
-k8s-namespace {{ .Release.Namespace }} \
{{- if .Values.global.enableConsulNamespaces }}
{{- if .Values.apiGateway.consulNamespaces.consulDestinationNamespace }}
-consul-destination-namespace={{ .Values.apiGateway.consulNamespaces.consulDestinationNamespace }} \
{{- end }}
{{- if .Values.apiGateway.consulNamespaces.mirroringK8S }}
-mirroring-k8s=true \
{{- if .Values.apiGateway.consulNamespaces.mirroringK8SPrefix }}
-mirroring-k8s-prefix={{ .Values.apiGateway.consulNamespaces.mirroringK8SPrefix }} \
{{- end }}
{{- end }}
{{- end }}
-log-level {{ default .Values.global.logLevel .Values.apiGateway.logLevel }} \
volumeMounts:
{{- if .Values.global.tls.enabled }}
Expand Down
38 changes: 38 additions & 0 deletions charts/consul/test/unit/api-gateway-controller-deployment.bats
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,44 @@ load _helpers
.
}

@test "apiGateway/Deployment: enable namespaces" {
cd `chart_dir`
local actual=$(helm template \
-s templates/api-gateway-controller-deployment.yaml \
--set 'apiGateway.enabled=true' \
--set 'apiGateway.image=bar' \
--set 'global.enableConsulNamespaces=true' \
. | tee /dev/stderr |
yq '.spec.template.spec.containers[0].command | join(" ") | contains("-consul-destination-namespace=default")' | tee /dev/stderr)
[ "${actual}" = "true" ]
}

@test "apiGateway/Deployment: enable namespace mirroring" {
cd `chart_dir`
local actual=$(helm template \
-s templates/api-gateway-controller-deployment.yaml \
--set 'apiGateway.enabled=true' \
--set 'apiGateway.image=bar' \
--set 'global.enableConsulNamespaces=true' \
--set 'apiGateway.consulNamespaces.mirroringK8S=true' \
. | tee /dev/stderr |
yq '.spec.template.spec.containers[0].command | join(" ") | contains("-mirroring-k8s=true")' | tee /dev/stderr)
[ "${actual}" = "true" ]
}

@test "apiGateway/Deployment: enable namespace mirroring prefixes" {
cd `chart_dir`
local actual=$(helm template \
-s templates/api-gateway-controller-deployment.yaml \
--set 'apiGateway.enabled=true' \
--set 'apiGateway.image=bar' \
--set 'global.enableConsulNamespaces=true' \
--set 'apiGateway.consulNamespaces.mirroringK8S=true' \
--set 'apiGateway.consulNamespaces.mirroringK8SPrefix=foo' \
. | tee /dev/stderr |
yq '.spec.template.spec.containers[0].command | join(" ") | contains("-mirroring-k8s-prefix=foo")' | tee /dev/stderr)
[ "${actual}" = "true" ]
}

@test "apiGateway/Deployment: container image overrides" {
cd `chart_dir`
Expand Down
23 changes: 23 additions & 0 deletions charts/consul/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2552,6 +2552,29 @@ apiGateway:
# @type: string
service: null

# [Enterprise Only] These settings manage the API Gateway's interaction with
# Consul namespaces (requires consul-ent v1.7+).
# Also, `global.enableConsulNamespaces` must be true.
consulNamespaces:
# Name of the Consul namespace to register all
# k8s services into. If the Consul namespace does not already exist,
# it will be created. This will be ignored if `mirroringK8S` is true.
consulDestinationNamespace: "default"

# If true, k8s services will be registered into a Consul namespace
# of the same name as their k8s namespace, optionally prefixed if
# `mirroringK8SPrefix` is set below. If the Consul namespace does not
# already exist, it will be created. Turning this on overrides the
# `consulDestinationNamespace` setting.
# `addK8SNamespaceSuffix` may no longer be needed if enabling this option.
mirroringK8S: false

# If `mirroringK8S` is set to true, `mirroringK8SPrefix` allows each Consul namespace
# to be given a prefix. For example, if `mirroringK8SPrefix` is set to "k8s-", a
# service in the k8s `staging` namespace will be registered into the
# `k8s-staging` Consul namespace.
mirroringK8SPrefix: ""

# Configuration for the ServiceAccount created for the api-gateway component
serviceAccount:
# This value defines additional annotations for the client service account. This should be formatted as a multi-line
Expand Down

0 comments on commit 9daaeba

Please sign in to comment.