Skip to content

Commit

Permalink
fix: missing MaxInboundConnections in service-defaults CRD (#1437)
Browse files Browse the repository at this point in the history
  • Loading branch information
huikang committed Aug 23, 2022
1 parent 2bb85a7 commit 13b5926
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 14 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
## UNRELEASED
FEATURES:
* MaxInboundConnections in service-defaults CRD
* Add support for MaxInboundConnections on the Service Defaults CRD. [[GH-1437](https://github.com/hashicorp/consul-k8s/pull/1437)]

IMPROVEMENTS:
* CLI:
Expand Down
5 changes: 5 additions & 0 deletions charts/consul/templates/crd-servicedefaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ spec:
TLS SNI value to be changed to a non-connect value when federating
with an external system.
type: string
maxInboundConnections:
description: MaxInboundConnections is the maximum number of concurrent
inbound connections to each service instance. Defaults to 0 (using
consul's default) if not set.
type: integer
meshGateway:
description: MeshGateway controls the default mesh gateway configuration
for this service.
Expand Down
29 changes: 19 additions & 10 deletions control-plane/api/v1alpha1/servicedefaults_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ type ServiceDefaultsSpec struct {
// mode. Destinations live outside of Consul's catalog, and because of this, they
// do not require an artificial node to be created.
Destination *ServiceDefaultsDestination `json:"destination,omitempty"`
// MaxInboundConnections is the maximum number of concurrent inbound connections to
// each service instance. Defaults to 0 (using consul's default) if not set.
MaxInboundConnections int `json:"maxInboundConnections,omitempty"`
}

type Upstreams struct {
Expand Down Expand Up @@ -245,16 +248,17 @@ func (in *ServiceDefaults) SyncedConditionStatus() corev1.ConditionStatus {
// ToConsul converts the entry into it's Consul equivalent struct.
func (in *ServiceDefaults) ToConsul(datacenter string) capi.ConfigEntry {
return &capi.ServiceConfigEntry{
Kind: in.ConsulKind(),
Name: in.ConsulName(),
Protocol: in.Spec.Protocol,
MeshGateway: in.Spec.MeshGateway.toConsul(),
Expose: in.Spec.Expose.toConsul(),
ExternalSNI: in.Spec.ExternalSNI,
TransparentProxy: in.Spec.TransparentProxy.toConsul(),
UpstreamConfig: in.Spec.UpstreamConfig.toConsul(),
Destination: in.Spec.Destination.toConsul(),
Meta: meta(datacenter),
Kind: in.ConsulKind(),
Name: in.ConsulName(),
Protocol: in.Spec.Protocol,
MeshGateway: in.Spec.MeshGateway.toConsul(),
Expose: in.Spec.Expose.toConsul(),
ExternalSNI: in.Spec.ExternalSNI,
TransparentProxy: in.Spec.TransparentProxy.toConsul(),
UpstreamConfig: in.Spec.UpstreamConfig.toConsul(),
Destination: in.Spec.Destination.toConsul(),
Meta: meta(datacenter),
MaxInboundConnections: in.Spec.MaxInboundConnections,
}
}

Expand All @@ -280,6 +284,11 @@ func (in *ServiceDefaults) Validate(consulMeta common.ConsulMeta) error {
if err := in.Spec.Destination.validate(path.Child("destination")); err != nil {
allErrs = append(allErrs, err...)
}

if in.Spec.MaxInboundConnections < 0 {
allErrs = append(allErrs, field.Invalid(path.Child("maxinboundconnections"), in.Spec.MaxInboundConnections, "MaxInboundConnections must be > 0"))
}

allErrs = append(allErrs, in.Spec.UpstreamConfig.validate(path.Child("upstreamConfig"), consulMeta.PartitionsEnabled)...)
allErrs = append(allErrs, in.Spec.Expose.validate(path.Child("expose"))...)

Expand Down
2 changes: 2 additions & 0 deletions control-plane/api/v1alpha1/servicedefaults_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ func TestServiceDefaults_ToConsul(t *testing.T) {
Addresses: []string{"api.google.com"},
Port: 443,
},
MaxInboundConnections: 20,
},
},
&capi.ServiceConfigEntry{
Expand Down Expand Up @@ -243,6 +244,7 @@ func TestServiceDefaults_ToConsul(t *testing.T) {
Addresses: []string{"api.google.com"},
Port: 443,
},
MaxInboundConnections: 20,
Meta: map[string]string{
common.SourceKey: common.SourceValue,
common.DatacenterKey: "datacenter",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ spec:
TLS SNI value to be changed to a non-connect value when federating
with an external system.
type: string
maxInboundConnections:
description: MaxInboundConnections is the maximum number of concurrent
inbound connections to each service instance. Defaults to 0 (using
consul's default) if not set.
type: integer
meshGateway:
description: MeshGateway controls the default mesh gateway configuration
for this service.
Expand Down
4 changes: 3 additions & 1 deletion control-plane/controller/configentry_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ func TestConfigEntryControllers_createsConfigEntry(t *testing.T) {
Namespace: kubeNS,
},
Spec: v1alpha1.ServiceDefaultsSpec{
Protocol: "http",
Protocol: "http",
MaxInboundConnections: 100,
},
},
reconciler: func(client client.Client, consulClient *capi.Client, logger logr.Logger) testReconciler {
Expand All @@ -68,6 +69,7 @@ func TestConfigEntryControllers_createsConfigEntry(t *testing.T) {
svcDefault, ok := consulEntry.(*capi.ServiceConfigEntry)
require.True(t, ok, "cast error")
require.Equal(t, "http", svcDefault.Protocol)
require.Equal(t, 100, svcDefault.MaxInboundConnections)
},
},
{
Expand Down
2 changes: 1 addition & 1 deletion control-plane/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/go-logr/logr v0.4.0
github.com/google/go-cmp v0.5.7
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
github.com/hashicorp/consul/api v1.14.0
github.com/hashicorp/consul/api v1.10.1-0.20220822180451-60c82757ea35
github.com/hashicorp/consul/sdk v0.11.0
github.com/hashicorp/go-discover v0.0.0-20200812215701-c4b85f6ed31f
github.com/hashicorp/go-hclog v0.16.1
Expand Down
4 changes: 2 additions & 2 deletions control-plane/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,8 @@ github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgf
github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
github.com/hashicorp/consul/api v1.1.0/go.mod h1:VmuI/Lkw1nC05EYQWNKwWGbkg+FbDBtguAZLlVdkD9Q=
github.com/hashicorp/consul/api v1.14.0 h1:Y64GIJ8hYTu+tuGekwO4G4ardXoiCivX9wv1iP/kihk=
github.com/hashicorp/consul/api v1.14.0/go.mod h1:bcaw5CSZ7NE9qfOfKCI1xb7ZKjzu/MyvQkCLTfqLqxQ=
github.com/hashicorp/consul/api v1.10.1-0.20220822180451-60c82757ea35 h1:csNww5qBHaFqsX1eMEKVvmJ4dhqcXWj0sCkbccsSsHc=
github.com/hashicorp/consul/api v1.10.1-0.20220822180451-60c82757ea35/go.mod h1:bcaw5CSZ7NE9qfOfKCI1xb7ZKjzu/MyvQkCLTfqLqxQ=
github.com/hashicorp/consul/sdk v0.1.1/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8=
github.com/hashicorp/consul/sdk v0.4.1-0.20220801192236-988e1fd35d51/go.mod h1:yPkX5Q6CsxTFMjQQDJwzeNmUUF5NUGGbrDsv9wTb8cw=
github.com/hashicorp/consul/sdk v0.11.0 h1:HRzj8YSCln2yGgCumN5CL8lYlD3gBurnervJRJAZyC4=
Expand Down

0 comments on commit 13b5926

Please sign in to comment.