Skip to content

Commit c7e6e9b

Browse files
ampantpleshakov
andcommitted
Addressed the PR comments
Co-Authored-By: Michael Pleshakov <[email protected]>
1 parent 94cf400 commit c7e6e9b

File tree

4 files changed

+41
-34
lines changed

4 files changed

+41
-34
lines changed

docs/virtualserver-and-virtualserverroute.md

+8-12
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ This document is the reference documentation for the resources. To see additiona
1818
- [VirtualServerRoute.Subroute](#virtualserverroutesubroute)
1919
- [Common Parts of the VirtualServer and VirtualServerRoute](#common-parts-of-the-virtualserver-and-virtualserverroute)
2020
- [Upstream](#upstream)
21+
- [Upstream.Buffers](#upstreambuffers)
2122
- [Upstream.TLS](#upstreamtls)
2223
- [Upstream.Healthcheck](#upstreamhealthcheck)
2324
- [Header](#header)
@@ -218,27 +219,22 @@ tls:
218219
| `tls` | The TLS configuration for the Upstream. | [`tls`](#UpstreamTLS) | No |
219220
| `healthCheck` | The health check configuration for the Upstream. See the [health_check](http://nginx.org/en/docs/http/ngx_http_upstream_hc_module.html#health_check) directive. Note: this feature is supported only in NGINX Plus. | [`healthcheck`](#UpstreamHealthcheck) | No |
220221
| `buffering` | Enables buffering of responses from the upstream server. See the [proxy_buffering](https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_buffering) directive. The default is set in the `proxy-buffering` ConfigMap key. | `boolean` | No |
221-
| `buffers` | Configures the buffers used for reading a response from the upstream server for a single connection. The buffers field configures the buffers used for reading a response from the upstream server for a single connection: number: 4 size: 8K . See the [proxy_buffers](https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_buffers) directive for additional information. | `buffers` | No |
222+
| `buffers` | Configures the buffers used for reading a response from the upstream server for a single connection. | [`buffers`](#UpstreamBuffers) | No |
222223
| `buffer-size` | Sets the size of the buffer used for reading the first part of a response received from the upstream server. See the [proxy_buffer_size](https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_buffer_size) directive. The default is set in the `proxy-buffer-size` ConfigMap key. | `string` | No |
223224

224225
### Upstream.Buffers
225-
Buffers defines Buffer Configuration for an Upstream. The buffers field configures the buffers used for reading a response from the upstream server for a single connection. For example
226+
The buffers field configures the buffers used for reading a response from the upstream server for a single connection:
226227

227228
```yaml
228-
name: tea
229-
service: tea-svc
230-
port: 80
231-
buffering: true
232-
buffers:
233-
number: 4
234-
size: 8K
235-
buffer-size: 16k
229+
number: 4
230+
size: 8K
236231
```
232+
See the [proxy_buffers](https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_buffers) directive for additional information.
237233

238234
| Field | Description | Type | Required |
239235
| ----- | ----------- | ---- | -------- |
240-
| `number` | Configures the number of buffers. The default is set in the `proxy-buffers` ConfigMap key. | `int` | Yes |
241-
| `size` | Configures the size of a buffer. The default is set in the `proxy-buffers` ConfigMap key. | `string` | Yes |
236+
| `number` | Configures the number of buffers. The default is set in the `proxy-buffers` ConfigMap key. | `int` | Yes |
237+
| `size` | Configures the size of a buffer. The default is set in the `proxy-buffers` ConfigMap key. | `string` | Yes |
242238

243239
### Upstream.TLS
244240

pkg/apis/configuration/v1alpha1/types.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ type Upstream struct {
4747
HealthCheck *HealthCheck `json:"healthCheck"`
4848
}
4949

50-
//UpstreamBuffers defines Buffer Configuration for an Upstream
50+
// UpstreamBuffers defines Buffer Configuration for an Upstream
5151
type UpstreamBuffers struct {
5252
Number int `json:"number"`
5353
Size string `json:"size"`

pkg/apis/configuration/validation/validation.go

+20-15
Original file line numberDiff line numberDiff line change
@@ -101,16 +101,16 @@ const offsetErrMsg = "must consist of numeric characters followed by a valid siz
101101

102102
var offsetRegexp = regexp.MustCompile("^" + offsetFmt + "$")
103103

104-
func validateOffset(size string, fieldPath *field.Path) field.ErrorList {
104+
func validateOffset(offset string, fieldPath *field.Path) field.ErrorList {
105105
allErrs := field.ErrorList{}
106106

107-
if size == "" {
107+
if offset == "" {
108108
return allErrs
109109
}
110110

111-
if !offsetRegexp.MatchString(size) {
111+
if !offsetRegexp.MatchString(offset) {
112112
msg := validation.RegexError(offsetErrMsg, offsetFmt, "16", "32k", "64M")
113-
return append(allErrs, field.Invalid(fieldPath, size, msg))
113+
return append(allErrs, field.Invalid(fieldPath, offset, msg))
114114
}
115115

116116
return allErrs
@@ -121,32 +121,37 @@ const sizeErrMsg = "must consist of numeric characters followed by a valid size
121121

122122
var sizeRegexp = regexp.MustCompile("^" + sizeFmt + "$")
123123

124-
func validateBuffer(buff *v1alpha1.UpstreamBuffers, fieldPath *field.Path) field.ErrorList {
124+
func validateSize(size string, fieldPath *field.Path) field.ErrorList {
125125
allErrs := field.ErrorList{}
126126

127-
if buff == nil {
127+
if size == "" {
128128
return allErrs
129129
}
130130

131-
if buff.Number <= 0 {
132-
return append(allErrs, field.Invalid(fieldPath, buff.Number, "must be positive"))
131+
if !sizeRegexp.MatchString(size) {
132+
msg := validation.RegexError(sizeErrMsg, sizeFmt, "16", "32k", "64M")
133+
return append(allErrs, field.Invalid(fieldPath, size, msg))
133134
}
134-
135-
allErrs = validateSize(buff.Size, fieldPath)
136135
return allErrs
137136
}
138137

139-
func validateSize(size string, fieldPath *field.Path) field.ErrorList {
138+
func validateBuffer(buff *v1alpha1.UpstreamBuffers, fieldPath *field.Path) field.ErrorList {
140139
allErrs := field.ErrorList{}
141140

142-
if size == "" {
141+
if buff == nil {
143142
return allErrs
144143
}
145144

146-
if !sizeRegexp.MatchString(size) {
147-
msg := validation.RegexError(sizeErrMsg, sizeFmt, "16", "32k", "64M")
148-
return append(allErrs, field.Invalid(fieldPath, size, msg))
145+
if buff.Number <= 0 {
146+
allErrs = append(allErrs, field.Invalid(fieldPath.Child("number"), buff.Number, "must be positive"))
149147
}
148+
149+
if buff.Size == "" {
150+
allErrs = append(allErrs, field.Required(fieldPath.Child("size"), "cannot be empty"))
151+
} else {
152+
allErrs = append(validateSize(buff.Size, fieldPath.Child("size")))
153+
}
154+
150155
return allErrs
151156
}
152157

pkg/apis/configuration/validation/validation_test.go

+12-6
Original file line numberDiff line numberDiff line change
@@ -1690,17 +1690,17 @@ func TestValidateTime(t *testing.T) {
16901690
}
16911691

16921692
func TestValidateOffset(t *testing.T) {
1693-
var validInput = []string{"", "1", "10k", "11m", "1K", "100M"}
1693+
var validInput = []string{"", "1", "10k", "11m", "1K", "100M", "5G"}
16941694
for _, test := range validInput {
1695-
allErrs := validateOffset(test, field.NewPath("size-field"))
1695+
allErrs := validateOffset(test, field.NewPath("offset-field"))
16961696
if len(allErrs) != 0 {
16971697
t.Errorf("validateOffset(%q) returned an error for valid input", test)
16981698
}
16991699
}
17001700

1701-
var invalidInput = []string{"55mm", "2mG", "6kb", "-5k", "1L"}
1701+
var invalidInput = []string{"55mm", "2mG", "6kb", "-5k", "1L", "5Gb"}
17021702
for _, test := range invalidInput {
1703-
allErrs := validateOffset(test, field.NewPath("size-field"))
1703+
allErrs := validateOffset(test, field.NewPath("offset-field"))
17041704
if len(allErrs) == 0 {
17051705
t.Errorf("validateOffset(%q) didn't return error for invalid input.", test)
17061706
}
@@ -1718,13 +1718,19 @@ func TestValidateBuffer(t *testing.T) {
17181718
invalidbuff := &v1alpha1.UpstreamBuffers{Number: -8, Size: "15G"}
17191719
allErrs = validateBuffer(invalidbuff, field.NewPath("buffers-field"))
17201720
if len(allErrs) == 0 {
1721-
t.Errorf("validateBuffer didn't return error %v for invalid input %v.", allErrs, invalidbuff)
1721+
t.Errorf("validateBuffer didn't return error for invalid input %v.", invalidbuff)
17221722
}
17231723

17241724
invalidbuff = &v1alpha1.UpstreamBuffers{Number: 8, Size: "15G"}
17251725
allErrs = validateBuffer(invalidbuff, field.NewPath("buffers-field"))
17261726
if len(allErrs) == 0 {
1727-
t.Errorf("validateBuffer didn't return error %v for invalid input %v.", allErrs, invalidbuff)
1727+
t.Errorf("validateBuffer didn't return error for invalid input %v.", invalidbuff)
1728+
}
1729+
1730+
invalidbuff = &v1alpha1.UpstreamBuffers{Number: 8, Size: ""}
1731+
allErrs = validateBuffer(invalidbuff, field.NewPath("buffers-field"))
1732+
if len(allErrs) == 0 {
1733+
t.Errorf("validateBuffer didn't return error for invalid input %v.", invalidbuff)
17281734
}
17291735
}
17301736

0 commit comments

Comments
 (0)