Skip to content

Commit

Permalink
Enable Windows OVS Container to run on pristine Host Environment
Browse files Browse the repository at this point in the history
Signed-off-by: Naman Agarwal <naman.agarwal75@gmail.com>
  • Loading branch information
NamanAg30 committed Aug 30, 2023
1 parent 4cc6f63 commit 1fb02d2
Showing 1 changed file with 131 additions and 2 deletions.
133 changes: 131 additions & 2 deletions build/yamls/antrea-windows-containerd-with-ovs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,135 @@ data:
& antrea-agent --config=$mountPath/etc/antrea/antrea-agent.conf --logtostderr=false --log_dir=c:/var/log/antrea --alsologtostderr --log_file_max_size=100 --log_file_max_num=4 --v=0
Run-AntreaOVS-Containerd.ps1: |
$ErrorActionPreference = "Stop"
$AntreaVersion = "3.0.5-antrea.0"
$OVSDownloadURL = "https://downloads.antrea.io/ovs/ovs-$AntreaVersion-win64.zip"
$OVSPublishedHash = 'fd27703ef7314b26b98cffb7aea27d569530ebd3ac3c98daa981ca2654373032'
$WorkDir = [System.IO.Path]::GetDirectoryName($myInvocation.MyCommand.Definition)
$OVSDownloadDir = $WorkDir
$OVSInstallDir = "C:\openvswitch"
$OVSZip = "$OVSDownloadDir\ovs-win64.zip"
$ImportCertificate = $true
$CheckFileHash = $true
$PowerShellModuleBase = "C:\Windows\System32\WindowsPowerShell\v1.0\Modules"
$InstallLog = "$OVSDownloadDir\install_ovs.log"
function Log($Info) {
$time = $(get-date -Format g)
"$time $Info `n`r" | Tee-Object $InstallLog -Append | Write-Host
}
function CreatePath($Path){
if ($(Test-Path $Path)) {
mv $Path $($Path + "_bak")
}
mkdir -p $Path | Out-Null
}
function SetEnvVar($key, $value) {
[Environment]::SetEnvironmentVariable($key, $value, [EnvironmentVariableTarget]::Machine)
}
function WaitExpandFiles($Src, $Dest) {
Log "Extract $Src to $Dest"
Expand-Archive -Path $Src -DestinationPath $Dest | Out-Null
}
function CheckIfOVSInstalled() {
if (Test-Path -Path $OVSInstallDir) {
Log "$OVSInstallDir already exists, exit OVS installation."
exit 1
}
}
If (!(Test-Path $OVSDownloadDir)) {
mkdir -p $OVSDownloadDir
}
Log "Downloading OVS package from $OVSDownloadURL to $OVSZip"
curl.exe -sLo $OVSZip $OVSDownloadURL
If (!$?) {
Log "Download OVS failed, URL: $OVSDownloadURL"
exit 1
}
if ($CheckFileHash) {
$FileHash = Get-FileHash $OVSZip
If ($OVSPublishedHash -ne "" -And $FileHash.Hash -ne $OVSPublishedHash) {
Log "SHA256 mismatch for OVS download"
exit 1
}
}
WaitExpandFiles $OVSZip $OVSDownloadDir
# Copy OVS package to target dir.
Log "Copying OVS package from $OVSDownloadDir\openvswitch to $OVSInstallDir"
mv "$OVSDownloadDir\openvswitch" $OVSInstallDir
rm $OVSZip
# Create log and run dir.
$OVS_LOG_PATH = $OVSInstallDir + "\var\log\openvswitch"
CreatePath $OVS_LOG_PATH
$OVSRunDir = $OVSInstallDir + "\var\run\openvswitch"
CreatePath $OVSRunDir
$OVSDriverDir = "$OVSInstallDir\driver"
# Install OVS driver certificate.
$DriverFile="$OVSDriverDir\OVSExt.sys"
if ($ImportCertificate) {
$CertificateFile = "$OVSDriverDir\package.cer"
if (!(Test-Path $CertificateFile)) {
$ExportType = [System.Security.Cryptography.X509Certificates.X509ContentType]::Cert;
$Cert = (Get-AuthenticodeSignature $DriverFile).SignerCertificate;
[System.IO.File]::WriteAllBytes($CertificateFile, $Cert.Export($ExportType));
}
Log "Installing OVS driver certificate."
Import-Certificate -FilePath "$CertificateFile" -CertStoreLocation cert:\LocalMachine\TrustedPublisher
Import-Certificate -FilePath "$CertificateFile" -CertStoreLocation cert:\LocalMachine\Root
}
# Install Microsoft Visual C++ Redistributable Package.
if (Test-Path $OVSInstallDir\redist) {
Log "Installing Microsoft Visual C++ Redistributable Package."
$RedistFiles = Get-ChildItem "$OVSInstallDir\redist" -Filter *.exe
$RedistFiles | ForEach-Object {
Log "Installing $_"
Start-Process -FilePath $_.FullName -Args '/install /passive /norestart' -Verb RunAs -Wait
}
}
# Install powershell modules
if (Test-Path $OVSInstallDir\scripts) {
Log "Installing powershell modules."
$PSModuleFiles = Get-ChildItem "$OVSInstallDir\scripts" -Filter *.psm1
$PSModuleFiles | ForEach-Object {
$PSModulePath = Join-Path -Path $PowerShellModuleBase -ChildPath $_.BaseName
if (!(Test-Path $PSModulePath)) {
Log "Installing $_"
mkdir -p $PSModulePath
Copy-Item $_.FullName $PSModulePath
}
}
}
# Install OVS kernel driver.
Log "Installing OVS kernel driver"
$VMMSStatus = $(Get-Service vmms -ErrorAction SilentlyContinue).Status
if (!$VMMSStatus) {
$VMMSStatus = "not exist"
}
Log "Hyper-V Virtual Machine Management service status: $VMMSStatus"
if ($VMMSStatus -eq "Running") {
cmd /c "cd $OVSDriverDir && install.cmd"
} else {
cd $OVSDriverDir ; netcfg -l .\ovsext.inf -c s -i OVSExt; cd $WorkDir
}
if (!$?) {
Log "Install OVS kernel driver failed, exit"
exit 1
}
$OVS_BIN_PATH="$OVSInstallDir\usr\bin;$OVSInstallDir\usr\sbin"
$env:Path += ";$OVS_BIN_PATH"
SetEnvVar "Path" $env:Path
$mountPath = $env:CONTAINER_SANDBOX_MOUNT_POINT
$mountPath = ($mountPath.Replace('\', '/')).TrimEnd('/')
$env:PATH = $env:PATH + ";$mountPath/Windows/System32;$mountPath/openvswitch/usr/bin;$mountPath/openvswitch/usr/sbin"
Expand Down Expand Up @@ -197,7 +326,7 @@ data:
# Provide the address of Kubernetes apiserver, to override any value provided in kubeconfig or InClusterConfig.
# Defaults to "". It must be a host string, a host:port pair, or a URL to the base of the apiserver.
#kubeAPIServerOverride: ""
kubeAPIServerOverride: "https://10.221.121.58:6443"
# Option antreaProxy contains AntreaProxy related configuration options.
antreaProxy:
Expand Down Expand Up @@ -366,4 +495,4 @@ spec:
type: DirectoryOrCreate
name: var-log-antrea
updateStrategy:
type: RollingUpdate
type: RollingUpdate

0 comments on commit 1fb02d2

Please sign in to comment.