Skip to content

Commit

Permalink
apis: replace unsigned integers in CRD fields with signed integers, a…
Browse files Browse the repository at this point in the history
…dd validation

This commit replaces the unsigned integers in the HTTPProxy and IngressRoute CRDs
with signed integers. Unsigned integers are discouraged due to API compatibility
issues. Validation rules have been added to the fields to ensure that the value
provided is always positive.

Fixes #2123

Signed-off-by: Alex Price <aprice@atlassian.com>
  • Loading branch information
awprice committed Jan 21, 2020
1 parent 9ebdf37 commit 133d8db
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 42 deletions.
9 changes: 6 additions & 3 deletions apis/contour/v1beta1/ingressroute.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ type Service struct {
Port int `json:"port"`
// Weight defines percentage of traffic to balance traffic
// +optional
Weight uint32 `json:"weight,omitempty"`
// +kubebuilder:validation:Minimum=0
Weight int64 `json:"weight,omitempty"`
// HealthCheck defines optional healthchecks on the upstream service
// +optional
HealthCheck *HealthCheck `json:"healthCheck,omitempty"`
Expand Down Expand Up @@ -115,10 +116,12 @@ type HealthCheck struct {
TimeoutSeconds int64 `json:"timeoutSeconds"`
// The number of unhealthy health checks required before a host is marked unhealthy
// +optional
UnhealthyThresholdCount uint32 `json:"unhealthyThresholdCount"`
// +kubebuilder:validation:Minimum=0
UnhealthyThresholdCount int64 `json:"unhealthyThresholdCount"`
// The number of healthy health checks required before a host is marked healthy
// +optional
HealthyThresholdCount uint32 `json:"healthyThresholdCount"`
// +kubebuilder:validation:Minimum=0
HealthyThresholdCount int64 `json:"healthyThresholdCount"`
}

// Delegate allows for delegating VHosts to other IngressRoutes
Expand Down
12 changes: 8 additions & 4 deletions apis/projectcontour/v1/httpproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,8 @@ type Service struct {
Protocol *string `json:"protocol,omitempty"`
// Weight defines percentage of traffic to balance traffic
// +optional
Weight uint32 `json:"weight,omitempty"`
// +kubebuilder:validation:Minimum=0
Weight int64 `json:"weight,omitempty"`
// UpstreamValidation defines how to verify the backend service's certificate
// +optional
UpstreamValidation *UpstreamValidation `json:"validation,omitempty"`
Expand Down Expand Up @@ -232,10 +233,12 @@ type HTTPHealthCheckPolicy struct {
TimeoutSeconds int64 `json:"timeoutSeconds"`
// The number of unhealthy health checks required before a host is marked unhealthy
// +optional
UnhealthyThresholdCount uint32 `json:"unhealthyThresholdCount"`
// +kubebuilder:validation:Minimum=0
UnhealthyThresholdCount int64 `json:"unhealthyThresholdCount"`
// The number of healthy health checks required before a host is marked healthy
// +optional
HealthyThresholdCount uint32 `json:"healthyThresholdCount"`
// +kubebuilder:validation:Minimum=0
HealthyThresholdCount int64 `json:"healthyThresholdCount"`
}

// TimeoutPolicy defines the attributes associated with timeout.
Expand All @@ -260,7 +263,8 @@ type RetryPolicy struct {
// NumRetries is maximum allowed number of retries.
// If not supplied, the number of retries is one.
// +optional
NumRetries uint32 `json:"count"`
// +kubebuilder:validation:Minimum=0
NumRetries int64 `json:"count"`
// PerTryTimeout specifies the timeout per retry attempt.
// Ignored if NumRetries is not supplied.
PerTryTimeout string `json:"perTryTimeout,omitempty"`
Expand Down
36 changes: 24 additions & 12 deletions examples/contour/01-crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ spec:
count:
description: NumRetries is maximum allowed number of retries.
If not supplied, the number of retries is one.
format: int32
format: int64
minimum: 0
type: integer
perTryTimeout:
description: PerTryTimeout specifies the timeout per retry
Expand All @@ -113,7 +114,8 @@ spec:
healthyThresholdCount:
description: The number of healthy health checks required
before a host is marked healthy
format: int32
format: int64
minimum: 0
type: integer
host:
description: The value of the host header in the HTTP
Expand All @@ -136,7 +138,8 @@ spec:
unhealthyThresholdCount:
description: The number of unhealthy health checks required
before a host is marked unhealthy
format: int32
format: int64
minimum: 0
type: integer
required:
- path
Expand Down Expand Up @@ -172,7 +175,8 @@ spec:
weight:
description: Weight defines percentage of traffic to balance
traffic
format: int32
format: int64
minimum: 0
type: integer
required:
- name
Expand Down Expand Up @@ -221,7 +225,8 @@ spec:
healthyThresholdCount:
description: The number of healthy health checks required
before a host is marked healthy
format: int32
format: int64
minimum: 0
type: integer
host:
description: The value of the host header in the HTTP
Expand All @@ -244,7 +249,8 @@ spec:
unhealthyThresholdCount:
description: The number of unhealthy health checks required
before a host is marked unhealthy
format: int32
format: int64
minimum: 0
type: integer
required:
- path
Expand Down Expand Up @@ -280,7 +286,8 @@ spec:
weight:
description: Weight defines percentage of traffic to balance
traffic
format: int32
format: int64
minimum: 0
type: integer
required:
- name
Expand Down Expand Up @@ -586,7 +593,8 @@ spec:
healthyThresholdCount:
description: The number of healthy health checks required
before a host is marked healthy
format: int32
format: int64
minimum: 0
type: integer
host:
description: The value of the host header in the HTTP health
Expand All @@ -609,7 +617,8 @@ spec:
unhealthyThresholdCount:
description: The number of unhealthy health checks required
before a host is marked unhealthy
format: int32
format: int64
minimum: 0
type: integer
required:
- path
Expand Down Expand Up @@ -726,7 +735,8 @@ spec:
count:
description: NumRetries is maximum allowed number of retries.
If not supplied, the number of retries is one.
format: int32
format: int64
minimum: 0
type: integer
perTryTimeout:
description: PerTryTimeout specifies the timeout per retry
Expand Down Expand Up @@ -841,7 +851,8 @@ spec:
weight:
description: Weight defines percentage of traffic to balance
traffic
format: int32
format: int64
minimum: 0
type: integer
required:
- name
Expand Down Expand Up @@ -995,7 +1006,8 @@ spec:
weight:
description: Weight defines percentage of traffic to balance
traffic
format: int32
format: int64
minimum: 0
type: integer
required:
- name
Expand Down
36 changes: 24 additions & 12 deletions examples/render/contour.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ spec:
count:
description: NumRetries is maximum allowed number of retries.
If not supplied, the number of retries is one.
format: int32
format: int64
minimum: 0
type: integer
perTryTimeout:
description: PerTryTimeout specifies the timeout per retry
Expand All @@ -187,7 +188,8 @@ spec:
healthyThresholdCount:
description: The number of healthy health checks required
before a host is marked healthy
format: int32
format: int64
minimum: 0
type: integer
host:
description: The value of the host header in the HTTP
Expand All @@ -210,7 +212,8 @@ spec:
unhealthyThresholdCount:
description: The number of unhealthy health checks required
before a host is marked unhealthy
format: int32
format: int64
minimum: 0
type: integer
required:
- path
Expand Down Expand Up @@ -246,7 +249,8 @@ spec:
weight:
description: Weight defines percentage of traffic to balance
traffic
format: int32
format: int64
minimum: 0
type: integer
required:
- name
Expand Down Expand Up @@ -295,7 +299,8 @@ spec:
healthyThresholdCount:
description: The number of healthy health checks required
before a host is marked healthy
format: int32
format: int64
minimum: 0
type: integer
host:
description: The value of the host header in the HTTP
Expand All @@ -318,7 +323,8 @@ spec:
unhealthyThresholdCount:
description: The number of unhealthy health checks required
before a host is marked unhealthy
format: int32
format: int64
minimum: 0
type: integer
required:
- path
Expand Down Expand Up @@ -354,7 +360,8 @@ spec:
weight:
description: Weight defines percentage of traffic to balance
traffic
format: int32
format: int64
minimum: 0
type: integer
required:
- name
Expand Down Expand Up @@ -660,7 +667,8 @@ spec:
healthyThresholdCount:
description: The number of healthy health checks required
before a host is marked healthy
format: int32
format: int64
minimum: 0
type: integer
host:
description: The value of the host header in the HTTP health
Expand All @@ -683,7 +691,8 @@ spec:
unhealthyThresholdCount:
description: The number of unhealthy health checks required
before a host is marked unhealthy
format: int32
format: int64
minimum: 0
type: integer
required:
- path
Expand Down Expand Up @@ -800,7 +809,8 @@ spec:
count:
description: NumRetries is maximum allowed number of retries.
If not supplied, the number of retries is one.
format: int32
format: int64
minimum: 0
type: integer
perTryTimeout:
description: PerTryTimeout specifies the timeout per retry
Expand Down Expand Up @@ -915,7 +925,8 @@ spec:
weight:
description: Weight defines percentage of traffic to balance
traffic
format: int32
format: int64
minimum: 0
type: integer
required:
- name
Expand Down Expand Up @@ -1069,7 +1080,8 @@ spec:
weight:
description: Weight defines percentage of traffic to balance
traffic
format: int32
format: int64
minimum: 0
type: integer
required:
- name
Expand Down
4 changes: 2 additions & 2 deletions internal/dag/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ func (b *Builder) computeRoutes(sw *ObjectStatusWriter, proxy *projcontour.HTTPP
c := &Cluster{
Upstream: s,
LoadBalancerPolicy: loadBalancerPolicy(route.LoadBalancerPolicy),
Weight: service.Weight,
Weight: uint32(service.Weight),
HealthCheckPolicy: healthCheckPolicy(route.HealthCheckPolicy),
UpstreamValidation: uv,
RequestHeadersPolicy: reqHP,
Expand Down Expand Up @@ -1004,7 +1004,7 @@ func (b *Builder) processIngressRoutes(sw *ObjectStatusWriter, ir *ingressroutev
r.Clusters = append(r.Clusters, &Cluster{
Upstream: s,
LoadBalancerPolicy: service.Strategy,
Weight: service.Weight,
Weight: uint32(service.Weight),
HealthCheckPolicy: ingressrouteHealthCheckPolicy(service.HealthCheck),
UpstreamValidation: uv,
Protocol: s.Protocol,
Expand Down
10 changes: 5 additions & 5 deletions internal/dag/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func retryPolicy(rp *projcontour.RetryPolicy) *RetryPolicy {
perTryTimeout, _ := time.ParseDuration(rp.PerTryTimeout)
return &RetryPolicy{
RetryOn: "5xx",
NumRetries: max(1, rp.NumRetries),
NumRetries: max(1, uint32(rp.NumRetries)),
PerTryTimeout: perTryTimeout,
}
}
Expand Down Expand Up @@ -156,8 +156,8 @@ func ingressrouteHealthCheckPolicy(hc *ingressroutev1.HealthCheck) *HealthCheckP
Host: hc.Host,
Interval: time.Duration(hc.IntervalSeconds) * time.Second,
Timeout: time.Duration(hc.TimeoutSeconds) * time.Second,
UnhealthyThreshold: hc.UnhealthyThresholdCount,
HealthyThreshold: hc.HealthyThresholdCount,
UnhealthyThreshold: uint32(hc.UnhealthyThresholdCount),
HealthyThreshold: uint32(hc.HealthyThresholdCount),
}
}

Expand All @@ -170,8 +170,8 @@ func healthCheckPolicy(hc *projcontour.HTTPHealthCheckPolicy) *HealthCheckPolicy
Host: hc.Host,
Interval: time.Duration(hc.IntervalSeconds) * time.Second,
Timeout: time.Duration(hc.TimeoutSeconds) * time.Second,
UnhealthyThreshold: hc.UnhealthyThresholdCount,
HealthyThreshold: hc.HealthyThresholdCount,
UnhealthyThreshold: uint32(hc.UnhealthyThresholdCount),
HealthyThreshold: uint32(hc.HealthyThresholdCount),
}
}

Expand Down
8 changes: 4 additions & 4 deletions site/docs/master/api-reference.html
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ <h3 id="projectcontour.io/v1.HTTPHealthCheckPolicy">HTTPHealthCheckPolicy
<td style="white-space:nowrap">
<code>unhealthyThresholdCount</code></br>
<em>
uint32
int64
</em>
</td>
<td>
Expand All @@ -395,7 +395,7 @@ <h3 id="projectcontour.io/v1.HTTPHealthCheckPolicy">HTTPHealthCheckPolicy
<td style="white-space:nowrap">
<code>healthyThresholdCount</code></br>
<em>
uint32
int64
</em>
</td>
<td>
Expand Down Expand Up @@ -860,7 +860,7 @@ <h3 id="projectcontour.io/v1.RetryPolicy">RetryPolicy
<td style="white-space:nowrap">
<code>count</code></br>
<em>
uint32
int64
</em>
</td>
<td>
Expand Down Expand Up @@ -1111,7 +1111,7 @@ <h3 id="projectcontour.io/v1.Service">Service
<td style="white-space:nowrap">
<code>weight</code></br>
<em>
uint32
int64
</em>
</td>
<td>
Expand Down

0 comments on commit 133d8db

Please sign in to comment.