-
Notifications
You must be signed in to change notification settings - Fork 289
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
Update error msgs for OSImageURL validation: #7769
base: main
Are you sure you want to change the base?
Update error msgs for OSImageURL validation: #7769
Conversation
566e170
to
cbd1c75
Compare
482e07d
to
4abcacf
Compare
c1f8ed0
to
6aaa4d9
Compare
As the error message is provided to Users, including the expected Kubernetes version format to the error message allows to User to clearly understand how to resolve the validation error. Signed-off-by: Jacob Weinstock <jakobweinstock@gmail.com>
6aaa4d9
to
f6a54f5
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #7769 +/- ##
==========================================
+ Coverage 73.48% 73.64% +0.15%
==========================================
Files 579 588 +9
Lines 36357 37207 +850
==========================================
+ Hits 26718 27400 +682
- Misses 7875 8015 +140
- Partials 1764 1792 +28 ☔ View full report in Codecov by Sentry. |
/approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: jacobweinstock 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 |
} | ||
|
||
// deduplicate returns a new slice with duplicates values removed. | ||
func deduplicate(s []string) []string { |
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.
wondering if this is needed, since we have the control over the input and this is not coming from user?
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 control we have over the input is "business" level logic, this function is the "application" level logic. Coupling those together creates for us future issues when business logic changes. I don't recommend we couple them.
} | ||
|
||
seps := remove(".", deduplicate(separators)) | ||
for idx, sep := range seps { |
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.
can we simplify this logic to just parsing in the version and concatenating the seps to list out all accepted versions in a single for loop
for idx, sep := range seps { | |
version := strings.Split(v, ".") | |
result := []string{v} | |
major := version[0] | |
minor := version[1] | |
for idx, sep := range seps { | |
elem := fmt.Sprintf("%s%s%s",major,sep,minor) | |
if idx == len(seps)-1 { | |
result = append(result, "or") | |
} else if idx != len(seps)-2 { | |
elem = elem + "," | |
} | |
result = append(result, elem) | |
} | |
return strings.Join(result, " ") | |
} |
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 changes the function to only support a single .
as a separator. In my opinion, this more generic implementation is basic, flexible, and simple enough to be future proof. I'm not convinced of the value of the trade off of a few less lines of code.
result := []string{} | ||
seen := make(map[string]struct{}) | ||
for _, val := range s { | ||
val := strings.ToLower(val) |
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.
since these are all symbols we might not need this too!
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 function doesnt limit the type of strings in the slice. the values could be characters. coupling the inputs to our business logic creates a rigid implementation.
{"1.27", []string{"."}, "1.27"}, | ||
{"1.28", []string{".", "."}, "1.28"}, | ||
{"1.29", []string{"-", "-", ""}, "1.29, 1-29 or 129"}, | ||
{"1.29.1", []string{"-", "_", "_", ""}, "1.29.1, 1-29-1, 1_29_1 or 1291"}, |
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 don't support patch version on our spec, so we don't have to be covering this. hence a simpler approach might work?
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.
what versions we support is business level logic. Coupling this with application logic will cause us future maintainability issues in the future. I don't recommend we couple them.
@@ -150,8 +150,8 @@ func validateK8sVersionInOSImageURLs(spec *ClusterSpec) error { | |||
} | |||
|
|||
if !containsK8sVersion(spec.ControlPlaneMachineConfig().Spec.OSImageURL, string(spec.Cluster.Spec.KubernetesVersion)) { | |||
return fmt.Errorf("missing kube version from control plane machine config OSImageURL: url=%v, version=%v", | |||
spec.ControlPlaneMachineConfig().Spec.OSImageURL, spec.Cluster.Spec.KubernetesVersion) | |||
return fmt.Errorf("missing kube version from control plane machine config OSImageURL, the image url must include %v: url=%v, version=%v", |
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.
return fmt.Errorf("missing kube version from control plane machine config OSImageURL, the image url must include %v: url=%v, version=%v", | |
return fmt.Errorf("missing kube version from control plane machine config OSImageURL, the image url must include %s: url=%v, version=%v", |
Issue #, if available:
Description of changes:
As the error message is provided to Users, including the expected Kubernetes version format to the error message allows to User to clearly understand how to resolve the validation error.
Testing (if applicable):
Documentation added/planned (if applicable):
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.