@@ -22,6 +22,7 @@ import (
22
22
"maps"
23
23
"os"
24
24
"path/filepath"
25
+ "time"
25
26
26
27
. "github.com/onsi/ginkgo/v2"
27
28
. "github.com/onsi/gomega"
@@ -70,6 +71,19 @@ type QuickStartSpecInput struct {
70
71
// which unblocks CNI installation, and for the control plane machines to be ready (after CNI installation).
71
72
ControlPlaneWaiters clusterctl.ControlPlaneWaiters
72
73
74
+ // ExtensionConfigName is the name of the ExtensionConfig. Defaults to "quick-start".
75
+ // This value is provided to clusterctl as "EXTENSION_CONFIG_NAME" variable and can be used to template the
76
+ // name of the ExtensionConfig into the ClusterClass.
77
+ ExtensionConfigName string
78
+
79
+ // ExtensionServiceNamespace is the namespace where the service for the Runtime Extension is located.
80
+ // Note: This should only be set if a Runtime Extension is used.
81
+ ExtensionServiceNamespace string
82
+
83
+ // ExtensionServiceNamespace is the name where the service for the Runtime Extension is located.
84
+ // Note: This should only be set if a Runtime Extension is used.
85
+ ExtensionServiceName string
86
+
73
87
// Allows to inject a function to be run after test namespace is created.
74
88
// If not specified, this is a no-op.
75
89
PostNamespaceCreated func (managementClusterProxy framework.ClusterProxy , workloadClusterNamespace string )
@@ -107,6 +121,12 @@ func QuickStartSpec(ctx context.Context, inputGetter func() QuickStartSpecInput)
107
121
108
122
Expect (input .E2EConfig .Variables ).To (HaveKey (KubernetesVersion ))
109
123
124
+ if input .ExtensionServiceNamespace != "" && input .ExtensionServiceName != "" {
125
+ if input .ExtensionConfigName == "" {
126
+ input .ExtensionConfigName = specName
127
+ }
128
+ }
129
+
110
130
// Setup a Namespace where to host objects for this spec and create a watcher for the namespace events.
111
131
namespace , cancelWatches = framework .SetupSpecNamespace (ctx , specName , input .BootstrapClusterProxy , input .ArtifactFolder , input .PostNamespaceCreated )
112
132
@@ -146,7 +166,36 @@ func QuickStartSpec(ctx context.Context, inputGetter func() QuickStartSpecInput)
146
166
clusterName = * input .ClusterName
147
167
}
148
168
149
- variables := map [string ]string {}
169
+ if input .ExtensionServiceNamespace != "" && input .ExtensionServiceName != "" {
170
+ // NOTE: test extension is already deployed in the management cluster. If for any reason in future we want
171
+ // to make this test more self-contained this test should be modified in order to create an additional
172
+ // management cluster; also the E2E test configuration should be modified introducing something like
173
+ // optional:true allowing to define which providers should not be installed by default in
174
+ // a management cluster.
175
+ By ("Deploy Test Extension ExtensionConfig" )
176
+
177
+ // In this test we are defaulting all handlers to non-blocking because we don't expect the handlers to block the
178
+ // cluster lifecycle by default. Setting defaultAllHandlersToBlocking to false enforces that the test-extension
179
+ // automatically creates the ConfigMap with non-blocking preloaded responses.
180
+ defaultAllHandlersToBlocking := false
181
+ // select on the current namespace
182
+ // This is necessary so in CI this test doesn't influence other tests by enabling lifecycle hooks
183
+ // in other test namespaces.
184
+ namespaces := []string {namespace .Name }
185
+ if input .DeployClusterClassInSeparateNamespace {
186
+ // Add the ClusterClass namespace, if the ClusterClass is deployed in a separate namespace.
187
+ namespaces = append (namespaces , clusterClassNamespace .Name )
188
+ }
189
+ extensionConfig := extensionConfig (input .ExtensionConfigName , input .ExtensionServiceNamespace , input .ExtensionServiceName , defaultAllHandlersToBlocking , namespaces ... )
190
+ Expect (input .BootstrapClusterProxy .GetClient ().Create (ctx ,
191
+ extensionConfig )).
192
+ To (Succeed (), "Failed to create the ExtensionConfig" )
193
+ }
194
+
195
+ variables := map [string ]string {
196
+ // This is used to template the name of the ExtensionConfig into the ClusterClass.
197
+ "EXTENSION_CONFIG_NAME" : input .ExtensionConfigName ,
198
+ }
150
199
maps .Copy (variables , input .ClusterctlVariables )
151
200
152
201
if input .DeployClusterClassInSeparateNamespace {
@@ -200,11 +249,18 @@ func QuickStartSpec(ctx context.Context, inputGetter func() QuickStartSpecInput)
200
249
AfterEach (func () {
201
250
// Dumps all the resources in the spec namespace, then cleanups the cluster object and the spec namespace itself.
202
251
framework .DumpSpecResourcesAndCleanup (ctx , specName , input .BootstrapClusterProxy , input .ClusterctlConfigPath , input .ArtifactFolder , namespace , cancelWatches , clusterResources .Cluster , input .E2EConfig .GetIntervals , input .SkipCleanup )
203
- if input .DeployClusterClassInSeparateNamespace && ! input .SkipCleanup {
204
- framework .DeleteNamespace (ctx , framework.DeleteNamespaceInput {
205
- Deleter : input .BootstrapClusterProxy .GetClient (),
206
- Name : clusterClassNamespace .Name ,
207
- })
252
+ if ! input .SkipCleanup {
253
+ if input .ExtensionServiceNamespace != "" && input .ExtensionServiceName != "" {
254
+ Eventually (func () error {
255
+ return input .BootstrapClusterProxy .GetClient ().Delete (ctx , extensionConfig (input .ExtensionConfigName , input .ExtensionServiceNamespace , input .ExtensionServiceName , true ))
256
+ }, 10 * time .Second , 1 * time .Second ).Should (Succeed (), "Deleting ExtensionConfig failed" )
257
+ }
258
+ if input .DeployClusterClassInSeparateNamespace {
259
+ framework .DeleteNamespace (ctx , framework.DeleteNamespaceInput {
260
+ Deleter : input .BootstrapClusterProxy .GetClient (),
261
+ Name : clusterClassNamespace .Name ,
262
+ })
263
+ }
208
264
}
209
265
})
210
266
}
0 commit comments