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

fix: missing MaxInboundConnections in service-defaults CRD #1437

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
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)]

## 0.47.1 (August 12, 2022)

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
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this should point to the 1.14 API package?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@david-yu , thanks for the feedback. This PR depends on the change in consul after api/v1.14.0. So shall I create a new tag for consul/api?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it is ok not to create a tag! We do use the above format to include unreleased API changes. It is strange only because golang interprets it as some 1.10.1-* version even though it contains all the 1.14 changes but that has been true for sometime now.

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