|
| 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