Skip to content

Commit

Permalink
Rename Int64Range to HTTPStatusRange for clearer semantics.
Browse files Browse the repository at this point in the history
Signed-off-by: lemonlinger <lemonlinger@gmail.com>
  • Loading branch information
lemonlinger committed Dec 4, 2023
1 parent 7b880e7 commit 1b90fcc
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 39 deletions.
11 changes: 8 additions & 3 deletions api/v1alpha1/healthcheck_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ type HTTPHealthChecker struct {
Method *string `json:"method,omitempty" yaml:"method,omitempty"`
// ExpectedStatuses defines a list of HTTP response statuses considered healthy.
// +optional
ExpectedStatuses []Int64Range `json:"expectedStatuses,omitempty" yaml:"expectedStatuses,omitempty"`
ExpectedStatuses []HTTPStatusRange `json:"expectedStatuses,omitempty" yaml:"expectedStatuses,omitempty"`
// ExpectedResponses defines a list of HTTP expected responses to match.
// +optional
ExpectedResponses []HealthCheckPayload `json:"expectedResponses,omitempty" yaml:"expectedResponses,omitempty"`
Expand Down Expand Up @@ -120,12 +120,17 @@ type TCPHealthChecker struct {
Receive []HealthCheckPayload `json:"receive,omitempty" yaml:"receive,omitempty"`
}

// Int64Range defines the int64 start and end of the range using half-open interval semantics [start, end).
// HTTPStatusRange defines the start and end of the http status range using half-open interval semantics [start, end). Only statuses in the range [100, 600) are allowed.
// +kubebuilder:validation:XValidation:rule="self.start <= self.end",message="start should be not greater than end"
type Int64Range struct {
type HTTPStatusRange struct {
// Start defines start of the range (inclusive)
// +kubebuilder:validation:Minimum=100
// +kubebuilder:validation:Maximum=600
// +kubebuilder:validation:ExclusiveMaximum=true
Start int64 `json:"start" yaml:"start"`
// End defines end of the range (exclusive)
// +kubebuilder:validation:Minimum=100
// +kubebuilder:validation:Maximum=600
End int64 `json:"end" yaml:"end"`
}

Expand Down
32 changes: 16 additions & 16 deletions api/v1alpha1/zz_generated.deepcopy.go

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

Original file line number Diff line number Diff line change
Expand Up @@ -115,17 +115,23 @@ spec:
description: ExpectedStatuses defines a list of HTTP response
statuses considered healthy.
items:
description: Int64Range defines the int64 start and
end of the range using half-open interval semantics
[start, end).
description: HTTPStatusRange defines the start and end
of the http status range using half-open interval
semantics [start, end). Only statuses in the range
[100, 600) are allowed.
properties:
end:
description: End defines end of the range (exclusive)
format: int64
maximum: 600
minimum: 100
type: integer
start:
description: Start defines start of the range (inclusive)
exclusiveMaximum: true
format: int64
maximum: 600
minimum: 100
type: integer
required:
- end
Expand Down
32 changes: 16 additions & 16 deletions site/content/en/latest/api/extension_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -862,10 +862,25 @@ _Appears in:_
| --- | --- |
| `path` _string_ | Path defines the HTTP path that will be requested during health checking. |
| `method` _string_ | Method defines the HTTP method used for health checking. Defaults to GET |
| `expectedStatuses` _[Int64Range](#int64range) array_ | ExpectedStatuses defines a list of HTTP response statuses considered healthy. |
| `expectedStatuses` _[HTTPStatusRange](#httpstatusrange) array_ | ExpectedStatuses defines a list of HTTP response statuses considered healthy. |
| `expectedResponses` _[HealthCheckPayload](#healthcheckpayload) array_ | ExpectedResponses defines a list of HTTP expected responses to match. |


#### HTTPStatusRange



HTTPStatusRange defines the start and end of the http status range using half-open interval semantics [start, end). Only statuses in the range [100, 600) are allowed.

_Appears in:_
- [HTTPHealthChecker](#httphealthchecker)

| Field | Description |
| --- | --- |
| `start` _integer_ | Start defines start of the range (inclusive) |
| `end` _integer_ | End defines end of the range (exclusive) |


#### HeaderMatch


Expand Down Expand Up @@ -962,21 +977,6 @@ _Appears in:_



#### Int64Range



Int64Range defines the int64 start and end of the range using half-open interval semantics [start, end).

_Appears in:_
- [HTTPHealthChecker](#httphealthchecker)

| Field | Description |
| --- | --- |
| `start` _integer_ | Start defines start of the range (inclusive) |
| `end` _integer_ | End defines end of the range (exclusive) |


#### JSONPatchOperation


Expand Down
55 changes: 54 additions & 1 deletion test/cel-validation/backendtrafficpolicy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ func TestBackendTrafficPolicyTarget(t *testing.T) {
Type: egv1a1.HealthCheckerTypeHTTP,
HTTP: &egv1a1.HTTPHealthChecker{
Path: "/healthz",
ExpectedStatuses: []egv1a1.Int64Range{{Start: 400, End: 200}},
ExpectedStatuses: []egv1a1.HTTPStatusRange{{Start: 400, End: 200}},
},
},
},
Expand All @@ -433,6 +433,59 @@ func TestBackendTrafficPolicyTarget(t *testing.T) {
`spec.healthCheck.healthChecker.http.expectedStatuses[0]: Invalid value: "object": start should be not greater than end`,
},
},
{
desc: "valid http expected statuses",
mutate: func(btp *egv1a1.BackendTrafficPolicy) {
btp.Spec = egv1a1.BackendTrafficPolicySpec{
TargetRef: gwapiv1a2.PolicyTargetReferenceWithSectionName{
PolicyTargetReference: gwapiv1a2.PolicyTargetReference{
Group: gwapiv1a2.Group("gateway.networking.k8s.io"),
Kind: gwapiv1a2.Kind("Gateway"),
Name: gwapiv1a2.ObjectName("eg"),
},
},
HealthCheck: &egv1a1.HealthCheck{
HealthChecker: egv1a1.HealthChecker{
Type: egv1a1.HealthCheckerTypeHTTP,
HTTP: &egv1a1.HTTPHealthChecker{
Path: "/healthz",
ExpectedStatuses: []egv1a1.HTTPStatusRange{{Start: 100, End: 600}},
},
},
},
}
},
wantErrors: []string{},
},
{
desc: "invalid http expected statuses - out of range",
mutate: func(btp *egv1a1.BackendTrafficPolicy) {
btp.Spec = egv1a1.BackendTrafficPolicySpec{
TargetRef: gwapiv1a2.PolicyTargetReferenceWithSectionName{
PolicyTargetReference: gwapiv1a2.PolicyTargetReference{
Group: gwapiv1a2.Group("gateway.networking.k8s.io"),
Kind: gwapiv1a2.Kind("Gateway"),
Name: gwapiv1a2.ObjectName("eg"),
},
},
HealthCheck: &egv1a1.HealthCheck{
HealthChecker: egv1a1.HealthChecker{
Type: egv1a1.HealthCheckerTypeHTTP,
HTTP: &egv1a1.HTTPHealthChecker{
Path: "/healthz",
ExpectedStatuses: []egv1a1.HTTPStatusRange{
{Start: 600, End: 600},
{Start: 200, End: 700},
},
},
},
},
}
},
wantErrors: []string{
`spec.healthCheck.healthChecker.http.expectedStatuses[0].start: Invalid value: 600: spec.healthCheck.healthChecker.http.expectedStatuses[0].start in body should be less than 600, spec.healthCheck.healthChecker.http.expectedStatuses[1].end: Invalid value: 700: spec.healthCheck.healthChecker.http.expectedStatuses[1].end in body should be less than or equal to 600`,
},
},
{
desc: "invalid http expected responses",
mutate: func(btp *egv1a1.BackendTrafficPolicy) {
Expand Down

0 comments on commit 1b90fcc

Please sign in to comment.