Skip to content

Commit

Permalink
Add support for PartitionExports (#802)
Browse files Browse the repository at this point in the history
* Add support for PartitionExports
- This PR does not include acceptance tests. The desired acceptance tests will be determined based on the expected behavior of PartitionExports when partitions are disabled.
- Similarly, controller tests have not been added as our existing controller tests only account for namespace. The behavior with partitions has not been resolved.
* CHANGELOG
  • Loading branch information
Ashwin Venkatesh authored Oct 27, 2021
1 parent de51017 commit e7c2ad3
Show file tree
Hide file tree
Showing 27 changed files with 1,450 additions and 129 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ IMPROVEMENTS:
FEATURES:
* Control Plane
* Add `gossip-encryption-autogenerate` subcommand to generate a random 32 byte Kubernetes secret to be used as a gossip encryption key. [[GH-772](https://github.com/hashicorp/consul-k8s/pull/772)]
* Add support for `partition-exports` config entry. [[GH-802](https://github.com/hashicorp/consul-k8s/pull/802)], [[GH-803](https://github.com/hashicorp/consul-k8s/pull/803)]
* Helm Chart
* Add automatic generation of gossip encryption with `global.gossipEncryption.autoGenerate=true`. [[GH-738](https://github.com/hashicorp/consul-k8s/pull/738)]
* Add support for configuring resources for mesh gateway `service-init` container. [[GH-758](https://github.com/hashicorp/consul-k8s/pull/758)]
* Add support for `PartitionExports` CRD. [[GH-802](https://github.com/hashicorp/consul-k8s/pull/802)], [[GH-803](https://github.com/hashicorp/consul-k8s/pull/803)]

IMPROVEMENTS:
* Control Plane
Expand Down
2 changes: 1 addition & 1 deletion acceptance/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.14

require (
github.com/gruntwork-io/terratest v0.31.2
github.com/hashicorp/consul/api v1.10.1-0.20210915232521-e0a7900f52bf
github.com/hashicorp/consul/api v1.10.1-0.20211020192418-04cd2c983e9c
github.com/hashicorp/consul/sdk v0.8.0
github.com/stretchr/testify v1.5.1
gopkg.in/yaml.v2 v2.2.8
Expand Down
2 changes: 2 additions & 0 deletions acceptance/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,8 @@ github.com/gruntwork-io/terratest v0.31.2 h1:xvYHA80MUq5kx670dM18HInewOrrQrAN+Xb
github.com/gruntwork-io/terratest v0.31.2/go.mod h1:EEgJie28gX/4AD71IFqgMj6e99KP5mi81hEtzmDjxTo=
github.com/hashicorp/consul/api v1.10.1-0.20210915232521-e0a7900f52bf h1:fouyN8SkrE4py09XaOru4PCM9zunem39CjOrMJMrKsc=
github.com/hashicorp/consul/api v1.10.1-0.20210915232521-e0a7900f52bf/go.mod h1:sDjTOq0yUyv5G4h+BqSea7Fn6BU+XbolEz1952UB+mk=
github.com/hashicorp/consul/api v1.10.1-0.20211020192418-04cd2c983e9c h1:7eKUSC17HDH0+lHsI/fiPe5y8hMarXJdECqG7KiGkNA=
github.com/hashicorp/consul/api v1.10.1-0.20211020192418-04cd2c983e9c/go.mod h1:XjsvQN+RJGWI2TWy1/kqaE16HrR2J/FWgkYjdZQsX9M=
github.com/hashicorp/consul/sdk v0.7.0/go.mod h1:fY08Y9z5SvJqevyZNy6WWPXiG3KwBPAvlcdx16zZ0fM=
github.com/hashicorp/consul/sdk v0.8.0 h1:OJtKBtEjboEZvG6AOUdh4Z1Zbyu0WcxQ0qatRrZHTVU=
github.com/hashicorp/consul/sdk v0.8.0/go.mod h1:GBvyrGALthsZObzUGsfgHZQDXjg4lOjagTIwIR1vPms=
Expand Down
10 changes: 10 additions & 0 deletions acceptance/tests/fixtures/crds/partitionexports.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: consul.hashicorp.com/v1alpha1
kind: PartitionExports
metadata:
name: exports
spec:
services:
- name: frontend
namespace: frontend
consumers:
- partition: other
2 changes: 2 additions & 0 deletions charts/consul/templates/controller-clusterrole.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ rules:
- serviceresolvers
- proxydefaults
- meshes
- partitionexports
- servicerouters
- servicesplitters
- serviceintentions
Expand All @@ -37,6 +38,7 @@ rules:
- serviceresolvers/status
- proxydefaults/status
- meshes/status
- partitionexports/status
- servicerouters/status
- servicesplitters/status
- serviceintentions/status
Expand Down
137 changes: 137 additions & 0 deletions charts/consul/templates/crd-partitionexports.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
{{- if .Values.controller.enabled }}
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.6.0
creationTimestamp: null
name: partitionexports.consul.hashicorp.com
labels:
app: {{ template "consul.name" . }}
chart: {{ template "consul.chart" . }}
heritage: {{ .Release.Service }}
release: {{ .Release.Name }}
component: crd
spec:
group: consul.hashicorp.com
names:
kind: PartitionExports
listKind: PartitionExportsList
plural: partitionexports
singular: partitionexports
scope: Namespaced
versions:
- additionalPrinterColumns:
- description: The sync status of the resource with Consul
jsonPath: .status.conditions[?(@.type=="Synced")].status
name: Synced
type: string
- description: The last successful synced time of the resource with Consul
jsonPath: .status.lastSyncedTime
name: Last Synced
type: date
- description: The age of the resource
jsonPath: .metadata.creationTimestamp
name: Age
type: date
name: v1alpha1
schema:
openAPIV3Schema:
description: PartitionExports is the Schema for the partitionexports API
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
kind:
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
spec:
description: PartitionExportsSpec defines the desired state of PartitionExports
properties:
services:
description: Services is a list of services to be exported and the
list of partitions to expose them to.
items:
description: ExportedService manages the exporting of a service
in the local partition to other partitions.
properties:
consumers:
description: Consumers is a list of downstream consumers of
the service to be exported.
items:
description: ServiceConsumer represents a downstream consumer
of the service to be exported.
properties:
partition:
description: Partition is the admin partition to export
the service to.
type: string
type: object
type: array
name:
description: Name is the name of the service to be exported.
type: string
namespace:
description: Namespace is the namespace to export the service
from.
type: string
type: object
type: array
type: object
status:
properties:
conditions:
description: Conditions indicate the latest available observations
of a resource's current state.
items:
description: 'Conditions define a readiness condition for a Consul
resource. See: https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#typical-status-properties'
properties:
lastTransitionTime:
description: LastTransitionTime is the last time the condition
transitioned from one status to another.
format: date-time
type: string
message:
description: A human readable message indicating details about
the transition.
type: string
reason:
description: The reason for the condition's last transition.
type: string
status:
description: Status of the condition, one of True, False, Unknown.
type: string
type:
description: Type of condition.
type: string
required:
- status
- type
type: object
type: array
lastSyncedTime:
description: LastSyncedTime is the last time the resource successfully
synced with Consul.
format: date-time
type: string
type: object
type: object
served: true
storage: true
subresources:
status: {}
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
{{- end }}
24 changes: 24 additions & 0 deletions charts/consul/test/unit/crd-partitionexports.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env bats

load _helpers

@test "partitionExports/CustomerResourceDefinition: disabled by default" {
cd `chart_dir`
assert_empty helm template \
-s templates/crd-partitionexports.yaml \
.
}

@test "partitionExports/CustomerResourceDefinition: enabled with controller.enabled=true" {
cd `chart_dir`
local actual=$(helm template \
-s templates/crd-partitionexports.yaml \
--set 'controller.enabled=true' \
. | tee /dev/stderr |
# The generated CRDs have "---" at the top which results in two objects
# being detected by yq, the first of which is null. We must therefore use
# yq -s so that length operates on both objects at once rather than
# individually, which would output false\ntrue and fail the test.
yq -s 'length > 0' | tee /dev/stderr)
[ "${actual}" = "true" ]
}
37 changes: 18 additions & 19 deletions control-plane/PROJECT
Original file line number Diff line number Diff line change
@@ -1,63 +1,62 @@
domain: hashicorp.com
layout: go.kubebuilder.io/v2
layout:
- go.kubebuilder.io/v2
plugins:
go.operator-sdk.io/v2-alpha: {}
repo: github.com/hashicorp/consul-k8s
resources:
-
controller: true
- controller: true
domain: hashicorp.com
group: consul
kind: IngressGateway
path: github.com/hashicorp/consul-k8s/api/v1alpha1
version: v1alpha1
-
controller: true
- controller: true
domain: hashicorp.com
group: consul
kind: ProxyDefaults
path: github.com/hashicorp/consul-k8s/api/v1alpha1
version: v1alpha1
-
controller: true
- controller: true
domain: hashicorp.com
group: consul
kind: ServiceIntentions
path: github.com/hashicorp/consul-k8s/api/v1alpha1
version: v1alpha1
-
controller: true
- controller: true
domain: hashicorp.com
group: consul
kind: ServiceDefaults
path: github.com/hashicorp/consul-k8s/api/v1alpha1
version: v1alpha1
-
controller: true
- controller: true
domain: hashicorp.com
group: consul
kind: ServiceResolver
path: github.com/hashicorp/consul-k8s/api/v1alpha1
version: v1alpha1
-
controller: true
- controller: true
domain: hashicorp.com
group: consul
kind: ServiceRouter
path: github.com/hashicorp/consul-k8s/api/v1alpha1
version: v1alpha1
-
controller: true
- controller: true
domain: hashicorp.com
group: consul
kind: ServiceSplitter
path: github.com/hashicorp/consul-k8s/api/v1alpha1
version: v1alpha1
-
controller: true
- controller: true
domain: hashicorp.com
group: consul
kind: TerminatingGateway
path: github.com/hashicorp/consul-k8s/api/v1alpha1
version: v1alpha1
- controller: true
domain: hashicorp.com
group: consul
kind: PartitionExport
path: github.com/hashicorp/consul-k8s/api/v1alpha1
version: v1alpha1
version: "3"
plugins:
go.operator-sdk.io/v2-alpha: {}
2 changes: 2 additions & 0 deletions control-plane/api/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ const (
ServiceRouter string = "servicerouter"
ServiceSplitter string = "servicesplitter"
ServiceIntentions string = "serviceintentions"
PartitionExports string = "partitionexports"
IngressGateway string = "ingressgateway"
TerminatingGateway string = "terminatinggateway"

Global string = "global"
Mesh string = "mesh"
DefaultConsulNamespace string = "default"
DefaultConsulPartition string = "default"
WildcardNamespace string = "*"

SourceKey string = "external-source"
Expand Down
Loading

0 comments on commit e7c2ad3

Please sign in to comment.