Skip to content

Commit

Permalink
Revert get version change due to the overlap in PR kubernetes#55143
Browse files Browse the repository at this point in the history
  • Loading branch information
JiangtianLi committed Nov 15, 2017
1 parent b91e030 commit 5fe8757
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
11 changes: 3 additions & 8 deletions pkg/kubelet/winstats/perfcounter_nodestats.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 9 additions & 0 deletions pkg/kubelet/winstats/winstats.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ limitations under the License.
package winstats

import (
"regexp"
"time"

cadvisorapi "github.com/google/cadvisor/info/v1"
Expand Down Expand Up @@ -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
}
7 changes: 7 additions & 0 deletions pkg/kubelet/winstats/winstats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 5fe8757

Please sign in to comment.