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

Update error msgs for OSImageURL validation: #7769

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jacobweinstock
Copy link
Member

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.

@eks-distro-bot eks-distro-bot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Mar 2, 2024
@jacobweinstock jacobweinstock force-pushed the update-OSImageURL-validation branch 2 times, most recently from 566e170 to cbd1c75 Compare March 2, 2024 01:25
@eks-distro-bot eks-distro-bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Mar 2, 2024
@jacobweinstock jacobweinstock force-pushed the update-OSImageURL-validation branch 4 times, most recently from 482e07d to 4abcacf Compare March 2, 2024 02:31
@eks-distro-bot eks-distro-bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Mar 2, 2024
@jacobweinstock jacobweinstock force-pushed the update-OSImageURL-validation branch 4 times, most recently from c1f8ed0 to 6aaa4d9 Compare March 4, 2024 15:49
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>
Copy link

codecov bot commented Mar 4, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 73.64%. Comparing base (4583834) to head (f6a54f5).
Report is 257 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

@jacobweinstock
Copy link
Member Author

/approve

@eks-distro-bot
Copy link
Collaborator

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

}

// deduplicate returns a new slice with duplicates values removed.
func deduplicate(s []string) []string {
Copy link
Member

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?

Copy link
Member Author

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 {
Copy link
Member

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

Suggested change
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, " ")
}

Copy link
Member Author

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)
Copy link
Member

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!

Copy link
Member Author

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"},
Copy link
Member

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?

Copy link
Member Author

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",
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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",

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants