@@ -42,8 +42,10 @@ import (
42
42
)
43
43
44
44
var (
45
+ ctx = ctrl .SetupSignalHandler ()
46
+
45
47
// 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 )
47
49
)
48
50
49
51
func init () {
@@ -73,16 +75,16 @@ var _ = SynchronizedBeforeSuite(func() []byte {
73
75
Expect (os .MkdirAll (artifactFolder , 0o755 )).To (Succeed (), "Invalid test suite argument. Can't create e2e.artifacts-folder %q" , artifactFolder )
74
76
75
77
Byf ("Loading the e2e test configuration from %q" , configPath )
76
- e2eConfig = loadE2EConfig (configPath )
78
+ e2eConfig = loadE2EConfig (ctx , configPath )
77
79
78
80
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" ))
80
82
81
83
By ("Setting up the bootstrap cluster" )
82
- bootstrapClusterProvider , bootstrapClusterProxy = setupBootstrapCluster (e2eConfig , useExistingCluster )
84
+ bootstrapClusterProvider , bootstrapClusterProxy = setupBootstrapCluster (ctx , e2eConfig , useExistingCluster )
83
85
84
86
By ("Initializing the bootstrap cluster" )
85
- initBootstrapCluster (bootstrapClusterProxy , e2eConfig , clusterctlConfigPath , artifactFolder )
87
+ initBootstrapCluster (watchesCtx , bootstrapClusterProxy , e2eConfig , clusterctlConfigPath , artifactFolder )
86
88
87
89
// encode the e2e config into the byte array.
88
90
var configBuf bytes.Buffer
@@ -133,20 +135,20 @@ var _ = SynchronizedAfterSuite(func() {
133
135
134
136
By ("Tearing down the management cluster" )
135
137
if ! skipCleanup {
136
- tearDown (bootstrapClusterProvider , bootstrapClusterProxy )
138
+ tearDown (ctx , bootstrapClusterProvider , bootstrapClusterProxy )
137
139
}
138
140
})
139
141
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 })
142
144
Expect (config ).NotTo (BeNil (), "Failed to load E2E config from %s" , configPath )
143
145
144
146
resolveKubernetesVersions (ctx , config )
145
147
146
148
return config
147
149
}
148
150
149
- func createClusterctlLocalRepository (config * clusterctl.E2EConfig , repositoryFolder string ) string {
151
+ func createClusterctlLocalRepository (ctx context. Context , config * clusterctl.E2EConfig , repositoryFolder string ) string {
150
152
createRepositoryInput := clusterctl.CreateRepositoryInput {
151
153
E2EConfig : config ,
152
154
RepositoryFolder : repositoryFolder ,
@@ -158,16 +160,16 @@ func createClusterctlLocalRepository(config *clusterctl.E2EConfig, repositoryFol
158
160
Expect (cniPath ).To (BeAnExistingFile (), "The %s variable should resolve to an existing file" , capi_e2e .CNIPath )
159
161
createRepositoryInput .RegisterClusterResourceSetConfigMapTransformation (cniPath , capi_e2e .CNIResources )
160
162
161
- clusterctlConfig := clusterctl .CreateRepository (context . TODO () , createRepositoryInput )
163
+ clusterctlConfig := clusterctl .CreateRepository (ctx , createRepositoryInput )
162
164
Expect (clusterctlConfig ).To (BeAnExistingFile (), "The clusterctl config file does not exists in the local repository %s" , repositoryFolder )
163
165
return clusterctlConfig
164
166
}
165
167
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 ) {
167
169
var clusterProvider bootstrap.ClusterProvider
168
170
kubeconfigPath := ""
169
171
if ! useExistingCluster {
170
- clusterProvider = bootstrap .CreateKindBootstrapClusterAndLoadImages (context . TODO () , bootstrap.CreateKindBootstrapClusterAndLoadImagesInput {
172
+ clusterProvider = bootstrap .CreateKindBootstrapClusterAndLoadImages (ctx , bootstrap.CreateKindBootstrapClusterAndLoadImagesInput {
171
173
Name : config .ManagementClusterName ,
172
174
RequiresDockerSock : config .HasDockerProvider (),
173
175
Images : config .Images ,
@@ -184,16 +186,16 @@ func setupBootstrapCluster(config *clusterctl.E2EConfig, useExistingCluster bool
184
186
Name : "capz-e2e" ,
185
187
Images : config .Images ,
186
188
}
187
- err := bootstrap .LoadImagesToKindCluster (context . TODO () , imagesInput )
189
+ err := bootstrap .LoadImagesToKindCluster (ctx , imagesInput )
188
190
Expect (err ).NotTo (HaveOccurred (), "Failed to load images to the bootstrap cluster: %s" , err )
189
191
}
190
192
clusterProxy := NewAzureClusterProxy ("bootstrap" , kubeconfigPath )
191
193
Expect (clusterProxy ).NotTo (BeNil (), "Failed to get a bootstrap cluster proxy" )
192
194
return clusterProvider , clusterProxy
193
195
}
194
196
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 {
197
199
ClusterProxy : bootstrapClusterProxy ,
198
200
ClusterctlConfigPath : clusterctlConfig ,
199
201
InfrastructureProviders : config .InfrastructureProviders (),
@@ -202,12 +204,12 @@ func initBootstrapCluster(bootstrapClusterProxy framework.ClusterProxy, config *
202
204
}, config .GetIntervals (bootstrapClusterProxy .GetName (), "wait-controllers" )... )
203
205
}
204
206
205
- func tearDown (bootstrapClusterProvider bootstrap.ClusterProvider , bootstrapClusterProxy framework.ClusterProxy ) {
207
+ func tearDown (ctx context. Context , bootstrapClusterProvider bootstrap.ClusterProvider , bootstrapClusterProxy framework.ClusterProxy ) {
206
208
cancelWatches ()
207
209
if bootstrapClusterProxy != nil {
208
- bootstrapClusterProxy .Dispose (context . TODO () )
210
+ bootstrapClusterProxy .Dispose (ctx )
209
211
}
210
212
if bootstrapClusterProvider != nil {
211
- bootstrapClusterProvider .Dispose (context . TODO () )
213
+ bootstrapClusterProvider .Dispose (ctx )
212
214
}
213
215
}
0 commit comments