@@ -759,14 +759,8 @@ func (d *ResourceDetector) BuildResourceBinding(object *unstructured.Unstructure
759
759
760
760
claimFunc (propagationBinding , policyID , policyMeta )
761
761
762
- if d .ResourceInterpreter .HookEnabled (object .GroupVersionKind (), configv1alpha1 .InterpreterOperationInterpretReplica ) {
763
- replicas , replicaRequirements , err := d .ResourceInterpreter .GetReplicas (object )
764
- if err != nil {
765
- klog .Errorf ("Failed to customize replicas for %s(%s), %v" , object .GroupVersionKind (), object .GetName (), err )
766
- return nil , err
767
- }
768
- propagationBinding .Spec .Replicas = replicas
769
- propagationBinding .Spec .ReplicaRequirements = replicaRequirements
762
+ if err := d .applyReplicaInterpretation (object , & propagationBinding .Spec ); err != nil {
763
+ return nil , err
770
764
}
771
765
772
766
if features .FeatureGate .Enabled (features .PriorityBasedScheduling ) && policySpec .SchedulePriority != nil {
@@ -833,14 +827,8 @@ func (d *ResourceDetector) BuildClusterResourceBinding(object *unstructured.Unst
833
827
834
828
AddCPPClaimMetadata (binding , policyID , policyMeta )
835
829
836
- if d .ResourceInterpreter .HookEnabled (object .GroupVersionKind (), configv1alpha1 .InterpreterOperationInterpretReplica ) {
837
- replicas , replicaRequirements , err := d .ResourceInterpreter .GetReplicas (object )
838
- if err != nil {
839
- klog .Errorf ("Failed to customize replicas for %s(%s), %v" , object .GroupVersionKind (), object .GetName (), err )
840
- return nil , err
841
- }
842
- binding .Spec .Replicas = replicas
843
- binding .Spec .ReplicaRequirements = replicaRequirements
830
+ if err := d .applyReplicaInterpretation (object , & binding .Spec ); err != nil {
831
+ return nil , err
844
832
}
845
833
846
834
return binding , nil
@@ -1350,8 +1338,38 @@ func (d *ResourceDetector) CleanupClusterResourceBindingClaimMetadata(crb *workv
1350
1338
if err = d .Client .Get (context .TODO (), client.ObjectKey {Name : crb .GetName ()}, updated ); err == nil {
1351
1339
crb = updated .DeepCopy ()
1352
1340
} else {
1353
- klog .Errorf ("Failed to get updated ClusterResourceBinding(%s):: %v" , crb .GetName (), err )
1341
+ klog .Errorf ("Failed to get updated ClusterResourceBinding(%s): %v" , crb .GetName (), err )
1354
1342
}
1355
1343
return updateErr
1356
1344
})
1357
1345
}
1346
+
1347
+ // applyReplicaInterpretation handles the logic for interpreting replicas or components from an object.
1348
+ func (d * ResourceDetector ) applyReplicaInterpretation (object * unstructured.Unstructured , spec * workv1alpha2.ResourceBindingSpec ) error {
1349
+ gvk := object .GroupVersionKind ()
1350
+ name := object .GetName ()
1351
+
1352
+ // Prioritize component interpretation if the feature and GetComponents are enabled.
1353
+ if features .FeatureGate .Enabled (features .MultiplePodTemplatesScheduling ) && d .ResourceInterpreter .HookEnabled (gvk , configv1alpha1 .InterpreterOperationInterpretComponent ) {
1354
+ components , err := d .ResourceInterpreter .GetComponents (object )
1355
+ if err != nil {
1356
+ klog .Errorf ("Failed to get components for %s(%s): %v" , gvk , name , err )
1357
+ return err
1358
+ }
1359
+ spec .Components = components
1360
+ return nil
1361
+ }
1362
+
1363
+ // GetReplicas is executed if the MultiplePodTemplatesScheduling feature gate is disabled, or if GetComponents is not implemented.
1364
+ if d .ResourceInterpreter .HookEnabled (gvk , configv1alpha1 .InterpreterOperationInterpretReplica ) {
1365
+ replicas , replicaRequirements , err := d .ResourceInterpreter .GetReplicas (object )
1366
+ if err != nil {
1367
+ klog .Errorf ("Failed to customize replicas for %s(%s): %v" , gvk , name , err )
1368
+ return err
1369
+ }
1370
+ spec .Replicas = replicas
1371
+ spec .ReplicaRequirements = replicaRequirements
1372
+ }
1373
+
1374
+ return nil
1375
+ }
0 commit comments