Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Helm namespace mirroring #1601

Merged
merged 7 commits into from
Oct 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
FEATURES:
* Peering: Add support for `PeerThroughMeshGateways` in Mesh CRD. [[GH-1478](https://github.com/hashicorp/consul-k8s/pull/1478)]

BREAKING CHANGES:
* Helm:
* `syncCatalog.consulNamespaces.mirroringK8S` now defaults to `true`. [[GH-1601](https://github.com/hashicorp/consul-k8s/pull/1601)]
* `connectInject.consulNamespaces.mirroringK8S` now defaults to `true`. [[GH-1601](https://github.com/hashicorp/consul-k8s/pull/1601)]

IMPROVEMENTS:
* Helm:
* API Gateway: Allow controller to read MeshServices for use as a route backend. [[GH-1574](https://github.com/hashicorp/consul-k8s/pull/1574)]
Expand Down
3 changes: 1 addition & 2 deletions charts/consul/templates/connect-inject-deployment.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{{- if and .Values.global.peering.enabled (not .Values.connectInject.enabled) }}{{ fail "setting global.peering.enabled to true requires connectInject.enabled to be true" }}{{ end }}
{{- if (or (and (ne (.Values.connectInject.enabled | toString) "-") .Values.connectInject.enabled) (and (eq (.Values.connectInject.enabled | toString) "-") .Values.global.enabled)) }}
{{- if and .Values.connectInject.consulNamespaces.mirroringK8S (not .Values.global.enableConsulNamespaces) }}{{ fail "global.enableConsulNamespaces must be true if mirroringK8S=true" }}{{ end }}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of failing here, I have the enable mirroring flag check for both conditions to be true in order to be passed to inject-connect.

{{- if and .Values.global.adminPartitions.enabled (not .Values.global.enableConsulNamespaces) }}{{ fail "global.enableConsulNamespaces must be true if global.adminPartitions.enabled=true" }}{{ end }}
{{ template "consul.validateVaultWebhookCertConfiguration" . }}
{{- template "consul.reservedNamesFailer" (list .Values.connectInject.consulNamespaces.consulDestinationNamespace "connectInject.consulNamespaces.consulDestinationNamespace") }}
Expand Down Expand Up @@ -206,7 +205,7 @@ spec:
{{- if .Values.connectInject.consulNamespaces.consulDestinationNamespace }}
-consul-destination-namespace={{ .Values.connectInject.consulNamespaces.consulDestinationNamespace }} \
{{- end }}
{{- if .Values.connectInject.consulNamespaces.mirroringK8S }}
{{- if and .Values.global.enableConsulNamespaces .Values.connectInject.consulNamespaces.mirroringK8S }}
-enable-k8s-namespace-mirroring=true \
{{- if .Values.connectInject.consulNamespaces.mirroringK8SPrefix }}
-k8s-namespace-mirroring-prefix={{ .Values.connectInject.consulNamespaces.mirroringK8SPrefix }} \
Expand Down
19 changes: 4 additions & 15 deletions charts/consul/test/unit/connect-inject-deployment.bats
Original file line number Diff line number Diff line change
Expand Up @@ -653,17 +653,6 @@ load _helpers
#--------------------------------------------------------------------
# namespaces

@test "connectInject/Deployment: fails if namespaces are disabled and mirroringK8S is true" {
cd `chart_dir`
run helm template \
-s templates/connect-inject-deployment.yaml \
--set 'global.enableConsulNamespaces=false' \
--set 'connectInject.consulNamespaces.mirroringK8S=true' \
--set 'connectInject.enabled=true' .
[ "$status" -eq 1 ]
[[ "$output" =~ "global.enableConsulNamespaces must be true if mirroringK8S=true" ]]
}

@test "connectInject/Deployment: namespace options disabled by default" {
cd `chart_dir`
local object=$(helm template \
Expand Down Expand Up @@ -708,20 +697,20 @@ load _helpers

local actual=$(echo $object |
yq 'any(contains("enable-k8s-namespace-mirroring"))' | tee /dev/stderr)
[ "${actual}" = "false" ]
[ "${actual}" = "true" ]

local actual=$(echo $object |
yq 'any(contains("k8s-namespace-mirroring-prefix"))' | tee /dev/stderr)
[ "${actual}" = "false" ]
}

@test "connectInject/Deployment: mirroring options set with .connectInject.consulNamespaces.mirroringK8S=true" {
@test "connectInject/Deployment: mirroring options omitted with .connectInject.consulNamespaces.mirroringK8S=false" {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition this checked is now covered by the test on line 681. I changed it to check the opposite case as it is no longer the default behavior.

cd `chart_dir`
local object=$(helm template \
-s templates/connect-inject-deployment.yaml \
--set 'connectInject.enabled=true' \
--set 'global.enableConsulNamespaces=true' \
--set 'connectInject.consulNamespaces.mirroringK8S=true' \
--set 'connectInject.consulNamespaces.mirroringK8S=false' \
. | tee /dev/stderr |
yq '.spec.template.spec.containers[0].command' | tee /dev/stderr)

Expand All @@ -735,7 +724,7 @@ load _helpers

local actual=$(echo $object |
yq 'any(contains("enable-k8s-namespace-mirroring=true"))' | tee /dev/stderr)
[ "${actual}" = "true" ]
[ "${actual}" = "false" ]

local actual=$(echo $object |
yq 'any(contains("k8s-namespace-mirroring-prefix"))' | tee /dev/stderr)
Expand Down
2 changes: 1 addition & 1 deletion charts/consul/test/unit/controller-deployment.bats
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ load _helpers

local actual=$(echo $object |
yq 'any(contains("enable-k8s-namespace-mirroring"))' | tee /dev/stderr)
[ "${actual}" = "false" ]
[ "${actual}" = "true" ]

local actual=$(echo $object |
yq 'any(contains("k8s-namespace-mirroring-prefix"))' | tee /dev/stderr)
Expand Down
12 changes: 6 additions & 6 deletions charts/consul/test/unit/server-acl-init-job.bats
Original file line number Diff line number Diff line change
Expand Up @@ -1072,7 +1072,7 @@ load _helpers

local actual=$(echo $object |
yq 'any(contains("enable-inject-k8s-namespace-mirroring"))' | tee /dev/stderr)
[ "${actual}" = "false" ]
[ "${actual}" = "true" ]

local actual=$(echo $object |
yq 'any(contains("inject-k8s-namespace-mirroring-prefix"))' | tee /dev/stderr)
Expand All @@ -1099,7 +1099,7 @@ load _helpers

local actual=$(echo $object |
yq 'any(contains("enable-sync-k8s-namespace-mirroring"))' | tee /dev/stderr)
[ "${actual}" = "false" ]
[ "${actual}" = "true" ]

local actual=$(echo $object |
yq 'any(contains("sync-k8s-namespace-mirroring-prefix"))' | tee /dev/stderr)
Expand All @@ -1115,7 +1115,7 @@ load _helpers

local actual=$(echo $object |
yq 'any(contains("enable-inject-k8s-namespace-mirroring"))' | tee /dev/stderr)
[ "${actual}" = "false" ]
[ "${actual}" = "true" ]

local actual=$(echo $object |
yq 'any(contains("inject-k8s-namespace-mirroring-prefix"))' | tee /dev/stderr)
Expand Down Expand Up @@ -1159,7 +1159,7 @@ load _helpers

local actual=$(echo $object |
yq 'any(contains("enable-inject-k8s-namespace-mirroring"))' | tee /dev/stderr)
[ "${actual}" = "false" ]
[ "${actual}" = "true" ]

local actual=$(echo $object |
yq 'any(contains("inject-k8s-namespace-mirroring-prefix"))' | tee /dev/stderr)
Expand Down Expand Up @@ -1204,7 +1204,7 @@ load _helpers

local actual=$(echo $object |
yq 'any(contains("enable-inject-k8s-namespace-mirroring"))' | tee /dev/stderr)
[ "${actual}" = "false" ]
[ "${actual}" = "true" ]

local actual=$(echo $object |
yq 'any(contains("inject-k8s-namespace-mirroring-prefix"))' | tee /dev/stderr)
Expand Down Expand Up @@ -1294,7 +1294,7 @@ load _helpers

local actual=$(echo $object |
yq 'any(contains("enable-inject-k8s-namespace-mirroring"))' | tee /dev/stderr)
[ "${actual}" = "false" ]
[ "${actual}" = "true" ]

local actual=$(echo $object |
yq 'any(contains("inject-k8s-namespace-mirroring-prefix"))' | tee /dev/stderr)
Expand Down
2 changes: 1 addition & 1 deletion charts/consul/test/unit/sync-catalog-deployment.bats
Original file line number Diff line number Diff line change
Expand Up @@ -984,7 +984,7 @@ load _helpers

local actual=$(echo $object |
yq 'any(contains("enable-k8s-namespace-mirroring"))' | tee /dev/stderr)
[ "${actual}" = "false" ]
[ "${actual}" = "true" ]

local actual=$(echo $object |
yq 'any(contains("k8s-namespace-mirroring-prefix"))' | tee /dev/stderr)
Expand Down
4 changes: 2 additions & 2 deletions charts/consul/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1755,7 +1755,7 @@ syncCatalog:
# If mirroring is enabled, avoid creating any Consul resources in the following
# Kubernetes namespaces, as Consul currently reserves these namespaces for
# system use: "system", "universal", "operator", "root".
mirroringK8S: false
mirroringK8S: true

# 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
Expand Down Expand Up @@ -2205,7 +2205,7 @@ connectInject:
# `consulDestinationNamespace` setting. If mirroring is enabled, avoid creating any Consul
# resources in the following Kubernetes namespaces, as Consul currently reserves these
# namespaces for system use: "system", "universal", "operator", "root".
mirroringK8S: false
mirroringK8S: true

# 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
Expand Down