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

Add helm value to enable cluster peering #1270

Merged
merged 2 commits into from
Jun 13, 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
4 changes: 4 additions & 0 deletions charts/consul/templates/connect-inject-deployment.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- 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 not (or (and (ne (.Values.client.enabled | toString) "-") .Values.client.enabled) (and (eq (.Values.client.enabled | toString) "-") .Values.global.enabled)) }}{{ fail "clients must be enabled for connect injection" }}{{ end }}
{{- if not .Values.client.grpc }}{{ fail "client.grpc must be true for connect injection" }}{{ end }}
Expand Down Expand Up @@ -111,6 +112,9 @@ spec:
{{- else }}
-default-enable-transparent-proxy=false \
{{- end }}
{{- if .Values.global.peering.enabled }}
-enable-peering=true \
{{- end }}
{{- if .Values.global.openshift.enabled }}
-enable-openshift \
{{- end }}
Expand Down
4 changes: 2 additions & 2 deletions charts/consul/templates/crd-exportedservices.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ spec:
the service to.
type: string
peerName:
description: PeerName is the name of the peer to export
the service to.
description: '[Experimental] PeerName is the name of the
peer to export the service to.'
type: string
type: object
type: array
Expand Down
2 changes: 1 addition & 1 deletion charts/consul/templates/crd-peeringacceptors.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- if .Values.connectInject.enabled }}
{{- if and .Values.connectInject.enabled .Values.global.peering.enabled }}
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
Expand Down
2 changes: 1 addition & 1 deletion charts/consul/templates/crd-peeringdialers.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- if .Values.connectInject.enabled }}
{{- if and .Values.connectInject.enabled .Values.global.peering.enabled }}
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
Expand Down
3 changes: 2 additions & 1 deletion charts/consul/templates/crd-serviceintentions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ spec:
description: Partition is the Admin Partition for the Name parameter.
type: string
peer:
description: Peer is the peer name for the Name parameter.
description: '[Experimental] Peer is the peer name for the Name
parameter.'
type: string
permissions:
description: Permissions is the list of all additional L7 attributes
Expand Down
37 changes: 37 additions & 0 deletions charts/consul/test/unit/connect-inject-deployment.bats
Original file line number Diff line number Diff line change
Expand Up @@ -1730,6 +1730,43 @@ EOF
[ "${actual}" = "true" ]
}

#--------------------------------------------------------------------
# peering

@test "connectInject/Deployment: peering is not set by default" {
cd `chart_dir`
local actual=$(helm template \
-s templates/connect-inject-deployment.yaml \
--set 'connectInject.enabled=true' \
. | tee /dev/stderr |
yq '.spec.template.spec.containers[0].command | any(contains("-enable-peering=true"))' | tee /dev/stderr)

[ "${actual}" = "false" ]
}

@test "connectInject/Deployment: -enable-peering=true is set when global.peering.enabled is true" {
cd `chart_dir`
local actual=$(helm template \
-s templates/connect-inject-deployment.yaml \
--set 'connectInject.enabled=true' \
--set 'global.peering.enabled=true' \
. | tee /dev/stderr |
yq '.spec.template.spec.containers[0].command | any(contains("-enable-peering=true"))' | tee /dev/stderr)

[ "${actual}" = "true" ]
}

@test "connectInject/Deployment: fails if peering is enabled but connect inject is not" {
cd `chart_dir`
run helm template \
-s templates/connect-inject-deployment.yaml \
--set 'connectInject.enabled=false' \
--set 'global.peering.enabled=true' .
[ "$status" -eq 1 ]
[[ "$output" =~ "setting global.peering.enabled to true requires connectInject.enabled to be true" ]]
}


#--------------------------------------------------------------------
# openshift

Expand Down
7 changes: 7 additions & 0 deletions charts/consul/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ global:
# Consul into Kubernetes will have, e.g. `service-name.service.consul`.
domain: consul

# [Experimental] Configures the Cluster Peering feature. Requires Consul v1.13+ and Consul-K8s v0.45+.
peering:
# If true, the Helm chart will enable Cluster Peering for the cluster. This will enable peering controllers and
# allow use of the PeeringAcceptor and PeeringDialer CRDs to establish peerings for service mesh.
# @type boolean
enabled: false
Comment on lines +34 to +37
Copy link
Member

Choose a reason for hiding this comment

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

