-
Notifications
You must be signed in to change notification settings - Fork 137
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
fix: Adjust duration validation to include format for 1h10m
#1125
Conversation
pkg/apis/v1beta1/nodepool.go
Outdated
@@ -124,7 +124,7 @@ type Budget struct { | |||
// This is required if Schedule is set. | |||
// This regex has an optional 0s at the end since the duration.String() always adds | |||
// a 0s at the end. | |||
// +kubebuilder:validation:Pattern=`^([0-9]+(m|h)+(0s)?)$` | |||
// +kubebuilder:validation:Pattern=`^(([0-9]+(h|m)(0s)?)|([0-9]+h+[0-9]+m+(0s)?))$` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there only needs to be one 0s at the end of the whole string, right before the $. It also seems like this means I could do 1h2h3m4m, which I don't think is what we want to do.
// +kubebuilder:validation:Pattern=`^(([0-9]+(h|m)(0s)?)|([0-9]+h+[0-9]+m+(0s)?))$` | |
// +kubebuilder:validation:Pattern=`^(([0-9]+(h|m)(0s)?)|([0-9]+h+[0-9]+m+(0s)?))$` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should not allow for that kind of format. We are only allowing 1h/1m or 1h1m
bf28f09
to
f247f26
Compare
@@ -80,7 +80,7 @@ spec: | |||
This is required if Schedule is set. | |||
This regex has an optional 0s at the end since the duration.String() always adds | |||
a 0s at the end. | |||
pattern: ^([0-9]+(m|h)+(0s)?)$ | |||
pattern: ^((([0-9]+(h|m))|([0-9]+h[0-9]+m))(0s)?)$ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a simpler way to write this pattern? I could imagine that you could do something like ([1-9](h|m|s)+)|(0s)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The format you suggested would allow 1h2m1h yo happen
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We also don't want to allow seconds, since this breaches the smallest denominator value of the schedule, which is minutes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could understand disallowing a leading 0 on the front of the duration, but I don't think it's a big deal, since they should really be treated the exact same. Disallowing it means that users can't do something like 0h5m or 0h or 0m or 5h0m. These are all weird in that there's better ways to define it, but it's up to us on how we want to allow/disallow this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, makes sense. I just looked over it quick. Current regex makes sense 👍🏼
Pull Request Test Coverage Report for Build 8382299321Details
💛 - Coveralls |
@@ -80,7 +80,7 @@ spec: | |||
This is required if Schedule is set. | |||
This regex has an optional 0s at the end since the duration.String() always adds | |||
a 0s at the end. | |||
pattern: ^([0-9]+(m|h)+(0s)?)$ | |||
pattern: ^((([0-9]+(h|m))|([0-9]+h[0-9]+m))(0s)?)$ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We also don't want to allow seconds, since this breaches the smallest denominator value of the schedule, which is minutes
@@ -80,7 +80,7 @@ spec: | |||
This is required if Schedule is set. | |||
This regex has an optional 0s at the end since the duration.String() always adds | |||
a 0s at the end. | |||
pattern: ^([0-9]+(m|h)+(0s)?)$ | |||
pattern: ^((([0-9]+(h|m))|([0-9]+h[0-9]+m))(0s)?)$ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could understand disallowing a leading 0 on the front of the duration, but I don't think it's a big deal, since they should really be treated the exact same. Disallowing it means that users can't do something like 0h5m or 0h or 0m or 5h0m. These are all weird in that there's better ways to define it, but it's up to us on how we want to allow/disallow this.
@@ -124,7 +124,7 @@ type Budget struct { | |||
// This is required if Schedule is set. | |||
// This regex has an optional 0s at the end since the duration.String() always adds | |||
// a 0s at the end. | |||
// +kubebuilder:validation:Pattern=`^([0-9]+(m|h)+(0s)?)$` | |||
// +kubebuilder:validation:Pattern=`^((([0-9]+(h|m))|([0-9]+h[0-9]+m))(0s)?)$` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Devils advocate: can't we just lower the unit we are using? 1h10m is just 70m. Maybe it gets more complex with 12d10m vs 730m.
I commonly see
consolidateAfter: 300s
consolidationPolicy: WhenEmpty
expireAfter: 720h
If we do move to a 1h10m pattern, we should probably do it everywhere to be consistent. here for example we follow a different pattern. It will be fairly confusing for users to see they can set 1h10m in one place but not everywhere
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR would allow both to happen. We currently promise both format to customer and this is addressing a bug
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems in your link @Bryce-Soghigian that the only difference in these two regexes is the order. Seems compound durations are enabled there as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
/approve
@@ -124,7 +124,7 @@ type Budget struct { | |||
// This is required if Schedule is set. | |||
// This regex has an optional 0s at the end since the duration.String() always adds | |||
// a 0s at the end. | |||
// +kubebuilder:validation:Pattern=`^([0-9]+(m|h)+(0s)?)$` | |||
// +kubebuilder:validation:Pattern=`^((([0-9]+(h|m))|([0-9]+h[0-9]+m))(0s)?)$` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems in your link @Bryce-Soghigian that the only difference in these two regexes is the order. Seems compound durations are enabled there as well.
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: engedaam, njtran The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Fixes aws/karpenter-provider-aws#5913
Description
1h10m
How was this change tested?
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.