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

Add version constraints #4

Merged
merged 1 commit into from
Sep 5, 2023
Merged

Add version constraints #4

merged 1 commit into from
Sep 5, 2023

Conversation

kke
Copy link
Collaborator

@kke kke commented Sep 1, 2023

As discussed in k0sproject/k0sctl#547

Implementing a k0s feature gate / registry will require a way to validate versions against constraints.

This PR adds a convenient version constraint system.

c := version.MustConstraint(">= v1.24, < 1.26.0")
println(c.CheckString("v1.24.0+k0s.1"))
// true

Which is a lot more convenient than something like:

targetVmin, err := version.NewVersion("v1.24.0")
if err != nil {
  return err
}
targetVmax, err := version.NewVersion("v1.26.0")
if err != nil {
  return err
}

k0sVersion, err := version.NewVersion(p.Config.Spec.K0s.Version)
if err != nil {
  return err
}

if k0sVersion.GreaterThanOrEqual(targetVmin) && k0sVersion.LessThan(targetVmax) {
  // do stuff
} else if .......

The ruby style "pessimistic" ~> 1.0 (roughly the same as >= 1.0.0, < 2.0.0) operator was not implemented.

The k0s versioning scheme doc does not address pre-release versions, but something like v1.24.0-alpha.1+k0s.0 should act as expected. Not entirely sure about v1.24.0+k0s.1-rc.1 or v1.24.0-alpha.1+k0s.1-rc.1 in case that is possible.

Signed-off-by: Kimmo Lehto <[email protected]>
@kke kke merged commit beeed05 into main Sep 5, 2023
2 checks passed
@kke kke deleted the add-constraints branch September 5, 2023 07:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant