-
Notifications
You must be signed in to change notification settings - Fork 1.5k
MCO-2181: Default version switchover #10533
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,13 +4,51 @@ package version | |
| import ( | ||
| "fmt" | ||
| "os" | ||
| "strconv" | ||
| "strings" | ||
|
|
||
| "github.com/sirupsen/logrus" | ||
|
|
||
| "github.com/openshift/installer/pkg/types" | ||
| ) | ||
|
|
||
| // VersionInfo represents a parsed semantic version. | ||
| type VersionInfo struct { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (non-blocking): This repo has the following semver libraries already vendored which could be a more robust implementation:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I known, and I've seen them. Unfortunately, some of them are strict with semver format and requires the version to start with |
||
| Major int | ||
| Minor int | ||
| Patch int | ||
| } | ||
|
|
||
| // GetVersionInfo returns the build version parsed as a VersionInfo. | ||
| func GetVersionInfo() (VersionInfo, error) { | ||
| s, err := Version() | ||
| if err != nil { | ||
| return VersionInfo{}, err | ||
| } | ||
| return parseVersionInfo(s) | ||
| } | ||
|
|
||
| func parseVersionInfo(s string) (VersionInfo, error) { | ||
| if idx := strings.Index(s, "-"); idx != -1 { | ||
| s = s[:idx] | ||
| } | ||
| parts := strings.Split(s, ".") | ||
| if len(parts) == 0 { | ||
| return VersionInfo{}, fmt.Errorf("invalid version %q", s) | ||
| } | ||
| var v VersionInfo | ||
| major, err := strconv.Atoi(parts[0]) | ||
| if err != nil { | ||
| return VersionInfo{}, fmt.Errorf("invalid version %q", s) | ||
| } | ||
| v.Major = major | ||
| if len(parts) > 1 { | ||
| v.Minor, _ = strconv.Atoi(parts[1]) | ||
| } | ||
| if len(parts) > 2 { | ||
| v.Patch, _ = strconv.Atoi(parts[2]) | ||
| } | ||
| return v, nil | ||
| } | ||
|
|
||
| // This file handles correctly identifying the default release version, which is expected to be | ||
| // replaced in the binary post-compile by the release name extracted from a payload. The expected modification is: | ||
| // | ||
|
|
@@ -65,7 +103,7 @@ func String() (string, error) { | |
| // Version returns the installer/release version. | ||
| func Version() (string, error) { | ||
| if strings.HasPrefix(defaultVersionPadded, defaultVersionPrefix) { | ||
| return Raw, nil | ||
| return removeGoVersionPrefix(Raw), nil | ||
| } | ||
| nullTerminator := strings.IndexByte(defaultVersionPadded, '\x00') | ||
| if nullTerminator == -1 { | ||
|
|
@@ -125,7 +163,20 @@ func cleanArch(releaseArchitecture string) string { | |
| return strings.ReplaceAll(releaseArchitecture, "linux/", "") | ||
| } | ||
|
|
||
| // DefaultArch returns the default release architecture | ||
| func DefaultArch() types.Architecture { | ||
| return types.Architecture(defaultArch) | ||
| // removeGoVersionPrefix converts a Go module version tag (e.g. "v1.4.22") | ||
| // into the corresponding OCP version (e.g. "4.22"). | ||
| func removeGoVersionPrefix(version string) string { | ||
| if strings.HasPrefix(version, "v") { | ||
| version = strings.TrimPrefix(version, "v") | ||
| parts := strings.SplitN(version, ".", 2) | ||
| if len(parts) > 1 { | ||
| version = parts[1] | ||
| } | ||
| } | ||
| return version | ||
| } | ||
|
|
||
| // DefaultArch returns the default release architecture embedded in the binary | ||
| func DefaultArch() string { | ||
| return defaultArch | ||
| } | ||
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 this just waiting for MCO-2200 to land?
Note that this affects not only ABI, but also the baremetal IPI bootstrap VM.
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.
Yes, and it's something I knew and identified.
We have been already booting with RHEL 9 and pivoting to RHEL 10 during the MCD firstboot so I don't think having this for a short period of time (if the ABI change doesn't land before) is problematic.