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 envoyExtensions field to serviceDefaults and proxyDefaults CRDs #1823

Merged
merged 12 commits into from
Jan 12, 2023
Merged
14 changes: 14 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,20 @@ env:
CONSUL_ENT_DOCKER_IMAGE: hashicorppreview/consul-enterprise:1.14-dev # Consul's enterprise version to use in tests

jobs:
terraform-fmt-check:
name: "Terraform format check"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
with:
terraform_version: TERRAFORM_VERSION
terraform_wrapper: false
- name: Run Terraform checks
run: |
make terraform-fmt-check TERRAFORM_DIR="${{ github.workspace }}"
get-go-version:
name: "Determine Go toolchain version"
runs-on: ubuntu-latest
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ IMPROVEMENTS:
* Helm:
* Add a `global.extraLabels` stanza to allow setting global Kubernetes labels for all components deployed by the `consul-k8s` Helm chart. [[GH-1778](https://github.com/hashicorp/consul-k8s/pull/1778)]
* Add the `accessLogs` field to the `ProxyDefaults` CRD. [[GH-1816](https://github.com/hashicorp/consul-k8s/pull/1816)]
* Add the `envoyExtensions` field to the `ProxyDefaults` and `ServiceDefaults` CRD. [[GH-1823]](https://github.com/hashicorp/consul-k8s/pull/1823)
* Add the `balanceInboundConnections` field to the `ServiceDefaults` CRD. [[GH-1823]](https://github.com/hashicorp/consul-k8s/pull/1823)
* Control-Plane
* Add support for the annotation `consul.hashicorp.com/use-proxy-health-check`. [[GH-1824](https://github.com/hashicorp/consul-k8s/pull/1824)]

Expand Down
17 changes: 12 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -424,20 +424,27 @@ rebase the branch on main, fixing any conflicts along the way before the code ca
manage your resource type.

### Testing A New CRD
1. Build a Docker image for consul-k8s via `make dev-docker` and tagging your image appropriately. Remember to CD into the `control-plane` directory!
1. Build a Docker image for consul-k8s via `make control-plane-dev-docker` and push to a docker repository:
```
docker tag consul-k8s-control-plane-dev <DOCKER-HUB-USERNAME>/consul-k8s-control-plane-dev:<version>
docker push <DOCKER-HUB-USERNAME>/consul-k8s-control-plane-dev:<version>
```
1. Install using the updated Helm repository, with a values like:
```yaml
global:
imageK8S: ghcr.io/lkysow/consul-k8s-dev:nov26
imageK8S: lkysow/consul-k8s-control-plane-dev:nov26
name: consul
server:
replicas: 1
bootstrapExpect: 1
controller:
ui:
enabled: true
connectInject:
enabled: true
```
1. `kubectl apply` your sample CRD.
1. Check its synced status:
1. Create a sample CRD
1. Run `kubectl apply -f <path-to-crd>` to apply your sample CRD.
1. Check its synced status (for example CRD called ingressgateway):
```bash
kubectl get ingressgateway
NAME SYNCED AGE
Expand Down
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@ kind-cni:
kind create cluster --config=$(CURDIR)/acceptance/framework/environment/cni-kind/kind.config --name dc2 --image kindest/node:v1.23.6
make kind-cni-calico

# Perform a terraform fmt check but don't change anything
terraform-fmt-check:
@$(CURDIR)/control-plane/build-support/scripts/terraformfmtcheck.sh $(TERRAFORM_DIR)
.PHONY: terraform-fmt-check

# Format all terraform files according to terraform fmt
terraform-fmt:
@terraform fmt -recursive
.PHONY: terraform-fmt


# ===========> CLI Targets

Expand Down
16 changes: 16 additions & 0 deletions charts/consul/templates/crd-proxydefaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,22 @@ spec:
globally here. Supports JSON config values. See https://www.consul.io/docs/connect/proxies/envoy#configuration-formatting
type: object
x-kubernetes-preserve-unknown-fields: true
envoyExtensions:
description: EnvoyExtensions are a list of extensions to modify Envoy
proxy configuration.
items:
description: EnvoyExtension has configuration for an extension that
patches Envoy resources.
properties:
arguments:
type: object
x-kubernetes-preserve-unknown-fields: true
name:
type: string
required:
type: boolean
type: object
type: array
expose:
description: Expose controls the default expose path configuration
for Envoy.
Expand Down
36 changes: 29 additions & 7 deletions charts/consul/templates/crd-servicedefaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ spec:
spec:
description: ServiceDefaultsSpec defines the desired state of ServiceDefaults.
properties:
balanceInboundConnections:
description: BalanceInboundConnections sets the strategy for allocating
inbound connections to the service across proxy threads. The only
supported value is exact_balance. By default, no connection balancing
is used. Refer to the Envoy Connection Balance config for details.
type: string
destination:
description: Destination is an address(es)/port combination that represents
an endpoint outside the mesh. This is only valid when the mesh is
Expand All @@ -76,6 +82,22 @@ spec:
format: int32
type: integer
type: object
envoyExtensions:
description: EnvoyExtensions are a list of extensions to modify Envoy
proxy configuration.
items:
description: EnvoyExtension has configuration for an extension that
patches Envoy resources.
properties:
arguments:
type: object
x-kubernetes-preserve-unknown-fields: true
name:
type: string
required:
type: boolean
type: object
type: array
expose:
description: Expose controls the default expose path configuration
for Envoy.
Expand Down Expand Up @@ -114,15 +136,15 @@ spec:
with an external system.
type: string
localConnectTimeoutMs:
description: The number of milliseconds allowed to make connections
to the local application instance before timing out. Defaults to
5000.
description: LocalConnectTimeoutMs is the number of milliseconds allowed
to make connections to the local application instance before timing
out. Defaults to 5000.
type: integer
localRequestTimeoutMs:
description: In milliseconds, the timeout for HTTP requests to the
local application instance. Applies to HTTP-based protocols only.
If not specified, inherits the Envoy default for route timeouts
(15s).
description: LocalRequestTimeoutMs is the timeout for HTTP requests
to the local application instance in milliseconds. Applies to HTTP-based
protocols only. If not specified, inherits the Envoy default for
route timeouts (15s).
type: integer
maxInboundConnections:
description: MaxInboundConnections is the maximum number of concurrent
Expand Down
2 changes: 1 addition & 1 deletion charts/consul/test/terraform/aks/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ variable "cluster_count" {
}

variable "tags" {
type = map
type = map(any)
default = {}
description = "Tags to attach to the created resources."
}
4 changes: 2 additions & 2 deletions charts/consul/test/terraform/eks/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ module "vpc" {
module "eks" {
count = var.cluster_count

source = "terraform-aws-modules/eks/aws"
version = "17.24.0"
source = "terraform-aws-modules/eks/aws"
version = "17.24.0"
kubeconfig_api_version = "client.authentication.k8s.io/v1beta1"

cluster_name = "consul-k8s-${random_id.suffix[count.index].dec}"
Expand Down
2 changes: 1 addition & 1 deletion charts/consul/test/terraform/eks/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ variable "role_arn" {
}

variable "tags" {
type = map
type = map(any)
default = {}
description = "Tags to attach to the created resources."
}
2 changes: 1 addition & 1 deletion charts/consul/test/terraform/gke/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ variable "cluster_count" {
}

variable "labels" {
type = map
type = map(any)
default = {}
description = "Labels to attach to the created resources."
}
2 changes: 1 addition & 1 deletion charts/consul/test/terraform/openshift/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ variable "cluster_count" {
}

variable "tags" {
type = map
type = map(any)
default = {}
description = "Tags to attach to the created resources."
}
7 changes: 6 additions & 1 deletion control-plane/api/v1alpha1/proxydefaults_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ type ProxyDefaultsSpec struct {
Expose Expose `json:"expose,omitempty"`
// AccessLogs controls all envoy instances' access logging configuration.
AccessLogs *AccessLogs `json:"accessLogs,omitempty"`
// EnvoyExtensions are a list of extensions to modify Envoy proxy configuration.
EnvoyExtensions EnvoyExtensions `json:"envoyExtensions,omitempty"`
}

func (in *ProxyDefaults) GetObjectMeta() metav1.ObjectMeta {
Expand Down Expand Up @@ -168,6 +170,7 @@ func (in *ProxyDefaults) ToConsul(datacenter string) capi.ConfigEntry {
Config: consulConfig,
TransparentProxy: in.Spec.TransparentProxy.toConsul(),
AccessLogs: in.Spec.AccessLogs.toConsul(),
EnvoyExtensions: in.Spec.EnvoyExtensions.toConsul(),
Meta: meta(datacenter),
}
}
Expand Down Expand Up @@ -202,6 +205,8 @@ func (in *ProxyDefaults) Validate(_ common.ConsulMeta) error {
allErrs = append(allErrs, err)
}
allErrs = append(allErrs, in.Spec.Expose.validate(path.Child("expose"))...)
allErrs = append(allErrs, in.Spec.EnvoyExtensions.validate(path.Child("envoyExtensions"))...)

if len(allErrs) > 0 {
return apierrors.NewInvalid(
schema.GroupKind{Group: ConsulHashicorpGroup, Kind: ProxyDefaultsKubeKind},
Expand Down Expand Up @@ -239,7 +244,7 @@ func (in *ProxyDefaults) validateConfig(path *field.Path) *field.Error {
}
var outConfig map[string]interface{}
if err := json.Unmarshal(in.Spec.Config, &outConfig); err != nil {
return field.Invalid(path, in.Spec.Config, fmt.Sprintf(`must be valid map value: %s`, err))
return field.Invalid(path, string(in.Spec.Config), fmt.Sprintf(`must be valid map value: %s`, err))
Copy link
Contributor

Choose a reason for hiding this comment

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

❤️

}
return nil
}
Expand Down
Loading