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

Change upgrade path validation for 8.0 to only allow 7.17 #5261

Merged
merged 7 commits into from
Jan 20, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions pkg/controller/elasticsearch/validation/validations.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,11 +272,11 @@ func noDowngrades(current, proposed esv1.Elasticsearch) field.ErrorList {

func validUpgradePath(current, proposed esv1.Elasticsearch) field.ErrorList {
var errs field.ErrorList
currentVer, err := version.Parse(current.Spec.Version)
if err != nil {
// this should not happen, since this is the already persisted version
errs = append(errs, field.Invalid(field.NewPath("spec").Child("version"), current.Spec.Version, parseStoredVersionErrMsg))
currentVer, ferr := currentVersion(current)
if ferr != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

ferr?

Copy link
Collaborator Author

@pebrc pebrc Jan 19, 2022

Choose a reason for hiding this comment

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

ferr for field.Error which is what the webhook API works with, err is used as a variable for a regular builtin error below

errs = append(errs, ferr)
}

proposedVer, err := version.Parse(proposed.Spec.Version)
if err != nil {
errs = append(errs, field.Invalid(field.NewPath("spec").Child("version"), proposed.Spec.Version, parseVersionErrMsg))
Expand All @@ -298,6 +298,26 @@ func validUpgradePath(current, proposed esv1.Elasticsearch) field.ErrorList {
return errs
}

func currentVersion(current esv1.Elasticsearch) (version.Version, *field.Error) {
// we do not have a version in the status let's use the version in the current spec instead which will not reflect
// actually running Pods but which is still better than no validation.
if current.Status.Version == "" {
currentVer, err := version.Parse(current.Spec.Version)
if err != nil {
// this should not happen, since this is the version from the spec copied to the status by the operator
pebrc marked this conversation as resolved.
Show resolved Hide resolved
return version.Version{}, field.Invalid(field.NewPath("spec").Child("version"), current.Spec.Version, parseStoredVersionErrMsg)
}
return currentVer, nil
}
// if available use the status version which reflects the lowest version currently running in the cluster
currentVer, err := version.Parse(current.Status.Version)
if err != nil {
// this should not happen, since this is the already persisted version
return version.Version{}, field.Invalid(field.NewPath("status").Child("version"), current.Status.Version, parseStoredVersionErrMsg)
}
return currentVer, nil
}

func validMonitoring(es esv1.Elasticsearch) field.ErrorList {
return stackmon.Validate(&es, es.Spec.Version)
}
4 changes: 2 additions & 2 deletions pkg/controller/elasticsearch/version/supported_versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ func technicallySupportedVersions(v version.Version) *version.MinMaxVersion {
}
case 8:
return &version.MinMaxVersion{
// 7.4.0 is the lowest version that offers a direct upgrade path to 8.0
Min: version.MustParse("7.4.0"),
// 7.17.0 is the lowest version that offers a direct upgrade path to 8.0
Min: version.MinFor(7, 17, 0), // allow snapshot builds here for testing
Max: version.MustParse("8.99.99"),
}
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func TestSupportedVersions(t *testing.T) {
v: version.MustParse("8.0.0"),
},
supported: []version.Version{
version.MustParse("7.4.0"),
version.MustParse("7.17.0"),
pebrc marked this conversation as resolved.
Show resolved Hide resolved
version.MustParse("8.9.0"),
},
unsupported: []version.Version{
Expand Down