Skip to content

Commit a68f166

Browse files
authored
Merge pull request #6984 from XiShanYongYe-Chang/automated-cherry-pick-of-#6931-upstream-release-1.13
Automated cherry pick of #6931: continue to match the dependencies, rather than return
2 parents 423a817 + 9a8dc96 commit a68f166

File tree

2 files changed

+384
-22
lines changed

2 files changed

+384
-22
lines changed

pkg/dependenciesdistributor/dependencies_distributor.go

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -178,13 +178,18 @@ func (d *DependenciesDistributor) reconcileResourceTemplate(key util.QueueKey) e
178178
return err
179179
}
180180

181+
var errs []error
181182
for i := range bindingList.Items {
182183
binding := &bindingList.Items[i]
183184
if !binding.DeletionTimestamp.IsZero() {
184185
continue
185186
}
186187

187-
matched := matchesWithBindingDependencies(resourceTemplateKey, binding)
188+
matched, err := matchesWithBindingDependencies(resourceTemplateKey, binding)
189+
if err != nil {
190+
errs = append(errs, err)
191+
continue
192+
}
188193
if !matched {
189194
continue
190195
}
@@ -193,49 +198,53 @@ func (d *DependenciesDistributor) reconcileResourceTemplate(key util.QueueKey) e
193198
d.genericEvent <- event.TypedGenericEvent[*workv1alpha2.ResourceBinding]{Object: binding}
194199
}
195200

196-
return nil
201+
return utilerrors.NewAggregate(errs)
197202
}
198203

199204
// matchesWithBindingDependencies tells if the given object(resource template) is matched
200205
// with the dependencies of independent resourceBinding.
201-
func matchesWithBindingDependencies(resourceTemplateKey *LabelsKey, independentBinding *workv1alpha2.ResourceBinding) bool {
206+
func matchesWithBindingDependencies(resourceTemplateKey *LabelsKey, independentBinding *workv1alpha2.ResourceBinding) (bool, error) {
202207
dependencies, exist := independentBinding.Annotations[dependenciesAnnotationKey]
203208
if !exist {
204-
return false
209+
return false, nil
205210
}
206211

207212
var dependenciesSlice []configv1alpha1.DependentObjectReference
208213
err := json.Unmarshal([]byte(dependencies), &dependenciesSlice)
209214
if err != nil {
210-
// If unmarshal fails, retrying with an error return will not solve the problem.
211-
// It will only increase the consumption by repeatedly listing the binding.
212-
// Therefore, it is better to print this error and ignore it.
213215
klog.Errorf("Failed to unmarshal binding(%s/%s) dependencies(%s): %v",
214216
independentBinding.Namespace, independentBinding.Name, dependencies, err)
215-
return false
217+
return false, err
216218
}
217219

218220
if len(dependenciesSlice) == 0 {
219-
return false
221+
return false, nil
220222
}
221223

224+
var errs []error
222225
for _, dependency := range dependenciesSlice {
223226
if resourceTemplateKey.GroupVersion().String() == dependency.APIVersion &&
224227
resourceTemplateKey.Kind == dependency.Kind &&
225228
resourceTemplateKey.Namespace == dependency.Namespace {
226229
if len(dependency.Name) != 0 {
227-
return dependency.Name == resourceTemplateKey.Name
230+
if dependency.Name == resourceTemplateKey.Name {
231+
return true, nil
232+
}
233+
continue
228234
}
229235
var selector labels.Selector
230236
if selector, err = metav1.LabelSelectorAsSelector(dependency.LabelSelector); err != nil {
231-
klog.Errorf("Failed to converts the LabelSelector of binding(%s/%s) dependencies(%s): %v",
237+
klog.Errorf("Failed to convert the LabelSelector of binding(%s/%s) dependencies(%s): %v",
232238
independentBinding.Namespace, independentBinding.Name, dependencies, err)
233-
return false
239+
errs = append(errs, err)
240+
continue
241+
}
242+
if selector.Matches(labels.Set(resourceTemplateKey.Labels)) {
243+
return true, nil
234244
}
235-
return selector.Matches(labels.Set(resourceTemplateKey.Labels))
236245
}
237246
}
238-
return false
247+
return false, utilerrors.NewAggregate(errs)
239248
}
240249

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

0 commit comments

Comments
 (0)