Skip to content

Commit

Permalink
[Windows] Optimize the containerized OVS installation steps
Browse files Browse the repository at this point in the history
1. Add logic to check the installed OVSext drivers, if only the desired version
   of driver is already installed, skip the installation; otherwise, remove the
   existing the drivers and re-install.
2. Add logic to check the installed VC redistributable files, if the existing
   installd vc_redist version is equal to or higher than the lowest requirement,
   skip the installation; otherwise re-install the files provided in the image.
3. Optimize the logic of maintaining the system paths by removing the duplicated
   path.
4. Optimize Uninstall-OVS script by removing OVS bin paths from the system path
   after it is deleted.

Signed-off-by: Wenying Dong <[email protected]>
  • Loading branch information
wenyingd committed Jun 13, 2024
1 parent cb618ed commit 514cf85
Show file tree
Hide file tree
Showing 9 changed files with 537 additions and 234 deletions.
2 changes: 1 addition & 1 deletion build/charts/antrea-windows/conf/Run-AntreaAgent.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
$ErrorActionPreference = "Stop"
$mountPath = $env:CONTAINER_SANDBOX_MOUNT_POINT
$mountPath = ($mountPath.Replace('\', '/')).TrimEnd('/')
$env:PATH = $env:PATH + ";$mountPath/Windows/System32;$mountPath/k/antrea/bin;$mountPath/openvswitch/usr/bin;$mountPath/openvswitch/usr/sbin"
$env:PATH = $env:PATH + ";$mountPath/k/antrea/bin;$mountPath/openvswitch/usr/bin;$mountPath/openvswitch/usr/sbin"
& 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
44 changes: 12 additions & 32 deletions build/charts/antrea-windows/conf/ovs/Install-OVSDriver.ps1
Original file line number Diff line number Diff line change
@@ -1,37 +1,17 @@
$ErrorActionPreference = "Stop"
$mountPath = $env:CONTAINER_SANDBOX_MOUNT_POINT
$mountPath = ($mountPath.Replace('\', '/')).TrimEnd('/')
$OVSDriverDir = "$mountPath\openvswitch\driver"

# Check if OVSExt driver is already installed
$driverStatus = netcfg -q ovsext
if ($driverStatus -like '*not installed*') {
# Install OVS Driver
$result = netcfg -l $OVSDriverDir/ovsext.inf -c s -i OVSExt
if ($result -like '*failed*') {
Write-Host "Failed to install OVSExt driver: $result"
exit 1
}
Write-Host "OVSExt driver has been installed"
$OVSInstallScript = "$mountPath\k\antrea\Install-OVS.ps1"
if (-not (Test-Path $OVSInstallScript)) {
Write-Host "Installation script not found: $OVSInstallScript, you may be using an invalid antrea-windows container image"
exit 1
}

# Check if the VC redistributable is already installed.
$OVSRedistDir="$mountPath\openvswitch\redist"
if (Test-Path $OVSRedistDir) {
$dllFound = $false
$paths = $env:PATH -split ';'
foreach ($path in $paths) {
$dllFiles = Get-ChildItem -Path $path -Filter "vcruntime*.dll" -File -ErrorAction SilentlyContinue
if ($dllFiles.Count -gt 0) {
$dllFound = $true
break
}
}

# vcruntime dlls are not installed on the host, then install the binaries.
if (-not $dllFound) {
Get-ChildItem $OVSRedistDir -Filter *.exe | ForEach-Object {
Start-Process -FilePath $_.FullName -Args '/install /passive /norestart' -Verb RunAs -Wait
}
}
$installOVSJob = Start-Job -FilePath $OVSInstallScript -ArgumentList "","","$mountPath/openvswitch",$false,""
$installOVSJob | Receive-Job -Wait
Remove-Job -Id $installOVSJob.Id
$state = $installOVSJob.State
if ($state -ne "Completed") {
Write-Host "Failed to install OVS with state: $state"
exit 1
}
Write-Host "Completed to install OVS"
2 changes: 1 addition & 1 deletion build/charts/antrea-windows/conf/ovs/Run-AntreaOVS.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
$ErrorActionPreference = "Stop"
$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"
$env:PATH = $env:PATH + ";$mountPath/openvswitch/usr/bin;$mountPath/openvswitch/usr/sbin"
$OVSDriverDir = "$mountPath\openvswitch\driver"

# Configure OVS processes
Expand Down
3 changes: 2 additions & 1 deletion build/images/Dockerfile.build.windows
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ RUN --mount=type=cache,target=/go/pkg/mod/ \
RUN mkdir -p /go/k/antrea/bin && \
cp /antrea/bin/antrea-agent.exe /go/k/antrea/bin/ && \
cp /antrea/bin/antctl.exe /go/k/antrea/bin/ && \
cp /antrea/bin/antrea-cni.exe /go/k/antrea/cni/antrea.exe
cp /antrea/bin/antrea-cni.exe /go/k/antrea/cni/antrea.exe && \
cp /antrea/hack/windows/Install-OVS.ps1 /go/k/antrea/

FROM antrea/windows-ovs:${OVS_VERSION} as antrea-ovs

Expand Down
50 changes: 15 additions & 35 deletions build/yamls/antrea-windows-with-ovs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,51 +40,31 @@ data:
$ErrorActionPreference = "Stop"
$mountPath = $env:CONTAINER_SANDBOX_MOUNT_POINT
$mountPath = ($mountPath.Replace('\', '/')).TrimEnd('/')
$env:PATH = $env:PATH + ";$mountPath/Windows/System32;$mountPath/k/antrea/bin;$mountPath/openvswitch/usr/bin;$mountPath/openvswitch/usr/sbin"
$env:PATH = $env:PATH + ";$mountPath/k/antrea/bin;$mountPath/openvswitch/usr/bin;$mountPath/openvswitch/usr/sbin"
& 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
Install-OVSDriver.ps1: |
$ErrorActionPreference = "Stop"
$mountPath = $env:CONTAINER_SANDBOX_MOUNT_POINT
$mountPath = ($mountPath.Replace('\', '/')).TrimEnd('/')
$OVSDriverDir = "$mountPath\openvswitch\driver"
# Check if OVSExt driver is already installed
$driverStatus = netcfg -q ovsext
if ($driverStatus -like '*not installed*') {
# Install OVS Driver
$result = netcfg -l $OVSDriverDir/ovsext.inf -c s -i OVSExt
if ($result -like '*failed*') {
Write-Host "Failed to install OVSExt driver: $result"
exit 1
}
Write-Host "OVSExt driver has been installed"
$OVSInstallScript = "$mountPath\k\antrea\Install-OVS.ps1"
if (-not (Test-Path $OVSInstallScript)) {
Write-Host "Installation script not found: $OVSInstallScript, you may be using an invalid antrea-windows container image"
exit 1
}
# Check if the VC redistributable is already installed.
$OVSRedistDir="$mountPath\openvswitch\redist"
if (Test-Path $OVSRedistDir) {
$dllFound = $false
$paths = $env:PATH -split ';'
foreach ($path in $paths) {
$dllFiles = Get-ChildItem -Path $path -Filter "vcruntime*.dll" -File -ErrorAction SilentlyContinue
if ($dllFiles.Count -gt 0) {
$dllFound = $true
break
}
}
# vcruntime dlls are not installed on the host, then install the binaries.
if (-not $dllFound) {
Get-ChildItem $OVSRedistDir -Filter *.exe | ForEach-Object {
Start-Process -FilePath $_.FullName -Args '/install /passive /norestart' -Verb RunAs -Wait
}
}
$installOVSJob = Start-Job -FilePath $OVSInstallScript -ArgumentList "","","$mountPath/openvswitch",$false,""
$installOVSJob | Receive-Job -Wait
Remove-Job -Id $installOVSJob.Id
$state = $installOVSJob.State
if ($state -ne "Completed") {
Write-Host "Failed to install OVS with state: $state"
exit 1
}
Write-Host "Completed to install OVS"
Run-AntreaOVS.ps1: |
$ErrorActionPreference = "Stop"
$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"
$env:PATH = $env:PATH + ";$mountPath/openvswitch/usr/bin;$mountPath/openvswitch/usr/sbin"
$OVSDriverDir = "$mountPath\openvswitch\driver"
# Configure OVS processes
Expand Down Expand Up @@ -328,7 +308,7 @@ spec:
template:
metadata:
annotations:
checksum/agent-windows: 5efe6525007ef87c58914b37d190f84bc93b8cf081d204979dffce0859ee2da3
checksum/agent-windows: 81b816813eb399e0c0d53fb7b9fb75883e244c1ab8418c1bdf29ccd21a981fe6
checksum/windows-config: 10ad2be0a04b1752abc224fed0124f7b1da36efc5e7323e193eb38e11b25e798
microsoft.com/hostprocess-inherit-user: "true"
labels:
Expand Down
4 changes: 2 additions & 2 deletions build/yamls/antrea-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ data:
$ErrorActionPreference = "Stop"
$mountPath = $env:CONTAINER_SANDBOX_MOUNT_POINT
$mountPath = ($mountPath.Replace('\', '/')).TrimEnd('/')
$env:PATH = $env:PATH + ";$mountPath/Windows/System32;$mountPath/k/antrea/bin;$mountPath/openvswitch/usr/bin;$mountPath/openvswitch/usr/sbin"
$env:PATH = $env:PATH + ";$mountPath/k/antrea/bin;$mountPath/openvswitch/usr/bin;$mountPath/openvswitch/usr/sbin"
& 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
kind: ConfigMap
metadata:
Expand Down Expand Up @@ -233,7 +233,7 @@ spec:
template:
metadata:
annotations:
checksum/agent-windows: adb135c962fe85e0a2bc86a45f4b8c72d89b09a1da35bb16775e547813295679
checksum/agent-windows: 63f16e1fadb6b1354efda21c73702b4290400181136d4d47d4b1cd6a5f82d037
checksum/windows-config: 10ad2be0a04b1752abc224fed0124f7b1da36efc5e7323e193eb38e11b25e798
microsoft.com/hostprocess-inherit-user: "true"
labels:
Expand Down
14 changes: 7 additions & 7 deletions docs/windows.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,12 @@ depending on whether you are using your own [signed](https://docs.microsoft.com/
OVS kernel driver or you want to use the test-signed driver provided by Antrea,
you will need to invoke the `Install-OVS.ps1` script differently (or not at all).

| Containerized OVS daemons? | Test-signed OVS driver? | Run this command |
| -------------------------- | ----------------------- | ---------------- |
| Yes | Yes | `.\Install-OVS.ps1 -InstallUserspace $false` |
| Yes | No | N/A |
| No | Yes | `.\Install-OVS.ps1` |
| No | No | `.\Install-OVS.ps1 -ImportCertificate $false -Local -LocalFile <PathToOVSPackage>` |
| Containerized OVS daemons? | Test-signed OVS driver? | Run this command |
| -------------------------- | ----------------------- |---------------------------------------------------------------------------|
| Yes | Yes | N/A |
| Yes | No | N/A |
| No | Yes | `.\Install-OVS.ps1 -InstallUserspace $true` |
| No | No | `.\Install-OVS.ps1 -InstallUserspace $true -LocalFile <PathToOVSPackage>` |

If you used `antrea-windows-with-ovs.yml` to create the antrea-agent
Windows DaemonSet, then you are using "Containerized OVS daemons". For all other
Expand Down Expand Up @@ -208,7 +208,7 @@ your own OVS package with a signed OVS kernel driver, you would run:

```powershell
curl.exe -LO https://raw.githubusercontent.com/antrea-io/antrea/main/hack/windows/Install-OVS.ps1
.\Install-OVS.ps1 -ImportCertificate $false -Local -LocalFile <PathToOVSPackage>
.\Install-OVS.ps1 -InstallUserspace $true -LocalFile <PathToOVSPackage>
# verify that the OVS services are installed
get-service ovsdb-server
Expand Down
Loading

0 comments on commit 514cf85

Please sign in to comment.