Revert get version change due to the overlap in PR #55143

pull/6/head
Jiangtian Li 2017-11-15 10:27:19 -08:00
parent b91e030fcf
commit 5fe87574d2
3 changed files with 19 additions and 8 deletions

View File

@ -57,18 +57,13 @@ func (p *perfCounterNodeStatsClient) startMonitoring() error {
return err
}
iv, err := exec.Command("powershell", "-command", "(Get-CimInstance Win32_OperatingSystem).Caption").Output()
version, err := exec.Command("cmd", "/C", "ver").Output()
if err != nil {
return err
}
osImageVersion := strings.TrimSpace(string(iv))
kv, err := exec.Command("powershell", "-command", "[System.Environment]::OSVersion.Version.ToString()").Output()
if err != nil {
return err
}
kernelVersion := strings.TrimSpace(string(kv))
osImageVersion := strings.TrimSpace(string(version))
kernelVersion := extractVersionNumber(osImageVersion)
p.nodeInfo = nodeInfo{
kernelVersion: kernelVersion,
osImageVersion: osImageVersion,

View File

@ -18,6 +18,7 @@ limitations under the License.
package winstats
import (
"regexp"
"time"
cadvisorapi "github.com/google/cadvisor/info/v1"
@ -134,3 +135,11 @@ func (c *statsClient) createRootContainerInfo() (*cadvisorapiv2.ContainerInfo, e
return &rootInfo, nil
}
// extractVersionNumber gets the version number from the full version string on Windows
// e.g. extracts "10.0.14393" from "Microsoft Windows [Version 10.0.14393]"
func extractVersionNumber(fullVersion string) string {
re := regexp.MustCompile("[^0-9.]")
version := re.ReplaceAllString(fullVersion, "")
return version
}

View File

@ -116,6 +116,13 @@ func TestWinVersionInfo(t *testing.T) {
KernelVersion: "v42"})
}
func TestExtractVersionNumber(t *testing.T) {
fullVersion := "Microsoft Windows [Version 10.0.14393]"
versionNumber := extractVersionNumber(fullVersion)
expected := "10.0.14393"
assert.Equal(t, expected, versionNumber)
}
func getClient(t *testing.T) Client {
f := fakeWinNodeStatsClient{}
c, err := newClient(f)