@@ -140,15 +140,18 @@ func (t *topologyClient) Plan(ctx context.Context, in *TopologyPlanInput) (*Topo
140
140
// This mimics the defaulting and validation webhooks that will run on the objects during a real execution.
141
141
// Running defaulting and validation on these objects helps to improve the UX of using the plan operation.
142
142
// This is especially important when working with Clusters and ClusterClasses that use variable and patches.
143
- if err := t .runDefaultAndValidationWebhooks (ctx , in , c ); err != nil {
143
+ reconciledClusterClasses , err := t .runDefaultAndValidationWebhooks (ctx , in , c )
144
+ if err != nil {
144
145
return nil , errors .Wrap (err , "failed defaulting and validation on input objects" )
145
146
}
146
147
147
148
objs := []client.Object {}
148
149
// Add all the objects from the input to the list used when initializing the dry run client.
149
- for _ , o := range in .Objs {
150
+ for _ , o := range filterObjects ( in .Objs , clusterv1 . GroupVersion . WithKind ( "ClusterClass" )) {
150
151
objs = append (objs , o )
151
152
}
153
+ // Note: We have to add the reconciled ClusterClasses, because the Cluster reconciler depends on that.
154
+ objs = append (objs , reconciledClusterClasses ... )
152
155
// Add mock CRDs of all the provider objects in the input to the list used when initializing the dry run client.
153
156
// Adding these CRDs makes sure that UpdateReferenceAPIContract calls in the reconciler can work.
154
157
for _ , o := range t .generateCRDs (in .Objs ) {
@@ -362,11 +365,11 @@ func (t *topologyClient) prepareClusters(ctx context.Context, clusters []*unstru
362
365
// ValidateCreate is performed.
363
366
// *Important Note*: We cannot perform defaulting and validation on provider objects as we do not have access to
364
367
// that code.
365
- func (t * topologyClient ) runDefaultAndValidationWebhooks (ctx context.Context , in * TopologyPlanInput , apiReader client.Reader ) error {
368
+ func (t * topologyClient ) runDefaultAndValidationWebhooks (ctx context.Context , in * TopologyPlanInput , apiReader client.Reader ) ([]client. Object , error ) {
366
369
// Enable the ClusterTopology feature gate so that the defaulter and validators do not complain.
367
370
// Note: We don't need to disable it later because the CLI is short lived.
368
371
if err := feature .Gates .(featuregate.MutableFeatureGate ).Set (fmt .Sprintf ("%s=%v" , feature .ClusterTopology , true )); err != nil {
369
- return errors .Wrapf (err , "failed to enable %s feature gate" , feature .ClusterTopology )
372
+ return nil , errors .Wrapf (err , "failed to enable %s feature gate" , feature .ClusterTopology )
370
373
}
371
374
372
375
// From the inputs gather all the objects that are not Clusters or ClusterClasses.
@@ -395,7 +398,7 @@ func (t *topologyClient) runDefaultAndValidationWebhooks(ctx context.Context, in
395
398
ccWebhook ,
396
399
apiReader ,
397
400
); err != nil {
398
- return errors .Wrap (err , "failed to run defaulting and validation on ClusterClasses" )
401
+ return nil , errors .Wrap (err , "failed to run defaulting and validation on ClusterClasses" )
399
402
}
400
403
401
404
// From the inputs gather all the objects that are not Clusters or ClusterClasses.
@@ -416,7 +419,7 @@ func (t *topologyClient) runDefaultAndValidationWebhooks(ctx context.Context, in
416
419
// during ClusterClass reconciliation.
417
420
reconciledClusterClasses , err := t .reconcileClusterClasses (ctx , in .Objs , apiReader )
418
421
if err != nil {
419
- return errors .Wrapf (err , "failed to reconcile ClusterClasses for defaulting and validating" )
422
+ return nil , errors .Wrapf (err , "failed to reconcile ClusterClasses for defaulting and validating" )
420
423
}
421
424
objs = append (objs , reconciledClusterClasses ... )
422
425
@@ -432,10 +435,10 @@ func (t *topologyClient) runDefaultAndValidationWebhooks(ctx context.Context, in
432
435
clusterWebhook ,
433
436
apiReader ,
434
437
); err != nil {
435
- return errors .Wrap (err , "failed to run defaulting and validation on Clusters" )
438
+ return nil , errors .Wrap (err , "failed to run defaulting and validation on Clusters" )
436
439
}
437
440
438
- return nil
441
+ return reconciledClusterClasses , nil
439
442
}
440
443
441
444
func (t * topologyClient ) reconcileClusterClasses (ctx context.Context , inputObjects []* unstructured.Unstructured , apiReader client.Reader ) ([]client.Object , error ) {
0 commit comments