mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 20:24:09 +00:00
Merge pull request #58498 from feiskyer/win-ver
Automatic merge from submit-queue (batch tested with PRs 56995, 58498, 57426, 58902, 58863). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Get windows kernel version directly from registry **What this PR does / why we need it**: kubernetes/kubernetes#55143 gets windows kernel version by calling windows.GetVersion(), but it doesn't work on windows 10. From https://msdn.microsoft.com/en-us/library/windows/desktop/ms724439(v=vs.85).aspx, GetVersion requires app to be manifested. Applications not manifested for Windows 8.1 or Windows 10 will return the Windows 8 OS version value (6.2). I tried a toy go program using GetVersion on Windows 10 and it returns 0x23f00206. Given the limited win32 functions in golang, we should read from registry directly. **Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*: Fixes #58497 **Special notes for your reviewer**: Should also cherry-pick to v1.9. **Release note**: ```release-note Get windows kernel version directly from registry ``` /cc @JiangtianLi @taylorb-microsoft
This commit is contained in:
commit
30c14dd83a
@ -69,20 +69,39 @@ func getVersionRevision() (uint16, error) {
|
||||
|
||||
// getKernelVersion gets the version of windows kernel.
|
||||
func getKernelVersion() (string, error) {
|
||||
ver, err := windows.GetVersion()
|
||||
// Get CurrentBuildNumber.
|
||||
buildNumber, err := getCurrentVersionVal("CurrentBuildNumber")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
// Get CurrentMajorVersionNumber.
|
||||
majorVersionNumberString, err := getCurrentVersionVal("CurrentMajorVersionNumber")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
majorVersionNumber, err := windows.UTF16FromString(majorVersionNumberString)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
// Get CurrentMinorVersionNumber.
|
||||
minorVersionNumberString, err := getCurrentVersionVal("CurrentMinorVersionNumber")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
minorVersionNumber, err := windows.UTF16FromString(minorVersionNumberString)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
// Get UBR.
|
||||
revision, err := getVersionRevision()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
major := ver & 0xFF
|
||||
minor := (ver >> 8) & 0xFF
|
||||
build := (ver >> 16) & 0xFFFF
|
||||
return fmt.Sprintf("%d.%d.%05d.%d\n", major, minor, build, revision), nil
|
||||
return fmt.Sprintf("%d.%d.%s.%d\n", majorVersionNumber[0], minorVersionNumber[0], buildNumber, revision), nil
|
||||
}
|
||||
|
||||
// getOSImageVersion gets the osImage name and version.
|
||||
|
Loading…
Reference in New Issue
Block a user