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

Commit 5670be3

Browse files
committed
Register cleanup for antrea and disable secretgen and vsphere-az1/2
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. secretgen does not support Windows cluster, just disable it. Disable vsphere-az1/2 on Windows cluster because this is not tested on Windows clusters.
1 parent 5e6211b commit 5670be3

File tree

12 files changed

+76
-14
lines changed

12 files changed

+76
-14
lines changed

pkg/v1/providers/infrastructure-vsphere/ytt/vsphere-overlay.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
#@ bomDataForK8sVersion = get_bom_data_for_tkr_name()
1313

14-
#@ if data.values.CLUSTER_PLAN == "prod":
14+
#@ if data.values.CLUSTER_PLAN == "prod" and not data.values.IS_WINDOWS_WORKLOAD_CLUSTER:
1515
#@overlay/match by=overlay.subset({"kind":"VSphereCluster"})
1616
---
1717
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1

pkg/v1/providers/tests/unit/windows_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ var _ = Describe("Windows Ytt Templating", func() {
3030
filepath.Join(yamlRoot, "ytt", "02_addons", "cpi", "cpi_addon_data.lib.yaml"),
3131
filepath.Join(yamlRoot, "ytt", "03_customizations", "02_avi", "ako-deployment.lib.yaml"),
3232
//filepath.Join(YAML_ROOT, "provider-bundle", "providers", "ytt", "02_addons", "cpi", "cpi_addon_data.lib.yaml"),
33+
filepath.Join(yamlRoot, "ytt", "03_customizations", "03_windows"),
3334
filepath.Join(yamlRoot, "ytt"), // lib/helpers.star, lib/config_variable_association.star, lib/validate.star
3435
}
3536
})

pkg/v1/providers/ytt/02_addons/secretgen-controller/add_secretgen-controller.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#@ load("/lib/helpers.star", "ValuesFormatStr")
55
#@ load("secretgen-controller_addon_data.lib.yaml", "secretgencontrollerdatavalues")
66

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

pkg/v1/tkg/client/client.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ type CreateClusterOptions struct {
5454
SkipValidation bool
5555
ClusterType TKGClusterType
5656
Edition string
57+
IsWindowsWorkloadCluster bool
5758
}
5859

5960
// InitRegionOptions contains options supported by InitRegion

pkg/v1/tkg/client/client_suite_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1368,7 +1368,7 @@ var _ = Describe("DistributeMachineDeploymentWorkers", func() {
13681368
JustBeforeEach(func() {
13691369
tkgClient, err = CreateTKGClient(tkgConfigPath, testingDir, defaultTKGBoMFileForTesting, 2*time.Second)
13701370
Expect(err).NotTo(HaveOccurred())
1371-
workerCounts, err = tkgClient.DistributeMachineDeploymentWorkers(workerMachineCount, isProdConfig, isManagementCluster, infraProviderName)
1371+
workerCounts, err = tkgClient.DistributeMachineDeploymentWorkers(workerMachineCount, isProdConfig, isManagementCluster, infraProviderName, false)
13721372
})
13731373

13741374
Context("when not aws and azure", func() {

pkg/v1/tkg/client/cluster.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func (c *TkgClient) CreateCluster(options *CreateClusterOptions, waitForCluster
130130
if err != nil {
131131
return err
132132
}
133-
bytes, err = c.getClusterConfiguration(&options.ClusterConfigOptions, isManagementCluster, infraProviderName)
133+
bytes, err = c.getClusterConfiguration(&options.ClusterConfigOptions, isManagementCluster, infraProviderName, options.IsWindowsWorkloadCluster)
134134
if err != nil {
135135
return errors.Wrap(err, "unable to get cluster configuration")
136136
}

pkg/v1/tkg/client/config.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func (c *TkgClient) GetClusterConfiguration(options *CreateClusterOptions) ([]by
4444
if err := c.configureAndValidateConfiguration(options, nil, true); err != nil {
4545
return nil, err
4646
}
47-
return c.getClusterConfiguration(&options.ClusterConfigOptions, false, provider)
47+
return c.getClusterConfiguration(&options.ClusterConfigOptions, false, provider, options.IsWindowsWorkloadCluster)
4848
}
4949
}
5050
currentRegion, err := c.GetCurrentRegionContext()
@@ -87,7 +87,7 @@ func (c *TkgClient) GetClusterConfiguration(options *CreateClusterOptions) ([]by
8787
return nil, err
8888
}
8989

90-
return c.getClusterConfiguration(&options.ClusterConfigOptions, false, infraProviderName)
90+
return c.getClusterConfiguration(&options.ClusterConfigOptions, false, infraProviderName, options.IsWindowsWorkloadCluster)
9191
}
9292

9393
func (c *TkgClient) configureAndValidateConfiguration(options *CreateClusterOptions, regionalClusterClient clusterclient.Client, skipValidation bool) error {
@@ -102,7 +102,7 @@ func (c *TkgClient) configureAndValidateConfiguration(options *CreateClusterOpti
102102
return nil
103103
}
104104

105-
func (c *TkgClient) getClusterConfiguration(options *ClusterConfigOptions, isManagementCluster bool, infraProvider string) ([]byte, error) {
105+
func (c *TkgClient) getClusterConfiguration(options *ClusterConfigOptions, isManagementCluster bool, infraProvider string, isWindowsWorkloadCluster bool) ([]byte, error) {
106106
// Set CLUSTER_PLAN to viper configuration
107107
c.SetPlan(options.ProviderRepositorySource.Flavor)
108108

@@ -112,7 +112,7 @@ func (c *TkgClient) getClusterConfiguration(options *ClusterConfigOptions, isMan
112112
}
113113

114114
// need to provide clusterctl the worker count for md0 and not the full worker-machine-count value.
115-
workerCounts, err := c.DistributeMachineDeploymentWorkers(*options.WorkerMachineCount, options.ProviderRepositorySource.Flavor == constants.PlanProd, isManagementCluster, infraProviderName)
115+
workerCounts, err := c.DistributeMachineDeploymentWorkers(*options.WorkerMachineCount, options.ProviderRepositorySource.Flavor == constants.PlanProd, isManagementCluster, infraProviderName, isWindowsWorkloadCluster)
116116
if err != nil {
117117
return nil, errors.Wrap(err, "failed to distribute machine deployments")
118118
}

pkg/v1/tkg/client/init.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ func (c *TkgClient) BuildRegionalClusterConfiguration(options *InitRegionOptions
574574
clusterConfigOptions.YamlProcessor = yamlprocessor.NewYttProcessorWithConfigDir(c.tkgConfigDir)
575575
}
576576

577-
bytes, err = c.getClusterConfiguration(&clusterConfigOptions, true, clusterConfigOptions.ProviderRepositorySource.InfrastructureProvider)
577+
bytes, err = c.getClusterConfiguration(&clusterConfigOptions, true, clusterConfigOptions.ProviderRepositorySource.InfrastructureProvider, false)
578578

579579
return bytes, options.ClusterName, err
580580
}

0 commit comments

Comments
 (0)