From 7310dd03db4e71f1b56e11a16dc491d19527a28b Mon Sep 17 00:00:00 2001 From: Amim Knabben Date: Wed, 15 Feb 2023 14:40:02 -0300 Subject: [PATCH 1/2] Registering cleanup Antrea interface --- .../bundle/config/upstream/base.yaml | 55 +++++++++++++++++++ .../v1.5.1/cconly/base.yaml | 55 +++++++++++++++++++ 2 files changed, 110 insertions(+) diff --git a/packages/tkg-clusterclass-vsphere/bundle/config/upstream/base.yaml b/packages/tkg-clusterclass-vsphere/bundle/config/upstream/base.yaml index b3c525c205..10da01a572 100644 --- a/packages/tkg-clusterclass-vsphere/bundle/config/upstream/base.yaml +++ b/packages/tkg-clusterclass-vsphere/bundle/config/upstream/base.yaml @@ -2057,6 +2057,61 @@ spec: start-service kubelet start-service kube-proxy start-service antrea-agent + - op: add + path: /spec/template/spec/files/- + value: + path: 'C:\k\antrea_cleanup.ps1' + content: | + stop-service antrea-agent -ErrorAction SilentlyContinue + C:\k\antrea\Clean-AntreaNetwork.ps1 + - op: add + path: /spec/template/spec/files/- + value: + path: 'C:\k\register_antrea_cleanup.ps1' + content: | + $methodScript = "C:\k\antrea\Clean-AntreaNetwork.ps1" + if (Test-Path "$methodScript") { + $cleanScriptPath = "C:\k\antrea_cleanup.ps1" + $method = "Shutdown" + $RegPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy" + $RegScriptsPath = "$RegPath\Scripts\$method\0" + $RegSmScriptsPath = "$RegPath\State\Machine\Scripts\$method\0" + # Create the path if not exist + $gpoPath = "$ENV:systemRoot\System32\GroupPolicy\Machine" + $methodPath = "$gpoPath\Scripts\$method" + if (-not (Test-Path $methodPath)) { + New-Item -path $methodPath -itemType Directory + } + # Create sub-path + $items = @("$RegScriptsPath\0", "$RegSmScriptsPath\0") + foreach ($item in $items) { + if (-not (Test-Path $item)) { + New-Item -path $item -force + } + } + # Register callback script to GPO + $items = @("$RegScriptsPath", "$RegSmScriptsPath") + foreach ($item in $items) { + New-ItemProperty -path "$item" -name DisplayName -propertyType String -value "Local Group Policy" -force + New-ItemProperty -path "$item" -name FileSysPath -propertyType String -value "$gpoPath" -force + New-ItemProperty -path "$item" -name GPO-ID -propertyType String -value "LocalGPO" -force + New-ItemProperty -path "$item" -name GPOName -propertyType String -value "Local Group Policy" -force + New-ItemProperty -path "$item" -name PSScriptOrder -propertyType DWord -value 2 -force + New-ItemProperty -path "$item" -name SOM-ID -propertyType String -value "Local" -force + } + $BinaryString = "00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00" + $ExecTime = $BinaryString.Split(',') | ForEach-Object {"0x$_"} + $items = @("$RegScriptsPath\0", "$RegSmScriptsPath\0") + foreach ($item in $items) { + New-ItemProperty -path "$item" -name Script -propertyType String -value $cleanScriptPath -force + New-ItemProperty -path "$item" -name Parameters -propertyType String -value $method -force + New-ItemProperty -path "$item" -name IsPowershell -propertyType DWord -value 1 -force + New-ItemProperty -path "$item" -name ExecTime -propertyType Binary -value ([byte[]]$ExecTime) -force + } + } + - op: add + path: /spec/template/spec/postKubeadmCommands/- + value: powershell C:/k/register_antrea_cleanup.ps1 -ExecutionPolicy Bypass - op: add path: /spec/template/spec/postKubeadmCommands/- value: powershell C:/Temp/antrea.ps1 -ExecutionPolicy Bypass diff --git a/providers/infrastructure-vsphere/v1.5.1/cconly/base.yaml b/providers/infrastructure-vsphere/v1.5.1/cconly/base.yaml index b3c525c205..10da01a572 100644 --- a/providers/infrastructure-vsphere/v1.5.1/cconly/base.yaml +++ b/providers/infrastructure-vsphere/v1.5.1/cconly/base.yaml @@ -2057,6 +2057,61 @@ spec: start-service kubelet start-service kube-proxy start-service antrea-agent + - op: add + path: /spec/template/spec/files/- + value: + path: 'C:\k\antrea_cleanup.ps1' + content: | + stop-service antrea-agent -ErrorAction SilentlyContinue + C:\k\antrea\Clean-AntreaNetwork.ps1 + - op: add + path: /spec/template/spec/files/- + value: + path: 'C:\k\register_antrea_cleanup.ps1' + content: | + $methodScript = "C:\k\antrea\Clean-AntreaNetwork.ps1" + if (Test-Path "$methodScript") { + $cleanScriptPath = "C:\k\antrea_cleanup.ps1" + $method = "Shutdown" + $RegPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy" + $RegScriptsPath = "$RegPath\Scripts\$method\0" + $RegSmScriptsPath = "$RegPath\State\Machine\Scripts\$method\0" + # Create the path if not exist + $gpoPath = "$ENV:systemRoot\System32\GroupPolicy\Machine" + $methodPath = "$gpoPath\Scripts\$method" + if (-not (Test-Path $methodPath)) { + New-Item -path $methodPath -itemType Directory + } + # Create sub-path + $items = @("$RegScriptsPath\0", "$RegSmScriptsPath\0") + foreach ($item in $items) { + if (-not (Test-Path $item)) { + New-Item -path $item -force + } + } + # Register callback script to GPO + $items = @("$RegScriptsPath", "$RegSmScriptsPath") + foreach ($item in $items) { + New-ItemProperty -path "$item" -name DisplayName -propertyType String -value "Local Group Policy" -force + New-ItemProperty -path "$item" -name FileSysPath -propertyType String -value "$gpoPath" -force + New-ItemProperty -path "$item" -name GPO-ID -propertyType String -value "LocalGPO" -force + New-ItemProperty -path "$item" -name GPOName -propertyType String -value "Local Group Policy" -force + New-ItemProperty -path "$item" -name PSScriptOrder -propertyType DWord -value 2 -force + New-ItemProperty -path "$item" -name SOM-ID -propertyType String -value "Local" -force + } + $BinaryString = "00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00" + $ExecTime = $BinaryString.Split(',') | ForEach-Object {"0x$_"} + $items = @("$RegScriptsPath\0", "$RegSmScriptsPath\0") + foreach ($item in $items) { + New-ItemProperty -path "$item" -name Script -propertyType String -value $cleanScriptPath -force + New-ItemProperty -path "$item" -name Parameters -propertyType String -value $method -force + New-ItemProperty -path "$item" -name IsPowershell -propertyType DWord -value 1 -force + New-ItemProperty -path "$item" -name ExecTime -propertyType Binary -value ([byte[]]$ExecTime) -force + } + } + - op: add + path: /spec/template/spec/postKubeadmCommands/- + value: powershell C:/k/register_antrea_cleanup.ps1 -ExecutionPolicy Bypass - op: add path: /spec/template/spec/postKubeadmCommands/- value: powershell C:/Temp/antrea.ps1 -ExecutionPolicy Bypass From 7b9c657e7e523815edead117328dcfba4d0f1296 Mon Sep 17 00:00:00 2001 From: Amim Knabben Date: Wed, 15 Feb 2023 18:05:59 -0300 Subject: [PATCH 2/2] Adding cleanup interface script on boot --- .../tkg-clusterclass-vsphere/bundle/config/upstream/base.yaml | 4 ++-- providers/infrastructure-vsphere/v1.5.1/cconly/base.yaml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/tkg-clusterclass-vsphere/bundle/config/upstream/base.yaml b/packages/tkg-clusterclass-vsphere/bundle/config/upstream/base.yaml index 10da01a572..7a3b107efe 100644 --- a/packages/tkg-clusterclass-vsphere/bundle/config/upstream/base.yaml +++ b/packages/tkg-clusterclass-vsphere/bundle/config/upstream/base.yaml @@ -2111,10 +2111,10 @@ spec: } - op: add path: /spec/template/spec/postKubeadmCommands/- - value: powershell C:/k/register_antrea_cleanup.ps1 -ExecutionPolicy Bypass + value: powershell C:/Temp/antrea.ps1 -ExecutionPolicy Bypass - op: add path: /spec/template/spec/postKubeadmCommands/- - value: powershell C:/Temp/antrea.ps1 -ExecutionPolicy Bypass + value: powershell C:/k/register_antrea_cleanup.ps1 -ExecutionPolicy Bypass - name: ntpServers enabledIf: '{{ not (empty .ntpServers) }}' definitions: diff --git a/providers/infrastructure-vsphere/v1.5.1/cconly/base.yaml b/providers/infrastructure-vsphere/v1.5.1/cconly/base.yaml index 10da01a572..7a3b107efe 100644 --- a/providers/infrastructure-vsphere/v1.5.1/cconly/base.yaml +++ b/providers/infrastructure-vsphere/v1.5.1/cconly/base.yaml @@ -2111,10 +2111,10 @@ spec: } - op: add path: /spec/template/spec/postKubeadmCommands/- - value: powershell C:/k/register_antrea_cleanup.ps1 -ExecutionPolicy Bypass + value: powershell C:/Temp/antrea.ps1 -ExecutionPolicy Bypass - op: add path: /spec/template/spec/postKubeadmCommands/- - value: powershell C:/Temp/antrea.ps1 -ExecutionPolicy Bypass + value: powershell C:/k/register_antrea_cleanup.ps1 -ExecutionPolicy Bypass - name: ntpServers enabledIf: '{{ not (empty .ntpServers) }}' definitions: