Skip to content

Commit e765b1e

Browse files
authored
Merge pull request #6982 from XiShanYongYe-Chang/automated-cherry-pick-of-#6931-upstream-release-1.15
Automated cherry pick of #6931: continue to match the dependencies, rather than return
2 parents 7e103e0 + a69403a commit e765b1e

File tree

2 files changed

+383
-21
lines changed

2 files changed

+383
-21
lines changed

pkg/dependenciesdistributor/dependencies_distributor.go

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -183,13 +183,18 @@ func (d *DependenciesDistributor) reconcileResourceTemplate(key util.QueueKey) e
183183
return err
184184
}
185185

186+
var errs []error
186187
for i := range readonlyBindingList.Items {
187188
binding := &readonlyBindingList.Items[i]
188189
if !binding.DeletionTimestamp.IsZero() {
189190
continue
190191
}
191192

192-
matched := matchesWithBindingDependencies(resourceTemplateKey, binding)
193+
matched, err := matchesWithBindingDependencies(resourceTemplateKey, binding)
194+
if err != nil {
195+
errs = append(errs, err)
196+
continue
197+
}
193198
if !matched {
194199
continue
195200
}
@@ -198,48 +203,52 @@ func (d *DependenciesDistributor) reconcileResourceTemplate(key util.QueueKey) e
198203
d.genericEvent <- event.TypedGenericEvent[*workv1alpha2.ResourceBinding]{Object: binding}
199204
}
200205

201-
return nil
206+
return utilerrors.NewAggregate(errs)
202207
}
203208

204209
// matchesWithBindingDependencies tells if the given object(resource template) is matched
205210
// with the dependencies of independent resourceBinding.
206-
func matchesWithBindingDependencies(resourceTemplateKey *LabelsKey, independentBinding *workv1alpha2.ResourceBinding) bool {
211+
func matchesWithBindingDependencies(resourceTemplateKey *LabelsKey, independentBinding *workv1alpha2.ResourceBinding) (bool, error) {
207212
dependencies, exist := independentBinding.Annotations[dependenciesAnnotationKey]
208213
if !exist {
209-
return false
214+
return false, nil
210215
}
211216

212217
var dependenciesSlice []configv1alpha1.DependentObjectReference
213218
err := json.Unmarshal([]byte(dependencies), &dependenciesSlice)
214219
if err != nil {
215-
// If unmarshal fails, retrying with an error return will not solve the problem.
216-
// It will only increase the consumption by repeatedly listing the binding.
217-
// Therefore, it is better to print this error and ignore it.
218220
klog.Errorf("Failed to unmarshal binding(%s/%s) dependencies(%s): %v",
219221
independentBinding.Namespace, independentBinding.Name, dependencies, err)
220-
return false
222+
return false, err
221223
}
222224
if len(dependenciesSlice) == 0 {
223-
return false
225+
return false, nil
224226
}
225227

228+
var errs []error
226229
for _, dependency := range dependenciesSlice {
227230
if resourceTemplateKey.GroupVersion().String() == dependency.APIVersion &&
228231
resourceTemplateKey.Kind == dependency.Kind &&
229232
resourceTemplateKey.Namespace == dependency.Namespace {
230233
if len(dependency.Name) != 0 {
231-
return dependency.Name == resourceTemplateKey.Name
234+
if dependency.Name == resourceTemplateKey.Name {
235+
return true, nil
236+
}
237+
continue
232238
}
233239
var selector labels.Selector
234240
if selector, err = metav1.LabelSelectorAsSelector(dependency.LabelSelector); err != nil {
235241
klog.Errorf("Failed to converts the LabelSelector of binding(%s/%s) dependencies(%s): %v",
236242
independentBinding.Namespace, independentBinding.Name, dependencies, err)
237-
return false
243+
errs = append(errs, err)
244+
continue
245+
}
246+
if selector.Matches(labels.Set(resourceTemplateKey.Labels)) {
247+
return true, nil
238248
}
239-
return selector.Matches(labels.Set(resourceTemplateKey.Labels))
240249
}
241250
}
242-
return false
251+
return false, utilerrors.NewAggregate(errs)
243252
}
244253

245254
// Reconcile performs a full reconciliation for the object referred to by the Request.

0 commit comments

Comments
 (0)