@@ -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,16 @@ 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 ) ([]byte , []byte )
131
+
122
132
// FailFast if set to true will return immediately after the first cluster operation fails.
123
133
// If set to false, the test suite will not exit immediately after the first cluster operation fails.
124
134
// Example: When creating clusters from c1 to c20 consider c6 fails creation. If FailFast is set to true
@@ -141,11 +151,11 @@ type scaleSpecInput struct {
141
151
SkipWaitForCreation bool
142
152
}
143
153
144
- // scaleSpec implements a scale test for clusters with MachineDeployments.
145
- func scaleSpec (ctx context.Context , inputGetter func () scaleSpecInput ) {
154
+ // ScaleSpec implements a scale test for clusters with MachineDeployments.
155
+ func ScaleSpec (ctx context.Context , inputGetter func () ScaleSpecInput ) {
146
156
var (
147
157
specName = "scale"
148
- input scaleSpecInput
158
+ input ScaleSpecInput
149
159
namespace * corev1.Namespace
150
160
cancelWatches context.CancelFunc
151
161
)
@@ -331,7 +341,7 @@ func scaleSpec(ctx context.Context, inputGetter func() scaleSpecInput) {
331
341
Concurrency : concurrency ,
332
342
FailFast : input .FailFast ,
333
343
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 )
344
+ createClusterWorker (ctx , input .BootstrapClusterProxy , inputChan , resultChan , wg , namespace .Name , input .DeployClusterInSeparateNamespaces , baseClusterClassYAML , baseClusterTemplateYAML , creator , input . PostScaleClusterNamespaceCreated )
335
345
},
336
346
})
337
347
if err != nil {
@@ -568,7 +578,9 @@ func getClusterCreateFn(clusterProxy framework.ClusterProxy) clusterCreator {
568
578
}
569
579
}
570
580
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 ) {
581
+ type PostScaleClusterNamespaceCreated func (clusterProxy framework.ClusterProxy , clusterNamespace string , clusterName string , clusterClassYAML []byte , clusterTemplateYAML []byte ) ([]byte , []byte )
582
+
583
+ 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
584
defer wg .Done ()
573
585
574
586
for {
@@ -604,24 +616,36 @@ func createClusterWorker(ctx context.Context, clusterProxy framework.ClusterProx
604
616
// If every cluster should be deployed in a separate namespace:
605
617
// * Adjust namespace in ClusterClass YAML.
606
618
// * Create new namespace.
607
- // * Deploy ClusterClass in new namespace.
608
619
if deployClusterInSeparateNamespaces {
609
620
log .Logf ("Create namespace %" , namespaceName )
610
621
_ = framework .CreateNamespace (ctx , framework.CreateNamespaceInput {
611
622
Creator : clusterProxy .GetClient (),
612
623
Name : namespaceName ,
613
624
IgnoreAlreadyExists : true ,
614
625
}, "40s" , "10s" )
626
+ }
615
627
628
+ // Call postScaleClusterNamespaceCreated hook to apply custom requirements based on the cluster name and namespace
629
+ // User might need to apply additional custom resource in the cluster namespace or customize the templates
630
+ customizedClusterTemplateYAML := baseClusterTemplateYAML
631
+ customizedClusterClassYAML := baseClusterClassYAML
632
+ if postScaleClusterNamespaceCreated != nil {
633
+ log .Logf ("Calling postScaleClusterNamespaceCreated for cluster %s in namespace %s" , clusterName , namespaceName )
634
+ customizedClusterClassYAML , customizedClusterTemplateYAML = postScaleClusterNamespaceCreated (clusterProxy , namespaceName , clusterName , baseClusterClassYAML , baseClusterTemplateYAML )
635
+ }
636
+
637
+ // If every cluster should be deployed in a separate namespace:
638
+ // * Deploy ClusterClass in new namespace.
639
+ if deployClusterInSeparateNamespaces {
616
640
log .Logf ("Apply ClusterClass in namespace %" , namespaceName )
617
- clusterClassYAML := bytes .Replace (baseClusterClassYAML , []byte (scaleClusterNamespacePlaceholder ), []byte (namespaceName ), - 1 )
641
+ clusterClassYAML := bytes .Replace (customizedClusterClassYAML , []byte (scaleClusterNamespacePlaceholder ), []byte (namespaceName ), - 1 )
618
642
Eventually (func () error {
619
643
return clusterProxy .CreateOrUpdate (ctx , clusterClassYAML )
620
644
}, 1 * time .Minute ).Should (Succeed ())
621
645
}
622
646
623
647
// Adjust namespace and name in Cluster YAML
624
- clusterTemplateYAML := bytes .Replace (baseClusterTemplateYAML , []byte (scaleClusterNamespacePlaceholder ), []byte (namespaceName ), - 1 )
648
+ clusterTemplateYAML := bytes .Replace (customizedClusterTemplateYAML , []byte (scaleClusterNamespacePlaceholder ), []byte (namespaceName ), - 1 )
625
649
clusterTemplateYAML = bytes .Replace (clusterTemplateYAML , []byte (scaleClusterNamePlaceholder ), []byte (clusterName ), - 1 )
626
650
627
651
// Deploy Cluster.
0 commit comments