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 <wenyingd@vmware.com>
  • Loading branch information
wenyingd committed Jun 6, 2024
1 parent baf51c1 commit 8e090cf
Show file tree
Hide file tree
Showing 8 changed files with 410 additions and 221 deletions.
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
43 changes: 8 additions & 35 deletions build/yamls/antrea-windows-with-ovs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,12 @@ data:
$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"
}
# 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
}
}
$OVSInstallScript = "$mountPath\k\antrea\Install-OVS.ps1"
if (Test-Path $OVSInstallScript) {
& $OVSInstallScript -InstallUserspace $false -LocalFile $mountPath\openvswitch
} else {
Write-Host "Installation script not found: $OVSInstallScript, please manually install OVS drivers"
exit 1
}
Install-WindowsCNI.ps1: |
$ErrorActionPreference = "Stop";
Expand Down Expand Up @@ -82,7 +55,7 @@ data:
$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 @@ -324,7 +297,7 @@ spec:
template:
metadata:
annotations:
checksum/agent-windows: da4b49898e3181dfcb6359f2b2acba452c2ff9a17af8342b6cccb73e8857aad6
checksum/agent-windows: 9aed7ded773dbf746f8373f2c7557c74568f7c9df9ce4b4fe8fcad97038ca637
checksum/windows-config: 6ff4f8bd0b310ebe4d4612bdd9697ffb3d79e0e0eab3936420417dd5a8fc128d
microsoft.com/hostprocess-inherit-user: "true"
labels:
Expand Down
39 changes: 6 additions & 33 deletions build/yamls/windows/containerd-with-ovs/conf/Install-OVSDriver.ps1
Original file line number Diff line number Diff line change
@@ -1,37 +1,10 @@
$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"
}

# 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
}
}
$OVSInstallScript = "$mountPath\k\antrea\Install-OVS.ps1"
if (Test-Path $OVSInstallScript) {
& $OVSInstallScript -InstallUserspace $false -LocalFile $mountPath\openvswitch
} else {
Write-Host "Installation script not found: $OVSInstallScript, please manually install OVS drivers"
exit 1
}
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
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ spec:
- $env:CONTAINER_SANDBOX_MOUNT_POINT/var/lib/antrea-windows/Install-OVSDriver.ps1
command:
- powershell
image: antrea/antrea-windows:latest
image: antrea-windows
imagePullPolicy: IfNotPresent
name: install-ovs-driver
volumeMounts:
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 | `.\Install-OVS.ps1 -InstallUserspace $false` |
| 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 8e090cf

Please sign in to comment.