@@ -2,21 +2,11 @@ package frmwrk
22
33import (
44 "context"
5- "fmt"
6- corev1 "k8s.io/api/core/v1"
7- "k8s.io/utils/ptr"
8- "os"
9- "path"
10- "path/filepath"
11-
125 . "github.com/onsi/ginkgo/v2" //nolint:staticcheck
136 . "github.com/onsi/gomega" //nolint:staticcheck
147
158 "sigs.k8s.io/cluster-api/test/framework"
169 "sigs.k8s.io/cluster-api/test/framework/clusterctl"
17- "sigs.k8s.io/cluster-api/util"
18-
19- "github.com/drone/envsubst/v2"
2010)
2111
2212type ClusterUpgradeSpecInput struct {
@@ -82,174 +72,3 @@ func createE2ECluster(ctx context.Context, e2eCtx *E2EContext, cfg ClusterConfig
8272
8373 return ec
8474}
85-
86- // Reference: https://github.com/kubernetes-sigs/cluster-api/blob/76697d5bf2a746aa1bf942c88170692666bfcc5c/test/e2e/cluster_upgrade.go#L37
87- func clusterUpgrade (ctx context.Context , e2eCtx * E2EContext , inputGetter func () ClusterUpgradeSpecInput ) {
88-
89- var (
90- specName = "cluster-upgrade"
91- input ClusterUpgradeSpecInput
92- namespace * corev1.Namespace
93- //cancelWatches context.CancelFunc
94-
95- KubernetesVersionUpgradeFrom = "KUBERNETES_VERSION_UPGRADE_FROM"
96- KubernetesVersionUpgradeTo = "KUBERNETES_VERSION_UPGRADE_TO"
97- CPMachineTemplateUpgradeTo = "CONTROL_PLANE_MACHINE_TEMPLATE_UPGRADE_TO"
98- WorkersMachineTemplateUpgradeTo = "WORKERS_MACHINE_TEMPLATE_UPGRADE_TO"
99-
100- controlPlaneMachineCount int64
101- workerMachineCount int64
102-
103- clusterResources * clusterctl.ApplyClusterTemplateAndWaitResult
104-
105- clusterName string
106- )
107-
108- ec := e2eCtx .NewE2ECluster (ClusterConfig {
109- SpecName : specName ,
110- NamespaceName : "cluster-upgrade" ,
111- ClusterName : "e2e-upgrade" ,
112- })
113- ec .SetupMetalStackPreconditions (ctx )
114- //ec.SetupNamespace(ctx)
115-
116- BeforeEach (func () {
117- Expect (ctx ).NotTo (BeNil (), "ctx is required for %s spec" , specName )
118- input = inputGetter ()
119- Expect (input .E2EConfig ).ToNot (BeNil (), "Invalid argument. input.E2EConfig can't be nil when calling %s spec" , specName )
120- Expect (input .ClusterctlConfigPath ).To (BeAnExistingFile (), "Invalid argument. input.ClusterctlConfigPath must be an existing file when calling %s spec" , specName )
121- Expect (input .BootstrapClusterProxy ).ToNot (BeNil (), "Invalid argument. input.BootstrapClusterProxy can't be nil when calling %s spec" , specName )
122- Expect (os .MkdirAll (input .ArtifactFolder , 0750 )).To (Succeed (), "Invalid argument. input.ArtifactFolder can't be created for %s spec" , specName )
123-
124- Expect (input .E2EConfig .Variables ).To (HaveKey (KubernetesVersionUpgradeFrom ))
125- Expect (input .E2EConfig .Variables ).To (HaveKey (KubernetesVersionUpgradeTo ))
126-
127- if input .ControlPlaneMachineCount == nil {
128- controlPlaneMachineCount = 1
129- } else {
130- controlPlaneMachineCount = * input .ControlPlaneMachineCount
131- }
132-
133- if input .WorkerMachineCount == nil {
134- workerMachineCount = 2
135- } else {
136- workerMachineCount = * input .WorkerMachineCount
137- }
138-
139- clusterResources = new (clusterctl.ApplyClusterTemplateAndWaitResult )
140- })
141-
142- It ("Should create and upgrade a workload cluster" , func () {
143- By ("Creating a workload cluster" )
144-
145- infrastructureProvider := clusterctl .DefaultInfrastructureProvider
146- if input .InfrastructureProvider != nil {
147- infrastructureProvider = * input .InfrastructureProvider
148- }
149-
150- clusterName = fmt .Sprintf ("%s-%s" , specName , util .RandomString (6 ))
151-
152- clusterctl .ApplyClusterTemplateAndWait (ctx , clusterctl.ApplyClusterTemplateAndWaitInput {
153- ClusterProxy : input .BootstrapClusterProxy ,
154- ConfigCluster : clusterctl.ConfigClusterInput {
155- LogFolder : filepath .Join (input .ArtifactFolder , "clusters" , input .BootstrapClusterProxy .GetName ()),
156- ClusterctlConfigPath : input .ClusterctlConfigPath ,
157- KubeconfigPath : input .BootstrapClusterProxy .GetKubeconfigPath (),
158- InfrastructureProvider : infrastructureProvider ,
159- Namespace : namespace .Name ,
160- ClusterName : clusterName ,
161- KubernetesVersion : input .E2EConfig .MustGetVariable (KubernetesVersionUpgradeFrom ),
162- ControlPlaneMachineCount : ptr.To [int64 ](controlPlaneMachineCount ),
163- WorkerMachineCount : ptr.To [int64 ](workerMachineCount ),
164- },
165- ControlPlaneWaiters : input .ControlPlaneWaiters ,
166- WaitForClusterIntervals : input .E2EConfig .GetIntervals (specName , "wait-cluster" ),
167- WaitForControlPlaneIntervals : input .E2EConfig .GetIntervals (specName , "wait-control-plane" ),
168- WaitForMachineDeployments : input .E2EConfig .GetIntervals (specName , "wait-worker-nodes" ),
169- WaitForMachinePools : input .E2EConfig .GetIntervals (specName , "wait-machine-pool-nodes" ),
170- }, clusterResources )
171-
172- By ("Wait for CNI and CCM" )
173- targetTemplate , err := os .ReadFile (path .Join (e2eCtx .Environment .artifactsPath , "config" , "target" , "base.yaml" ))
174- Expect (err ).ToNot (HaveOccurred ())
175-
176- vars := ec .Variables ()
177- targetResources , err := envsubst .Eval (string (targetTemplate ), func (varName string ) string {
178- return vars [varName ]
179- })
180- Expect (err ).ToNot (HaveOccurred ())
181-
182- Eventually (func () error {
183- return ec .Refs .Workload .CreateOrUpdate (ctx , []byte (targetResources ))
184- }, "10m" , "15s" ).Should (Succeed ()) // currently this long delay is required as machines might not be ready yet
185-
186- By ("Upgrading the Kubernetes control-plane" )
187- var (
188- upgradeCPMachineTemplateTo * string
189- upgradeWorkersMachineTemplateTo * string
190- )
191-
192- if input .E2EConfig .HasVariable (CPMachineTemplateUpgradeTo ) {
193- upgradeCPMachineTemplateTo = ptr .To (input .E2EConfig .MustGetVariable (CPMachineTemplateUpgradeTo ))
194- }
195-
196- if input .E2EConfig .HasVariable (WorkersMachineTemplateUpgradeTo ) {
197- upgradeWorkersMachineTemplateTo = ptr .To (input .E2EConfig .MustGetVariable (WorkersMachineTemplateUpgradeTo ))
198- }
199-
200- framework .UpgradeControlPlaneAndWaitForUpgrade (ctx , framework.UpgradeControlPlaneAndWaitForUpgradeInput {
201- ClusterProxy : input .BootstrapClusterProxy ,
202- Cluster : clusterResources .Cluster ,
203- ControlPlane : clusterResources .ControlPlane ,
204- EtcdImageTag : "" ,
205- DNSImageTag : "" ,
206- KubernetesUpgradeVersion : input .E2EConfig .MustGetVariable (KubernetesVersionUpgradeTo ),
207- UpgradeMachineTemplate : upgradeCPMachineTemplateTo ,
208- WaitForMachinesToBeUpgraded : input .E2EConfig .GetIntervals (specName , "wait-machine-upgrade" ),
209- WaitForKubeProxyUpgrade : input .E2EConfig .GetIntervals (specName , "wait-machine-upgrade" ),
210- WaitForDNSUpgrade : input .E2EConfig .GetIntervals (specName , "wait-machine-upgrade" ),
211- WaitForEtcdUpgrade : input .E2EConfig .GetIntervals (specName , "wait-machine-upgrade" ),
212- PreWaitForControlPlaneToBeUpgraded : func () {},
213- })
214-
215- if workerMachineCount > 0 {
216- By ("Upgrading the machine deployment" )
217- framework .UpgradeMachineDeploymentsAndWait (ctx , framework.UpgradeMachineDeploymentsAndWaitInput {
218- ClusterProxy : input .BootstrapClusterProxy ,
219- Cluster : clusterResources .Cluster ,
220- UpgradeVersion : input .E2EConfig .MustGetVariable (KubernetesVersionUpgradeTo ),
221- UpgradeMachineTemplate : upgradeWorkersMachineTemplateTo ,
222- MachineDeployments : clusterResources .MachineDeployments ,
223- WaitForMachinesToBeUpgraded : input .E2EConfig .GetIntervals (specName , "wait-worker-nodes" ),
224- })
225-
226- if len (clusterResources .MachinePools ) > 0 {
227- By ("Upgrading the machinepool instances" )
228- framework .UpgradeMachinePoolAndWait (ctx , framework.UpgradeMachinePoolAndWaitInput {
229- ClusterProxy : input .BootstrapClusterProxy ,
230- Cluster : clusterResources .Cluster ,
231- UpgradeVersion : input .E2EConfig .MustGetVariable (KubernetesVersionUpgradeTo ),
232- WaitForMachinePoolToBeUpgraded : input .E2EConfig .GetIntervals (specName , "wait-machine-pool-upgrade" ),
233- MachinePools : clusterResources .MachinePools ,
234- })
235- }
236- }
237-
238- By ("Waiting until nodes are ready" )
239- workloadProxy := input .BootstrapClusterProxy .GetWorkloadCluster (ctx , namespace .Name , clusterResources .Cluster .Name )
240- workloadClient := workloadProxy .GetClient ()
241- framework .WaitForNodesReady (ctx , framework.WaitForNodesReadyInput {
242- Lister : workloadClient ,
243- KubernetesVersion : input .E2EConfig .MustGetVariable (KubernetesVersionUpgradeTo ),
244- Count : int (clusterResources .ExpectedTotalNodes ()),
245- WaitForNodesReady : input .E2EConfig .GetIntervals (specName , "wait-nodes-ready" ),
246- })
247-
248- By ("PASSED!" )
249- })
250-
251- //AfterEach(func() {
252- // // Dumps all the resources in the spec Namespace, then cleanups the cluster object and the spec Namespace itself.
253- // framework.DumpSpecResourcesAndCleanup(ctx, specName, input.BootstrapClusterProxy, input.ClusterctlConfigPath, input.ArtifactFolder, namespace, cancelWatches, clusterResources.Cluster, input.E2EConfig.GetIntervals, input.SkipCleanup)
254- //})
255- }
0 commit comments