Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

apis: replace unsigned integers in CRD fields with signed integers, add validation #2133

Merged
merged 1 commit into from
Feb 2, 2020

Conversation

awprice
Copy link
Contributor

@awprice awprice commented Jan 21, 2020

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

Copy link
Contributor

@davecheney davecheney left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this, same comment everywhere, if we can just say int not int64 throughout I'd be fine.

Also, is it just uint32 that (can't remember the thing that complained) will uint work?

@@ -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"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not just int?

@@ -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"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

@awprice
Copy link
Contributor Author

awprice commented Jan 21, 2020

Upon reading https://book.kubebuilder.io/cronjob-tutorial/api-design.html?highlight=integer#designing-an-api it also recommends not using int too and only use int32/int64. I felt like changing these everywhere would be out of scope for this change.

Should I raise a second ticket for this?

@awprice
Copy link
Contributor Author

awprice commented Jan 21, 2020

Thanks for working on this, same comment everywhere, if we can just say int not int64 throughout I'd be fine.

Also, is it just uint32 that (can't remember the thing that complained) will uint work?

Thanks for the quick reply! See comment #2133 (comment) about usage of int/uint.

@ash2k
Copy link

ash2k commented Jan 30, 2020

Hi all :)

From https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#primitive-types :

  • Do not use unsigned integers, due to inconsistent support across languages and libraries. Just validate that the integer is non-negative if that's the case.

  • All public integer fields MUST use the Go (u)int32 or Go (u)int64 types, not (u)int (which is ambiguous depending on target platform). Internal types may use (u)int.

@ash2k
Copy link

ash2k commented Jan 31, 2020

Copy link
Member

@youngnick youngnick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that Kubernetes doesn't do straight int, this LGTM. Thanks for adding the validation.

@youngnick
Copy link
Member

@awprice if you can fix up the merge conflicts, I'll merge this one.

…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 projectcontour#2123

Signed-off-by: Alex Price <aprice@atlassian.com>
@codecov
Copy link

codecov bot commented Feb 2, 2020

Codecov Report

Merging #2133 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #2133   +/-   ##
=======================================
  Coverage   78.08%   78.08%           
=======================================
  Files          56       56           
  Lines        4946     4946           
=======================================
  Hits         3862     3862           
  Misses       1005     1005           
  Partials       79       79
Impacted Files Coverage Δ
internal/dag/policy.go 96.24% <100%> (ø) ⬆️
internal/dag/builder.go 92.75% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 67d4105...ebfe6bb. Read the comment docs.

@awprice
Copy link
Contributor Author

awprice commented Feb 2, 2020

@youngnick Thanks for the reminder. Conflicts fixed.

@youngnick youngnick merged commit 4f37ec2 into projectcontour:master Feb 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DeepCopy unstructured HTTPProxy causes panic
4 participants