@@ -60,8 +60,8 @@ const (
60
60
scaleClusterNamespacePlaceholder = "scale-cluster-namespace-placeholder"
61
61
)
62
62
63
- // scaleSpecInput is the input for scaleSpec .
64
- type scaleSpecInput struct {
63
+ // ScaleSpecInput is the input for ScaleSpec .
64
+ type ScaleSpecInput struct {
65
65
E2EConfig * clusterctl.E2EConfig
66
66
ClusterctlConfigPath string
67
67
BootstrapClusterProxy framework.ClusterProxy
@@ -119,6 +119,15 @@ type scaleSpecInput struct {
119
119
// If not specified, this is a no-op.
120
120
PostNamespaceCreated func (managementClusterProxy framework.ClusterProxy , workloadClusterNamespace string )
121
121
122
+ // Allows to inject a function to be run after test workload cluster name and namespace are generated and
123
+ // before applying the clusterclass and the cluster template.
124
+ // If not specified, this is a no-op.
125
+ PostScaleClusterNamespaceCreated func (
126
+ clusterProxy framework.ClusterProxy ,
127
+ clusterNamespace string ,
128
+ clusterName string ,
129
+ clusterClassYAML []byte ,
130
+ clusterTemplateYAML []byte ) (clusterClassTemlate []byte , ClusterTemplate []byte )
122
131
// FailFast if set to true will return immediately after the first cluster operation fails.
123
132
// If set to false, the test suite will not exit immediately after the first cluster operation fails.
124
133
// Example: When creating clusters from c1 to c20 consider c6 fails creation. If FailFast is set to true
@@ -141,11 +150,11 @@ type scaleSpecInput struct {
141
150
SkipWaitForCreation bool
142
151
}
143
152
144
- // scaleSpec implements a scale test for clusters with MachineDeployments.
145
- func scaleSpec (ctx context.Context , inputGetter func () scaleSpecInput ) {
153
+ // ScaleSpec implements a scale test for clusters with MachineDeployments.
154
+ func ScaleSpec (ctx context.Context , inputGetter func () ScaleSpecInput ) {
146
155
var (
147
156
specName = "scale"
148
- input scaleSpecInput
157
+ input ScaleSpecInput
149
158
namespace * corev1.Namespace
150
159
cancelWatches context.CancelFunc
151
160
)
@@ -331,7 +340,7 @@ func scaleSpec(ctx context.Context, inputGetter func() scaleSpecInput) {
331
340
Concurrency : concurrency ,
332
341
FailFast : input .FailFast ,
333
342
WorkerFunc : func (ctx context.Context , inputChan chan string , resultChan chan workResult , wg * sync.WaitGroup ) {
334
- createClusterWorker (ctx , input .BootstrapClusterProxy , inputChan , resultChan , wg , namespace .Name , input .DeployClusterInSeparateNamespaces , baseClusterClassYAML , baseClusterTemplateYAML , creator )
343
+ createClusterWorker (ctx , input .BootstrapClusterProxy , inputChan , resultChan , wg , namespace .Name , input .DeployClusterInSeparateNamespaces , baseClusterClassYAML , baseClusterTemplateYAML , creator , input . PostScaleClusterNamespaceCreated )
335
344
},
336
345
})
337
346
if err != nil {
@@ -568,7 +577,9 @@ func getClusterCreateFn(clusterProxy framework.ClusterProxy) clusterCreator {
568
577
}
569
578
}
570
579
571
- func createClusterWorker (ctx context.Context , clusterProxy framework.ClusterProxy , inputChan <- chan string , resultChan chan <- workResult , wg * sync.WaitGroup , defaultNamespace string , deployClusterInSeparateNamespaces bool , baseClusterClassYAML , baseClusterTemplateYAML []byte , create clusterCreator ) {
580
+ type PostScaleClusterNamespaceCreated func (clusterProxy framework.ClusterProxy , clusterNamespace string , clusterName string , clusterClassYAML []byte , clusterTemplateYAML []byte ) (clusterClassTemlate []byte , ClusterTemplate []byte )
581
+
582
+ func createClusterWorker (ctx context.Context , clusterProxy framework.ClusterProxy , inputChan <- chan string , resultChan chan <- workResult , wg * sync.WaitGroup , defaultNamespace string , deployClusterInSeparateNamespaces bool , baseClusterClassYAML , baseClusterTemplateYAML []byte , create clusterCreator , postScaleClusterNamespaceCreated PostScaleClusterNamespaceCreated ) {
572
583
defer wg .Done ()
573
584
574
585
for {
@@ -600,7 +611,13 @@ func createClusterWorker(ctx context.Context, clusterProxy framework.ClusterProx
600
611
if deployClusterInSeparateNamespaces {
601
612
namespaceName = clusterName
602
613
}
603
-
614
+ // Call postScaleClusterNamespaceCreated hook to apply custom requirements based on the clustername and namespace
615
+ customizedClusterTemplateYAML := baseClusterTemplateYAML
616
+ customizedClusterClassYAML := baseClusterClassYAML
617
+ if postScaleClusterNamespaceCreated != nil {
618
+ log .Logf ("Calling postScaleClusterNamespaceCreated for cluster %s in namespace %s" , clusterName , namespaceName )
619
+ customizedClusterClassYAML , customizedClusterTemplateYAML = postScaleClusterNamespaceCreated (clusterProxy , namespaceName , clusterName , baseClusterClassYAML , baseClusterTemplateYAML )
620
+ }
604
621
// If every cluster should be deployed in a separate namespace:
605
622
// * Adjust namespace in ClusterClass YAML.
606
623
// * Create new namespace.
@@ -614,14 +631,13 @@ func createClusterWorker(ctx context.Context, clusterProxy framework.ClusterProx
614
631
}, "40s" , "10s" )
615
632
616
633
log .Logf ("Apply ClusterClass in namespace %" , namespaceName )
617
- clusterClassYAML := bytes .Replace (baseClusterClassYAML , []byte (scaleClusterNamespacePlaceholder ), []byte (namespaceName ), - 1 )
634
+ clusterClassYAML := bytes .Replace (customizedClusterClassYAML , []byte (scaleClusterNamespacePlaceholder ), []byte (namespaceName ), - 1 )
618
635
Eventually (func () error {
619
636
return clusterProxy .CreateOrUpdate (ctx , clusterClassYAML )
620
637
}, 1 * time .Minute ).Should (Succeed ())
621
638
}
622
-
623
639
// Adjust namespace and name in Cluster YAML
624
- clusterTemplateYAML := bytes .Replace (baseClusterTemplateYAML , []byte (scaleClusterNamespacePlaceholder ), []byte (namespaceName ), - 1 )
640
+ clusterTemplateYAML := bytes .Replace (customizedClusterTemplateYAML , []byte (scaleClusterNamespacePlaceholder ), []byte (namespaceName ), - 1 )
625
641
clusterTemplateYAML = bytes .Replace (clusterTemplateYAML , []byte (scaleClusterNamePlaceholder ), []byte (clusterName ), - 1 )
626
642
627
643
// Deploy Cluster.
0 commit comments