Skip to content

Commit

Permalink
Enable runtime info tests for Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
feiskyer committed Nov 1, 2018
1 parent e3ebc8a commit 37c3115
Show file tree
Hide file tree
Showing 5 changed files with 399 additions and 28 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ jobs:
- stage: Test
os: windows
script:
- make
- make windows
- powershell -c "Set-ExecutionPolicy Bypass -Scope CURRENTUSER -Force"
- powershell hack/install-kubelet.ps1
# Skip hack/run-critest.sh temporarily.
- powershell hack/run-critest.ps1

stages:
- Static check
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ clean:
find . -name \*~ -delete
find . -name \#\* -delete

cross: check-gopath
windows: check-gopath
GOOS=windows $(GO) test -c -o $(CURDIR)/_output/critest.exe \
-ldflags '$(GO_LDFLAGS)' \
$(PROJECT)/cmd/critest
Expand Down
164 changes: 139 additions & 25 deletions hack/install-kubelet.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,146 @@
# See the License for the specific language governing permissions and
# limitations under the License.


Param(
$clusterCIDR="192.168.0.0/16",
$podCIDR="192.168.1.0/24"
)

# Stop on any error.
$ErrorActionPreference = "Stop"
$VerbosePreference = "Continue"

# Install kubelet
$gopath = [System.Environment]::GetEnvironmentVariable("GOPATH")
$k8siopath = $gopath + "/src/k8s.io"
$kubernetespath = $k8siopath + "/kubernetes"
mkdir -p $k8siopath
cd $k8siopath
git clone -c core.symlinks=true https://github.com/kubernetes/kubernetes

cd $kubernetespath
$branch = [System.Environment]::GetEnvironmentVariable("TRAVIS_BRANCH")
if ( ! "$branch".Equals("master") ) {
# We can do this because cri-tools have the same branch name with kubernetes.
git checkout "$branch"
}

# Build kubelet
$version = git describe --tags --dirty --always
go build -ldflags "-X k8s.io/kubernetes/vendor/k8s.io/client-go/pkg/version.gitVersion=$version -X k8s.io/kubernetes/pkg/version.gitVersion=$version" ./cmd/kubelet/kubelet.go
cp ./kubelet.exe "$gopath/bin/"

# Dump version
echo "Kubelet version:"
kubelet.exe --version
echo "Docker version:"
docker version
function BuildKubelet()
{
Write-Host "Building kubelet"
$gopath = [System.Environment]::GetEnvironmentVariable("GOPATH")
$k8siopath = $gopath + "/src/k8s.io"
$kubernetespath = $k8siopath + "/kubernetes"
md $k8siopath -ErrorAction Ignore
if (Test-Path $kubernetespath)
{
Write-Host "Using existing kubernetes repo."
}
else
{
cd $k8siopath
git clone -c core.symlinks=true https://github.com/kubernetes/kubernetes
}

cd $kubernetespath
$branch = [System.Environment]::GetEnvironmentVariable("TRAVIS_BRANCH")
if ( ! "$branch".Equals("master") ) {
# We can do this because cri-tools have the same branch name with kubernetes.
git checkout "$branch"
}

# Build kubelet
$version = git describe --tags --dirty --always
go build -ldflags "-X k8s.io/kubernetes/vendor/k8s.io/client-go/pkg/version.gitVersion=$version -X k8s.io/kubernetes/pkg/version.gitVersion=$version" ./cmd/kubelet/kubelet.go
cp ./kubelet.exe $BaseDir
}

function DumpKubeletVersion()
{
# Dump version
echo "Kubelet version:"
C:\k\kubelet.exe --version
echo "Docker version:"
docker version
}

function DownloadFile()
{
param(
[parameter(Mandatory = $true)] $Url,
[parameter(Mandatory = $true)] $Destination
)

if (Test-Path $Destination)
{
Write-Host "File $Destination already exists."
return
}

try {
(New-Object System.Net.WebClient).DownloadFile($Url,$Destination)
Write-Host "Downloaded $Url=>$Destination"
} catch {
Write-Error "Failed to download $Url"
throw
}
}

function DownloadCniBinaries()
{
Write-Host "Downloading CNI binaries"
md $BaseDir\cni\config -ErrorAction Ignore

DownloadFile -Url https://github.com/Microsoft/SDN/raw/master/Kubernetes/windows/cni/wincni.exe -Destination $BaseDir\cni\wincni.exe
}

function DownloadWindowsKubernetesScripts()
{
Write-Host "Downloading Windows Kubernetes scripts"
DownloadFile -Url https://github.com/Microsoft/SDN/raw/master/Kubernetes/windows/hns.psm1 -Destination $BaseDir\hns.psm1
DownloadFile -Url https://raw.githubusercontent.com/Microsoft/SDN/master/Kubernetes/windows/helper.psm1 -Destination $BaseDir\helper.psm1
}

function CopyKubeletScripts()
{
$gopath = [System.Environment]::GetEnvironmentVariable("GOPATH")
$critestpath = $gopath + "/src/github.com/kubernetes-sigs/cri-tools/hack/start-kubelet.ps1"
cp $critestpath $BaseDir
}

function DownloadAllFiles()
{
DownloadCniBinaries
DownloadWindowsKubernetesScripts
BuildKubelet
CopyKubeletScripts
}

function New-InfraContainer
{
cd C:\k
$computerInfo = Get-ComputerInfo
$windowsBase = if ($computerInfo.WindowsVersion -eq "1709") {
"microsoft/nanoserver:1709"
} elseif ($computerInfo.WindowsVersion -eq "1803") {
"microsoft/nanoserver:1803"
} elseif ($computerInfo.WindowsVersion -eq "1809") {
# TODO: unsure if 2019 will report 1809 or not
"microsoft/nanoserver:1809"
} else {
"mcr.microsoft.com/nanoserver-insider"
}

"FROM $($windowsBase)" | Out-File -encoding ascii -FilePath Dockerfile
"CMD cmd /c ping -t localhost" | Out-File -encoding ascii -FilePath Dockerfile -Append
docker build -t kubletwin/pause .
}

# Download files
$BaseDir = "c:\k"
md $BaseDir -ErrorAction Ignore
DownloadAllFiles
DumpKubeletVersion
ipmo $BaseDir\helper.psm1
ipmo $BaseDir\hns.psm1

# Prepare POD infra Images
New-InfraContainer


# WinCni needs the networkType and network name to be the same
$NetworkName = "l2bridge"
CleanupOldNetwork $NetworkName

# Start kubelet
Start powershell -ArgumentList "-File $BaseDir\start-kubelet.ps1 -clusterCIDR $clusterCIDR -podCIDR $podCIDR -NetworkName $NetworkName"

# Wait a while for dockershim starting.
Start-Sleep 10

33 changes: 33 additions & 0 deletions hack/run-critest.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright 2018 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Stop on any error.
$ErrorActionPreference = "Stop"
$VerbosePreference = "Continue"

# Get binary path
$gopath = [System.Environment]::GetEnvironmentVariable("GOPATH")
$critestpath = $gopath + "/src/github.com/kubernetes-sigs/cri-tools/_output"

# Run e2e test cases
# Only run basic runtime info now because Windows images are not yet pushed.
cd $critestpath
./critest.exe -"ginkgo.focus" "Runtime info"

# Check
if (!$?)
{
Write-Host "critest failed!"
exit 1
}
Loading

0 comments on commit 37c3115

Please sign in to comment.