Skip to content
This repository was archived by the owner on Oct 10, 2023. It is now read-only.

Commit 988ea3a

Browse files
committed
Register cleanup for antrea
Antrea fails to start after Windows nodes reboot because OVS bridge and HnsNetwork previously created by Antrea is not cleaned, a cleanup script is provided in the new version of Antrea, this change registers the script as a callback on system's shutdown, the cleanup script will be invoked before Windows shutdown.
1 parent 80b16b5 commit 988ea3a

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#@ load("@ytt:overlay", "overlay")
2+
#@ load("@ytt:data", "data")
3+
#@ if data.values.IS_WINDOWS_WORKLOAD_CLUSTER:
4+
#@ if data.values.CNI == "antrea":
5+
#@overlay/match by=overlay.subset({"kind":"KubeadmConfigTemplate"})
6+
---
7+
spec:
8+
template:
9+
spec:
10+
files:
11+
- path: C:\k\register_antrea_cleanup.ps1
12+
content: |
13+
$methodScript = "C:\k\antrea\Clean-AntreaNetwork.ps1"
14+
if (Test-Path "$methodScript") {
15+
$method = "Shutdown"
16+
$RegPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy"
17+
$RegScriptsPath = "$RegPath\Scripts\$method\0"
18+
$RegSmScriptsPath = "$RegPath\State\Machine\Scripts\$method\0"
19+
# Create the path if not exist
20+
$gpoPath = "$ENV:systemRoot\System32\GroupPolicy\Machine"
21+
$methodPath = "$gpoPath\Scripts\$method"
22+
if (-not (Test-Path $methodPath)) {
23+
New-Item -path $methodPath -itemType Directory
24+
}
25+
# Create sub-path
26+
$items = @("$RegScriptsPath\0", "$RegSmScriptsPath\0")
27+
foreach ($item in $items) {
28+
if (-not (Test-Path $item)) {
29+
New-Item -path $item -force
30+
}
31+
}
32+
# Register callback script to GPO
33+
$items = @("$RegScriptsPath", "$RegSmScriptsPath")
34+
foreach ($item in $items) {
35+
New-ItemProperty -path "$item" -name DisplayName -propertyType String -value "Local Group Policy" -force
36+
New-ItemProperty -path "$item" -name FileSysPath -propertyType String -value "$gpoPath" -force
37+
New-ItemProperty -path "$item" -name GPO-ID -propertyType String -value "LocalGPO" -force
38+
New-ItemProperty -path "$item" -name GPOName -propertyType String -value "Local Group Policy" -force
39+
New-ItemProperty -path "$item" -name PSScriptOrder -propertyType DWord -value 2 -force
40+
New-ItemProperty -path "$item" -name SOM-ID -propertyType String -value "Local" -force
41+
}
42+
$BinaryString = "00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00"
43+
$ExecTime = $BinaryString.Split(',') | ForEach-Object {"0x$_"}
44+
$items = @("$RegScriptsPath\0", "$RegSmScriptsPath\0")
45+
foreach ($item in $items) {
46+
New-ItemProperty -path "$item" -name Script -propertyType String -value $methodScript -force
47+
New-ItemProperty -path "$item" -name Parameters -propertyType String -value $method -force
48+
New-ItemProperty -path "$item" -name IsPowershell -propertyType DWord -value 1 -force
49+
New-ItemProperty -path "$item" -name ExecTime -propertyType Binary -value ([byte[]]$ExecTime) -force
50+
}
51+
}
52+
postKubeadmCommands:
53+
- powershell C:/k/register_antrea_cleanup.ps1 -ExecutionPolicy Bypass
54+
#@ end
55+
#@ end

0 commit comments

Comments
 (0)