@@ -42,8 +42,10 @@ import (
4242)
4343
4444var (
45+ ctx = ctrl .SetupSignalHandler ()
46+
4547 // watchesCtx is used in log streaming to be able to get canceled via cancelWatches after ending the test suite.
46- watchesCtx , cancelWatches = context .WithCancel (context . Background () )
48+ watchesCtx , cancelWatches = context .WithCancel (ctx )
4749)
4850
4951func init () {
@@ -73,16 +75,16 @@ var _ = SynchronizedBeforeSuite(func() []byte {
7375 Expect (os .MkdirAll (artifactFolder , 0o755 )).To (Succeed (), "Invalid test suite argument. Can't create e2e.artifacts-folder %q" , artifactFolder )
7476
7577 Byf ("Loading the e2e test configuration from %q" , configPath )
76- e2eConfig = loadE2EConfig (configPath )
78+ e2eConfig = loadE2EConfig (ctx , configPath )
7779
7880 Byf ("Creating a clusterctl local repository into %q" , artifactFolder )
79- clusterctlConfigPath = createClusterctlLocalRepository (e2eConfig , filepath .Join (artifactFolder , "repository" ))
81+ clusterctlConfigPath = createClusterctlLocalRepository (ctx , e2eConfig , filepath .Join (artifactFolder , "repository" ))
8082
8183 By ("Setting up the bootstrap cluster" )
82- bootstrapClusterProvider , bootstrapClusterProxy = setupBootstrapCluster (e2eConfig , useExistingCluster )
84+ bootstrapClusterProvider , bootstrapClusterProxy = setupBootstrapCluster (ctx , e2eConfig , useExistingCluster )
8385
8486 By ("Initializing the bootstrap cluster" )
85- initBootstrapCluster (bootstrapClusterProxy , e2eConfig , clusterctlConfigPath , artifactFolder )
87+ initBootstrapCluster (watchesCtx , bootstrapClusterProxy , e2eConfig , clusterctlConfigPath , artifactFolder )
8688
8789 // encode the e2e config into the byte array.
8890 var configBuf bytes.Buffer
@@ -133,20 +135,20 @@ var _ = SynchronizedAfterSuite(func() {
133135
134136 By ("Tearing down the management cluster" )
135137 if ! skipCleanup {
136- tearDown (bootstrapClusterProvider , bootstrapClusterProxy )
138+ tearDown (ctx , bootstrapClusterProvider , bootstrapClusterProxy )
137139 }
138140})
139141
140- func loadE2EConfig (configPath string ) * clusterctl.E2EConfig {
141- config := clusterctl .LoadE2EConfig (context . TODO () , clusterctl.LoadE2EConfigInput {ConfigPath : configPath })
142+ func loadE2EConfig (ctx context. Context , configPath string ) * clusterctl.E2EConfig {
143+ config := clusterctl .LoadE2EConfig (ctx , clusterctl.LoadE2EConfigInput {ConfigPath : configPath })
142144 Expect (config ).NotTo (BeNil (), "Failed to load E2E config from %s" , configPath )
143145
144146 resolveKubernetesVersions (ctx , config )
145147
146148 return config
147149}
148150
149- func createClusterctlLocalRepository (config * clusterctl.E2EConfig , repositoryFolder string ) string {
151+ func createClusterctlLocalRepository (ctx context. Context , config * clusterctl.E2EConfig , repositoryFolder string ) string {
150152 createRepositoryInput := clusterctl.CreateRepositoryInput {
151153 E2EConfig : config ,
152154 RepositoryFolder : repositoryFolder ,
@@ -158,16 +160,16 @@ func createClusterctlLocalRepository(config *clusterctl.E2EConfig, repositoryFol
158160 Expect (cniPath ).To (BeAnExistingFile (), "The %s variable should resolve to an existing file" , capi_e2e .CNIPath )
159161 createRepositoryInput .RegisterClusterResourceSetConfigMapTransformation (cniPath , capi_e2e .CNIResources )
160162
161- clusterctlConfig := clusterctl .CreateRepository (context . TODO () , createRepositoryInput )
163+ clusterctlConfig := clusterctl .CreateRepository (ctx , createRepositoryInput )
162164 Expect (clusterctlConfig ).To (BeAnExistingFile (), "The clusterctl config file does not exists in the local repository %s" , repositoryFolder )
163165 return clusterctlConfig
164166}
165167
166- func setupBootstrapCluster (config * clusterctl.E2EConfig , useExistingCluster bool ) (bootstrap.ClusterProvider , framework.ClusterProxy ) {
168+ func setupBootstrapCluster (ctx context. Context , config * clusterctl.E2EConfig , useExistingCluster bool ) (bootstrap.ClusterProvider , framework.ClusterProxy ) {
167169 var clusterProvider bootstrap.ClusterProvider
168170 kubeconfigPath := ""
169171 if ! useExistingCluster {
170- clusterProvider = bootstrap .CreateKindBootstrapClusterAndLoadImages (context . TODO () , bootstrap.CreateKindBootstrapClusterAndLoadImagesInput {
172+ clusterProvider = bootstrap .CreateKindBootstrapClusterAndLoadImages (ctx , bootstrap.CreateKindBootstrapClusterAndLoadImagesInput {
171173 Name : config .ManagementClusterName ,
172174 RequiresDockerSock : config .HasDockerProvider (),
173175 Images : config .Images ,
@@ -184,16 +186,16 @@ func setupBootstrapCluster(config *clusterctl.E2EConfig, useExistingCluster bool
184186 Name : "capz-e2e" ,
185187 Images : config .Images ,
186188 }
187- err := bootstrap .LoadImagesToKindCluster (context . TODO () , imagesInput )
189+ err := bootstrap .LoadImagesToKindCluster (ctx , imagesInput )
188190 Expect (err ).NotTo (HaveOccurred (), "Failed to load images to the bootstrap cluster: %s" , err )
189191 }
190192 clusterProxy := NewAzureClusterProxy ("bootstrap" , kubeconfigPath )
191193 Expect (clusterProxy ).NotTo (BeNil (), "Failed to get a bootstrap cluster proxy" )
192194 return clusterProvider , clusterProxy
193195}
194196
195- func initBootstrapCluster (bootstrapClusterProxy framework.ClusterProxy , config * clusterctl.E2EConfig , clusterctlConfig , artifactFolder string ) {
196- clusterctl .InitManagementClusterAndWatchControllerLogs (watchesCtx , clusterctl.InitManagementClusterAndWatchControllerLogsInput {
197+ func initBootstrapCluster (ctx context. Context , bootstrapClusterProxy framework.ClusterProxy , config * clusterctl.E2EConfig , clusterctlConfig , artifactFolder string ) {
198+ clusterctl .InitManagementClusterAndWatchControllerLogs (ctx , clusterctl.InitManagementClusterAndWatchControllerLogsInput {
197199 ClusterProxy : bootstrapClusterProxy ,
198200 ClusterctlConfigPath : clusterctlConfig ,
199201 InfrastructureProviders : config .InfrastructureProviders (),
@@ -202,12 +204,12 @@ func initBootstrapCluster(bootstrapClusterProxy framework.ClusterProxy, config *
202204 }, config .GetIntervals (bootstrapClusterProxy .GetName (), "wait-controllers" )... )
203205}
204206
205- func tearDown (bootstrapClusterProvider bootstrap.ClusterProvider , bootstrapClusterProxy framework.ClusterProxy ) {
207+ func tearDown (ctx context. Context , bootstrapClusterProvider bootstrap.ClusterProvider , bootstrapClusterProxy framework.ClusterProxy ) {
206208 cancelWatches ()
207209 if bootstrapClusterProxy != nil {
208- bootstrapClusterProxy .Dispose (context . TODO () )
210+ bootstrapClusterProxy .Dispose (ctx )
209211 }
210212 if bootstrapClusterProvider != nil {
211- bootstrapClusterProvider .Dispose (context . TODO () )
213+ bootstrapClusterProvider .Dispose (ctx )
212214 }
213215}
0 commit comments