Should say which version is required

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added this for the peering block, thanks!


# [Enterprise Only] Enabling `adminPartitions` allows creation of Admin Partitions in Kubernetes clusters.
# It additionally indicates that you are running Consul Enterprise v1.11+ with a valid Consul Enterprise
# license. Admin partitions enables deploying services across partitions, while sharing
Expand Down
2 changes: 1 addition & 1 deletion control-plane/api/v1alpha1/exportedservices_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ type ExportedService struct {
type ServiceConsumer struct {
// Partition is the admin partition to export the service to.
Partition string `json:"partition,omitempty"`
// PeerName is the name of the peer to export the service to.
// [Experimental] PeerName is the name of the peer to export the service to.
PeerName string `json:"peerName,omitempty"`
}

Expand Down
2 changes: 1 addition & 1 deletion control-plane/api/v1alpha1/serviceintentions_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ type SourceIntention struct {
Name string `json:"name,omitempty"`
// Namespace is the namespace for the Name parameter.
Namespace string `json:"namespace,omitempty"`
// Peer is the peer name for the Name parameter.
// [Experimental] Peer is the peer name for the Name parameter.
Peer string `json:"peer,omitempty"`
// Partition is the Admin Partition for the Name parameter.
Partition string `json:"partition,omitempty"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ spec:
the service to.
type: string
peerName:
description: PeerName is the name of the peer to export
the service to.
description: '[Experimental] PeerName is the name of the
peer to export the service to.'
type: string
type: object
type: array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ spec:
description: Partition is the Admin Partition for the Name parameter.
type: string
peer:
description: Peer is the peer name for the Name parameter.
description: '[Experimental] Peer is the peer name for the Name
parameter.'
type: string
permissions:
description: Permissions is the list of all additional L7 attributes
Expand Down
45 changes: 26 additions & 19 deletions control-plane/subcommand/inject-connect/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ type Command struct {
flagDefaultEnableTransparentProxy bool
flagTransparentProxyDefaultOverwriteProbes bool

// Peering flags.
flagEnablePeering bool

// Consul DNS flags.
flagEnableConsulDNS bool
flagResourcePrefix string
Expand Down Expand Up @@ -133,6 +136,7 @@ func (c *Command) init() {
"Docker image for Envoy.")
c.flagSet.StringVar(&c.flagConsulK8sImage, "consul-k8s-image", "",
"Docker image for consul-k8s. Used for the connect sidecar.")
c.flagSet.BoolVar(&c.flagEnablePeering, "enable-peering", false, "Enable cluster peering controllers.")
c.flagSet.StringVar(&c.flagEnvoyExtraArgs, "envoy-extra-args", "",
"Extra envoy command line args to be set when starting envoy (e.g \"--log-level debug --disable-hot-restart\").")
c.flagSet.StringVar(&c.flagACLAuthMethod, "acl-auth-method", "",
Expand Down Expand Up @@ -426,26 +430,29 @@ func (c *Command) Run(args []string) int {
return 1
}

if err = (&connectinject.PeeringAcceptorController{
Client: mgr.GetClient(),
ConsulClient: c.consulClient,
Log: ctrl.Log.WithName("controller").WithName("peering-acceptor"),
Scheme: mgr.GetScheme(),
Context: ctx,
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "peering-acceptor")
return 1
}
if err = (&connectinject.PeeringDialerController{
Client: mgr.GetClient(),
ConsulClient: c.consulClient,
Log: ctrl.Log.WithName("controller").WithName("peering-dialer"),
Scheme: mgr.GetScheme(),
Context: ctx,
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "peering-dialer")
return 1
if c.flagEnablePeering {
if err = (&connectinject.PeeringAcceptorController{
Client: mgr.GetClient(),
ConsulClient: c.consulClient,
Log: ctrl.Log.WithName("controller").WithName("peering-acceptor"),
Scheme: mgr.GetScheme(),
Context: ctx,
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "peering-acceptor")
return 1
}
if err = (&connectinject.PeeringDialerController{
Client: mgr.GetClient(),
ConsulClient: c.consulClient,
Log: ctrl.Log.WithName("controller").WithName("peering-dialer"),
Scheme: mgr.GetScheme(),
Context: ctx,
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "peering-dialer")
return 1
}
}

mgr.GetWebhookServer().CertDir = c.flagCertDir

mgr.GetWebhookServer().Register("/mutate",
Expand Down