@@ -30,51 +30,53 @@ func IPReuse(ctx context.Context, inputGetter func() IPReuseInput) {
3030 targetClusterClient := input .TargetCluster .GetClient ()
3131 managementClusterClient := input .BootstrapClusterProxy .GetClient ()
3232 fromK8sVersion := input .E2EConfig .GetVariable ("FROM_K8S_VERSION" )
33- kubernetesVersion := input .E2EConfig .GetVariable ("KUBERNETES_VERSION" )
33+ toK8sVersion := input .E2EConfig .GetVariable ("KUBERNETES_VERSION" )
34+ numberOfControlplane := * input .E2EConfig .GetInt32PtrVariable ("CONTROL_PLANE_MACHINE_COUNT" )
35+ numberOfWorkers := * input .E2EConfig .GetInt32PtrVariable ("WORKER_MACHINE_COUNT" )
36+ numberOfAllBmh := numberOfControlplane + numberOfWorkers
3437
35- // scale down KCP to 1
36- By ("Scale the controlplane down to 1" )
37- ScaleKubeadmControlPlane (ctx , managementClusterClient , client.ObjectKey {Namespace : input .Namespace , Name : input .ClusterName }, 1 )
38- Byf ("Wait until controlplane is scaled down and %d BMHs are Available" , 2 )
39- WaitForNumBmhInState (ctx , bmov1alpha1 .StateAvailable , WaitForNumInput {
38+ // Download node image
39+ Byf ("Download image %s" , toK8sVersion )
40+ imageURL , imageChecksum := EnsureImage (toK8sVersion )
41+
42+ // Upgrade KCP
43+ By ("Create new KCP Metal3MachineTemplate with upgraded image to boot" )
44+ KCPm3MachineTemplateName := fmt .Sprintf ("%s-controlplane" , input .ClusterName )
45+ KCPNewM3MachineTemplateName := fmt .Sprintf ("%s-new-controlplane" , input .ClusterName )
46+ CreateNewM3MachineTemplate (ctx , input .Namespace , KCPNewM3MachineTemplateName , KCPm3MachineTemplateName , managementClusterClient , imageURL , imageChecksum )
47+
48+ Byf ("Update KCP to upgrade k8s version and binaries from %s to %s" , fromK8sVersion , toK8sVersion )
49+ kcpObj := framework .GetKubeadmControlPlaneByCluster (ctx , framework.GetKubeadmControlPlaneByClusterInput {
50+ Lister : managementClusterClient ,
51+ ClusterName : input .ClusterName ,
52+ Namespace : input .Namespace ,
53+ })
54+ helper , err := patch .NewHelper (kcpObj , managementClusterClient )
55+ Expect (err ).NotTo (HaveOccurred ())
56+ kcpObj .Spec .MachineTemplate .InfrastructureRef .Name = KCPNewM3MachineTemplateName
57+ kcpObj .Spec .Version = toK8sVersion
58+ kcpObj .Spec .RolloutStrategy .RollingUpdate .MaxSurge .IntVal = 0
59+
60+ Expect (helper .Patch (ctx , kcpObj )).To (Succeed ())
61+
62+ Byf ("Wait until %d Control Plane machines become running and updated with the new %s k8s version" , numberOfControlplane , toK8sVersion )
63+ runningAndUpgraded := func (machine clusterv1.Machine ) bool {
64+ running := machine .Status .GetTypedPhase () == clusterv1 .MachinePhaseRunning
65+ upgraded := * machine .Spec .Version == toK8sVersion
66+ return (running && upgraded )
67+ }
68+ WaitForNumMachines (ctx , runningAndUpgraded , WaitForNumInput {
4069 Client : managementClusterClient ,
4170 Options : []client.ListOption {client .InNamespace (input .Namespace )},
42- Replicas : 2 ,
43- Intervals : input .E2EConfig .GetIntervals (input .SpecName , "wait-cp-available " ),
71+ Replicas : int ( numberOfControlplane ) ,
72+ Intervals : input .E2EConfig .GetIntervals (input .Namespace , "wait-machine-running " ),
4473 })
4574
4675 ListBareMetalHosts (ctx , managementClusterClient , client .InNamespace (input .Namespace ))
4776 ListMetal3Machines (ctx , managementClusterClient , client .InNamespace (input .Namespace ))
4877 ListMachines (ctx , managementClusterClient , client .InNamespace (input .Namespace ))
4978 ListNodes (ctx , targetClusterClient )
5079
51- // scale up MD to 3
52- By ("Scale the worker up to 3" )
53- ScaleMachineDeployment (ctx , managementClusterClient , input .ClusterName , input .Namespace , 3 )
54- By ("Waiting for one BMH to become provisioning" )
55- WaitForNumBmhInState (ctx , bmov1alpha1 .StateProvisioning , WaitForNumInput {
56- Client : managementClusterClient ,
57- Options : []client.ListOption {client .InNamespace (input .Namespace )},
58- Replicas : 2 ,
59- Intervals : input .E2EConfig .GetIntervals (input .SpecName , "wait-machine-remediation" ),
60- })
61-
62- By ("Waiting for all BMHs to become provisioned" )
63- WaitForNumBmhInState (ctx , bmov1alpha1 .StateProvisioned , WaitForNumInput {
64- Client : managementClusterClient ,
65- Options : []client.ListOption {client .InNamespace (input .Namespace )},
66- Replicas : 4 ,
67- Intervals : input .E2EConfig .GetIntervals (input .SpecName , "wait-machine-remediation" ),
68- })
69-
70- By ("Waiting for all Machines to be Running" )
71- WaitForNumMachinesInState (ctx , clusterv1 .MachinePhaseRunning , WaitForNumInput {
72- Client : managementClusterClient ,
73- Options : []client.ListOption {client .InNamespace (input .Namespace )},
74- Replicas : 4 ,
75- Intervals : input .E2EConfig .GetIntervals (input .SpecName , "wait-machine-remediation" ),
76- })
77-
7880 By ("Get the IPPools in the cluster" )
7981 baremetalv4Pool , provisioningPool := GetIPPools (ctx , managementClusterClient , input .ClusterName , input .Namespace )
8082 Expect (baremetalv4Pool ).To (HaveLen (1 ))
@@ -115,29 +117,25 @@ func IPReuse(ctx context.Context, inputGetter func() IPReuseInput) {
115117 Expect (machineDeployments ).To (HaveLen (1 ), "Expected exactly 1 MachineDeployment" )
116118 md := machineDeployments [0 ]
117119
118- // Download node image
119- Byf ("Download image %s" , kubernetesVersion )
120- imageURL , imageChecksum := EnsureImage (kubernetesVersion )
121-
122120 By ("Create new worker Metal3MachineTemplate with upgraded image to boot" )
123121 m3MachineTemplateName := md .Spec .Template .Spec .InfrastructureRef .Name
124122 newM3MachineTemplateName := fmt .Sprintf ("%s-new" , m3MachineTemplateName )
125123 CreateNewM3MachineTemplate (ctx , input .Namespace , newM3MachineTemplateName , m3MachineTemplateName , managementClusterClient , imageURL , imageChecksum )
126124
127- Byf ("Update MachineDeployment maxUnavailable to number of workers and k8s version from %s to %s" , fromK8sVersion , kubernetesVersion )
128- helper , err : = patch .NewHelper (md , managementClusterClient )
125+ Byf ("Update MachineDeployment maxUnavailable to number of workers and k8s version from %s to %s" , fromK8sVersion , toK8sVersion )
126+ helper , err = patch .NewHelper (md , managementClusterClient )
129127 Expect (err ).NotTo (HaveOccurred ())
130128 md .Spec .Template .Spec .InfrastructureRef .Name = newM3MachineTemplateName
131- md .Spec .Template .Spec .Version = & kubernetesVersion
129+ md .Spec .Template .Spec .Version = & toK8sVersion
132130 md .Spec .Strategy .RollingUpdate .MaxSurge .IntVal = 0
133- md .Spec .Strategy .RollingUpdate .MaxUnavailable .IntVal = 3
131+ md .Spec .Strategy .RollingUpdate .MaxUnavailable .IntVal = numberOfWorkers
134132 Expect (helper .Patch (ctx , md )).To (Succeed ())
135133
136- Byf ("Wait until %d BMH(s) in deprovisioning state" , 3 )
134+ Byf ("Wait until %d BMH(s) in deprovisioning state" , numberOfWorkers )
137135 WaitForNumBmhInState (ctx , bmov1alpha1 .StateDeprovisioning , WaitForNumInput {
138136 Client : managementClusterClient ,
139137 Options : []client.ListOption {client .InNamespace (input .Namespace )},
140- Replicas : 3 ,
138+ Replicas : int ( numberOfWorkers ) ,
141139 Intervals : input .E2EConfig .GetIntervals (input .SpecName , "wait-bmh-deprovisioning" ),
142140 })
143141
@@ -146,11 +144,11 @@ func IPReuse(ctx context.Context, inputGetter func() IPReuseInput) {
146144 ListMachines (ctx , managementClusterClient , client .InNamespace (input .Namespace ))
147145 ListNodes (ctx , targetClusterClient )
148146
149- Byf ("Wait until all %d machine(s) become(s) running" , 4 )
147+ Byf ("Wait until all %d machine(s) become(s) running" , numberOfAllBmh )
150148 WaitForNumMachinesInState (ctx , clusterv1 .MachinePhaseRunning , WaitForNumInput {
151149 Client : managementClusterClient ,
152150 Options : []client.ListOption {client .InNamespace (input .Namespace )},
153- Replicas : 4 ,
151+ Replicas : int ( numberOfAllBmh ) ,
154152 Intervals : input .E2EConfig .GetIntervals (input .SpecName , "wait-machine-running" ),
155153 })
156154
0 commit comments