Skip to content

Commit

Permalink
add sameness group CRD (#2048)
Browse files Browse the repository at this point in the history
* draft of adding sameness group CRD

* move sameness group tests to ent test file

* update tests

* fix lint issues

* generate yaml and update helm charts

* update field descriptions and validation and its test

* remove unwanted files, add license comments back

* rename samenessgroups to samenessgroup

* fix resource names

* update failing unit test
  • Loading branch information
malizz authored Apr 18, 2023
1 parent 34fb4a2 commit 11f842c
Show file tree
Hide file tree
Showing 37 changed files with 1,640 additions and 105 deletions.
10 changes: 4 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ rebase the branch on main, fixing any conflicts along the way before the code ca
```bash
operator-sdk create api --group consul --version v1alpha1 --kind IngressGateway --controller --namespaced=true --make=false --resource=true
```
1. Re-order the file so it looks like:
1. Re-order the generated ingressgateway_types.go file, so it looks like:
```go
func init() {
SchemeBuilder.Register(&IngressGateway{}, &IngressGatewayList{})
Expand Down Expand Up @@ -320,8 +320,6 @@ rebase the branch on main, fixing any conflicts along the way before the code ca

### Controller
1. Delete the file `control-plane/controllers/suite_test.go`. We don't write suite tests, just unit tests.
1. Move `control-plane/controllers/ingressgateway_controller.go` to `control-plane/controller` directory.
1. Delete the `control-plane/controllers` directory.
1. Rename `Reconciler` to `Controller`, e.g. `IngressGatewayReconciler` => `IngressGatewayController`
1. Use the existing controller files as a guide and make this file match.
1. Add your controller as a case in the tests in `configentry_controller_test.go`:
Expand Down Expand Up @@ -395,13 +393,13 @@ rebase the branch on main, fixing any conflicts along the way before the code ca
```

### Updating Helm chart
1. Update `charts/consul/templates/controller-mutatingwebhookconfiguration` with the webhook for this resource
1. Update `charts/consul/templates/connect-inject-mutatingwebhookconfiguration` with the webhook for this resource
using the updated `control-plane/config/webhook/manifests.v1beta1.yaml` and replacing `clientConfig.service.name/namespace`
with the templated strings shown below to match the other webhooks.:
```yaml
- clientConfig:
service:
name: {{ template "consul.fullname" . }}-controller-webhook
name: {{ template "consul.fullname" . }}-connect-injector
namespace: {{ .Release.Namespace }}
path: /mutate-v1alpha1-ingressgateway
failurePolicy: Fail
Expand All @@ -421,7 +419,7 @@ rebase the branch on main, fixing any conflicts along the way before the code ca
- ingressgateways
sideEffects: None
```
1. Update `charts/consul/templates/controller-clusterrole.yaml` to allow the controller to
1. Update `charts/consul/templates/connect-inject-clusterrole.yaml` to allow the controller to
manage your resource type.

### Testing A New CRD
Expand Down
2 changes: 2 additions & 0 deletions charts/consul/templates/connect-inject-clusterrole.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ rules:
- serviceintentions
- ingressgateways
- terminatinggateways
- samenessgroups
{{- if .Values.global.peering.enabled }}
- peeringacceptors
- peeringdialers
Expand All @@ -49,6 +50,7 @@ rules:
- serviceintentions/status
- ingressgateways/status
- terminatinggateways/status
- samenessgroups/status
{{- if .Values.global.peering.enabled }}
- peeringacceptors/status
- peeringdialers/status
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,5 +291,26 @@ webhooks:
admissionReviewVersions:
- "v1beta1"
- "v1"
- admissionReviewVersions:
- v1beta1
- v1
clientConfig:
service:
name: {{ template "consul.fullname" . }}-connect-injector
namespace: {{ .Release.Namespace }}
path: /mutate-v1alpha1-samenessgroup
failurePolicy: Fail
name: mutate-samenessgroup.consul.hashicorp.com
rules:
- apiGroups:
- consul.hashicorp.com
apiVersions:
- v1alpha1
operations:
- CREATE
- UPDATE
resources:
- samenessgroups
sideEffects: None
{{- end }}
{{- end }}
14 changes: 8 additions & 6 deletions charts/consul/templates/crd-proxydefaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -143,16 +143,18 @@ spec:
type: object
type: array
type: object
failoverPolicy:
description: FailoverPolicy specifies the exact mechanism used for failover.
failoverPolicy:
description: FailoverPolicy specifies the exact mechanism used for
failover.
properties:
mode:
description: Mode specifies the type of failover that will be performed.
Valid values are "sequential", "" (equivalent to "sequential") and "order-by-locality".
description: Mode specifies the type of failover that will be
performed. Valid values are "sequential", "" (equivalent to
"sequential") and "order-by-locality".
type: string
regions:
regions:
description: The ordered list of the regions of the failover targets.
Valid values can be "us-west-1", "us-west-2", and so on.
Valid values can be "us-west-1", "us-west-2", and so on.
items:
type: string
type: array
Expand Down
126 changes: 126 additions & 0 deletions charts/consul/templates/crd-samenessgroups.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
{{- if .Values.connectInject.enabled }}
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.8.0
creationTimestamp: null
name: samenessgroups.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: SamenessGroup
listKind: SamenessGroupList
plural: samenessgroups
shortNames:
- sameness-group
singular: samenessgroup
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: SamenessGroup is the Schema for the samenessgroups 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: SamenessGroupSpec defines the desired state of SamenessGroup.
properties:
defaultForFailover:
description: 'DefaultForFailover indicates that upstream requests to members of the given sameness group will implicitly failover between members of this sameness group.'
type: boolean
includeLocal:
description: 'IncludeLocal is used to include the local partition as the first member of the sameness group.'
type: boolean
members:
description: 'Members are the partitions and peers that are part of the sameness group.'
items:
properties:
partition:
type: string
peer:
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 }}
9 changes: 5 additions & 4 deletions charts/consul/templates/crd-serviceresolvers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,14 @@ spec:
the current namespace is used.
type: string
policy:
description: FailoverPolicy specifies the exact mechanism used for failover.
description: Policy specifies the exact mechanism used for failover.
properties:
mode:
description: Mode specifies the type of failover that will be performed.
Valid values are "sequential", "" (equivalent to "sequential") and "order-by-locality".
description: Mode specifies the type of failover that will
be performed. Valid values are "sequential", "" (equivalent
to "sequential") and "order-by-locality".
type: string
regions:
regions:
description: The ordered list of the regions of the failover targets.
Valid values can be "us-west-1", "us-west-2", and so on.
items:
Expand Down
13 changes: 13 additions & 0 deletions control-plane/PROJECT
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Code generated by tool. DO NOT EDIT.
# This file is used to track the info used to scaffold your project
# and allow the plugins properly work.
# More info: https://book.kubebuilder.io/reference/project-config.html
domain: hashicorp.com
layout:
- go.kubebuilder.io/v2
Expand Down Expand Up @@ -77,4 +81,13 @@ resources:
kind: PeeringDialer
path: github.com/hashicorp/consul-k8s/control-plane/api/v1alpha1
version: v1alpha1
- api:
crdVersion: v1beta1
namespaced: true
controller: true
domain: hashicorp.com
group: consul
kind: SamenessGroup
path: github.com/hashicorp/consul-k8s/control-plane/api/v1alpha1
version: v1alpha1
version: "3"
1 change: 1 addition & 0 deletions control-plane/api/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const (
ExportedServices string = "exportedservices"
IngressGateway string = "ingressgateway"
TerminatingGateway string = "terminatinggateway"
SamenessGroup string = "samenessgroup"

Global string = "global"
Mesh string = "mesh"
Expand Down
Loading

0 comments on commit 11f842c

Please sign in to comment.