Add GRPC Buffer Size to the Configmap (#11155)
* feat: add grpc buffer size in the nginx template * feat: add grpc buffer size in the configmap struct * feat: add test for GRCP buffer size configuration in the configmap * chore: add documentation for the grcp buffer size configuration * fix: fix the copyright year of the test * fix: fix import order * fix: fix ignore for the linter - reason was missing * chore: seems like we don't need to ignore the error handling
This commit is contained in:
parent
c25b80ca00
commit
c0b3294bf4
4 changed files with 338 additions and 211 deletions
|
@ -26,7 +26,7 @@ data:
|
|||
The following table shows a configuration option's name, type, and the default value:
|
||||
|
||||
|name| type | default |notes|
|
||||
|:---|:---|:------|:----|
|
||||
|:---|:-------------|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|:----|
|
||||
|[add-headers](#add-headers)| string | "" ||
|
||||
|[allow-backend-server-header](#allow-backend-server-header)| bool | "false" ||
|
||||
|[allow-cross-namespace-resources](#allow-cross-namespace-resources)| bool | "true" ||
|
||||
|
@ -234,6 +234,7 @@ The following table shows a configuration option's name, type, and the default v
|
|||
|[ssl-reject-handshake](#ssl-reject-handshake)| bool | "false" ||
|
||||
|[debug-connections](#debug-connections)| []string | "127.0.0.1,1.1.1.1/24" ||
|
||||
|[strict-validate-path-type](#strict-validate-path-type)| bool | "false" (v1.7.x) ||
|
||||
|[grpc-buffer-size-kb](#grpc-buffer-size-kb)| int | 0 ||
|
||||
|
||||
## add-headers
|
||||
|
||||
|
@ -1432,3 +1433,10 @@ This means that Ingress objects that rely on paths containing regex characters s
|
|||
|
||||
The cluster admin should establish validation rules using mechanisms like [Open Policy Agent](https://www.openpolicyagent.org/) to
|
||||
validate that only authorized users can use `ImplementationSpecific` pathType and that only the authorized characters can be used.
|
||||
|
||||
## grpc-buffer-size-kb
|
||||
|
||||
Sets the configuration for the GRPC Buffer Size parameter. If not set it will use the default from NGINX.
|
||||
|
||||
_References:_
|
||||
[https://nginx.org/en/docs/http/ngx_http_grpc_module.html#grpc_buffer_size](https://nginx.org/en/docs/http/ngx_http_grpc_module.html#grpc_buffer_size)
|
|
@ -20,9 +20,8 @@ import (
|
|||
"strconv"
|
||||
"time"
|
||||
|
||||
"k8s.io/klog/v2"
|
||||
|
||||
apiv1 "k8s.io/api/core/v1"
|
||||
"k8s.io/klog/v2"
|
||||
|
||||
"k8s.io/ingress-nginx/internal/ingress/defaults"
|
||||
"k8s.io/ingress-nginx/pkg/apis/ingress"
|
||||
|
@ -752,6 +751,11 @@ type Configuration struct {
|
|||
// alphanumeric chars, "-", "_", "/".In case of additional characters,
|
||||
// like used on Rewrite configurations the user should use pathType as ImplementationSpecific
|
||||
StrictValidatePathType bool `json:"strict-validate-path-type"`
|
||||
|
||||
// GRPCBufferSizeKb Sets the size of the buffer used for reading the response received
|
||||
// from the gRPC server. The response is passed to the client synchronously,
|
||||
// as soon as it is received.
|
||||
GRPCBufferSizeKb int `json:"grpc-buffer-size-kb"`
|
||||
}
|
||||
|
||||
// NewDefault returns the default nginx configuration
|
||||
|
@ -917,6 +921,7 @@ func NewDefault() Configuration {
|
|||
GlobalRateLimitStatucCode: 429,
|
||||
DebugConnections: []string{},
|
||||
StrictValidatePathType: false, // TODO: This will be true in future releases
|
||||
GRPCBufferSizeKb: 0,
|
||||
}
|
||||
|
||||
if klog.V(5).Enabled() {
|
||||
|
|
|
@ -331,6 +331,10 @@ http {
|
|||
client_body_buffer_size {{ $cfg.ClientBodyBufferSize }};
|
||||
client_body_timeout {{ $cfg.ClientBodyTimeout }}s;
|
||||
|
||||
{{ if gt $cfg.GRPCBufferSizeKb 0 }}
|
||||
grpc_buffer_size {{ $cfg.GRPCBufferSizeKb }}k;
|
||||
{{ end }}
|
||||
|
||||
{{ if and (ne $cfg.HTTP2MaxHeaderSize "") (ne $cfg.HTTP2MaxFieldSize "") }}
|
||||
http2_max_field_size {{ $cfg.HTTP2MaxFieldSize }};
|
||||
http2_max_header_size {{ $cfg.HTTP2MaxHeaderSize }};
|
||||
|
|
110
test/e2e/settings/grpc.go
Normal file
110
test/e2e/settings/grpc.go
Normal file
|
@ -0,0 +1,110 @@
|
|||
/*
|
||||
Copyright 2024 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package settings
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
pb "github.com/moul/pb/grpcbin/go-grpc"
|
||||
"github.com/onsi/ginkgo/v2"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/util/intstr"
|
||||
|
||||
"k8s.io/ingress-nginx/test/e2e/framework"
|
||||
)
|
||||
|
||||
const echoHost = "echo"
|
||||
|
||||
var _ = framework.DescribeSetting("GRPC", func() {
|
||||
f := framework.NewDefaultFramework("grpc-buffersize", framework.WithHTTPBunEnabled())
|
||||
|
||||
ginkgo.It("should set the correct GRPC Buffer Size", func() {
|
||||
f.SetNginxConfigMapData(map[string]string{
|
||||
"grpc-buffer-size-kb": "8",
|
||||
})
|
||||
|
||||
f.WaitForNginxConfiguration(
|
||||
func(cfg string) bool {
|
||||
return strings.Contains(cfg, "grpc_buffer_size 8k")
|
||||
})
|
||||
|
||||
f.NewGRPCBinDeployment()
|
||||
|
||||
host := echoHost
|
||||
|
||||
svc := &corev1.Service{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "grpcbin-test",
|
||||
Namespace: f.Namespace,
|
||||
},
|
||||
Spec: corev1.ServiceSpec{
|
||||
ExternalName: fmt.Sprintf("grpcbin.%v.svc.cluster.local", f.Namespace),
|
||||
Type: corev1.ServiceTypeExternalName,
|
||||
Ports: []corev1.ServicePort{
|
||||
{
|
||||
Name: host,
|
||||
Port: 9000,
|
||||
TargetPort: intstr.FromInt(9000),
|
||||
Protocol: "TCP",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
f.EnsureService(svc)
|
||||
|
||||
annotations := map[string]string{
|
||||
"nginx.ingress.kubernetes.io/backend-protocol": "GRPC",
|
||||
}
|
||||
|
||||
ing := framework.NewSingleIngressWithTLS(host, "/", host, []string{host}, f.Namespace, "grpcbin-test", 9000, annotations)
|
||||
|
||||
f.EnsureIngress(ing)
|
||||
|
||||
f.WaitForNginxServer(host,
|
||||
func(server string) bool {
|
||||
return strings.Contains(server, "grpc_pass grpc://upstream_balancer;")
|
||||
})
|
||||
|
||||
conn, err := grpc.Dial(f.GetNginxIP()+":443",
|
||||
grpc.WithTransportCredentials(
|
||||
credentials.NewTLS(&tls.Config{
|
||||
ServerName: echoHost,
|
||||
InsecureSkipVerify: true, //nolint:gosec // Ignore certificate validation in testing
|
||||
}),
|
||||
),
|
||||
)
|
||||
assert.Nil(ginkgo.GinkgoT(), err, "error creating a connection")
|
||||
defer conn.Close()
|
||||
|
||||
client := pb.NewGRPCBinClient(conn)
|
||||
ctx := context.Background()
|
||||
|
||||
res, err := client.HeadersUnary(ctx, &pb.EmptyMessage{})
|
||||
assert.Nil(ginkgo.GinkgoT(), err)
|
||||
|
||||
metadata := res.GetMetadata()
|
||||
assert.Equal(ginkgo.GinkgoT(), metadata["content-type"].Values[0], "application/grpc")
|
||||
assert.Equal(ginkgo.GinkgoT(), metadata[":authority"].Values[0], host)
|
||||
})
|
||||
})
|
Loading…
Reference in a new issue