Skip to content

Commit

Permalink
Inline IngressServiceConfig for DRY validatino
Browse files Browse the repository at this point in the history
  • Loading branch information
analogue committed Nov 10, 2022
1 parent 77fb7c7 commit 9a8ab4d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 57 deletions.
24 changes: 2 additions & 22 deletions control-plane/api/v1alpha1/ingressgateway_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,17 +162,7 @@ type IngressService struct {
RequestHeaders *HTTPHeaderModifiers `json:"requestHeaders,omitempty"`
ResponseHeaders *HTTPHeaderModifiers `json:"responseHeaders,omitempty"`

// The maximum number of connections a service instance
// will be allowed to establish against the given upstream. Use this to limit
// HTTP/1.1 traffic, since HTTP/1.1 has a request per connection.
MaxConnections *uint32 `json:"maxConnections,omitempty"`
// The maximum number of requests that will be queued
// while waiting for a connection to be established.
MaxPendingRequests *uint32 `json:"maxPendingRequests,omitempty"`
// The maximum number of concurrent requests that
// will be allowed at a single point in time. Use this to limit HTTP/2 traffic,
// since HTTP/2 has many requests per connection.
MaxConcurrentRequests *uint32 `json:"maxConcurrentRequests,omitempty"`
IngressServiceConfig `json:",inline"`
}

func (in *IngressGateway) GetObjectMeta() metav1.ObjectMeta {
Expand Down Expand Up @@ -442,17 +432,7 @@ func (in IngressListener) validate(path *field.Path, consulMeta common.ConsulMet
"hosts must be empty if protocol is \"tcp\""))
}

if svc.MaxConnections != nil && *svc.MaxConnections <= 0 {
errs = append(errs, field.Invalid(path.Child("maxconnections"), *svc.MaxConnections, "MaxConnections must be > 0"))
}

if svc.MaxConcurrentRequests != nil && *svc.MaxConcurrentRequests <= 0 {
errs = append(errs, field.Invalid(path.Child("maxconcurrentrequests"), *svc.MaxConcurrentRequests, "MaxConcurrentRequests must be > 0"))
}

if svc.MaxPendingRequests != nil && *svc.MaxPendingRequests <= 0 {
errs = append(errs, field.Invalid(path.Child("maxpendingrequests"), *svc.MaxPendingRequests, "MaxPendingRequests must be > 0"))
}
errs = append(errs, svc.IngressServiceConfig.validate(path)...)
}
return errs
}
Expand Down
50 changes: 30 additions & 20 deletions control-plane/api/v1alpha1/ingressgateway_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,15 @@ func TestIngressGateway_MatchesConsul(t *testing.T) {
},
Services: []IngressService{
{
Name: "name1",
Hosts: []string{"host1_1", "host1_2"},
Namespace: "ns1",
Partition: "default",
MaxConnections: &maxConnections,
MaxPendingRequests: &maxPendingRequests,
MaxConcurrentRequests: &maxConcurrentRequests,
Name: "name1",
Hosts: []string{"host1_1", "host1_2"},
Namespace: "ns1",
Partition: "default",
IngressServiceConfig: IngressServiceConfig{
MaxConnections: &maxConnections,
MaxPendingRequests: &maxPendingRequests,
MaxConcurrentRequests: &maxConcurrentRequests,
},
TLS: &GatewayServiceTLSConfig{
SDS: &GatewayTLSSDSConfig{
ClusterName: "cluster1",
Expand Down Expand Up @@ -344,13 +346,15 @@ func TestIngressGateway_ToConsul(t *testing.T) {
},
Services: []IngressService{
{
Name: "name1",
Hosts: []string{"host1_1", "host1_2"},
Namespace: "ns1",
Partition: "default",
MaxConnections: &maxConnections,
MaxPendingRequests: &maxPendingRequests,
MaxConcurrentRequests: &maxConcurrentRequests,
Name: "name1",
Hosts: []string{"host1_1", "host1_2"},
Namespace: "ns1",
Partition: "default",
IngressServiceConfig: IngressServiceConfig{
MaxConnections: &maxConnections,
MaxPendingRequests: &maxPendingRequests,
MaxConcurrentRequests: &maxConcurrentRequests,
},
TLS: &GatewayServiceTLSConfig{
SDS: &GatewayTLSSDSConfig{
ClusterName: "cluster1",
Expand Down Expand Up @@ -893,8 +897,10 @@ func TestIngressGateway_Validate(t *testing.T) {
Protocol: "http",
Services: []IngressService{
{
Name: "svc1",
MaxConnections: &zero,
Name: "svc1",
IngressServiceConfig: IngressServiceConfig{
MaxConnections: &zero,
},
},
},
},
Expand All @@ -916,8 +922,10 @@ func TestIngressGateway_Validate(t *testing.T) {
Protocol: "http",
Services: []IngressService{
{
Name: "svc1",
MaxConcurrentRequests: &zero,
Name: "svc1",
IngressServiceConfig: IngressServiceConfig{
MaxConcurrentRequests: &zero,
},
},
},
},
Expand All @@ -939,8 +947,10 @@ func TestIngressGateway_Validate(t *testing.T) {
Protocol: "http",
Services: []IngressService{
{
Name: "svc1",
MaxPendingRequests: &zero,
Name: "svc1",
IngressServiceConfig: IngressServiceConfig{
MaxPendingRequests: &zero,
},
},
},
},
Expand Down
16 changes: 1 addition & 15 deletions control-plane/api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9a8ab4d

Please sign in to comment.