diff --git a/reconcilers/reconcilers.go b/reconcilers/reconcilers.go index 69f5a9b..b93c9a1 100644 --- a/reconcilers/reconcilers.go +++ b/reconcilers/reconcilers.go @@ -980,7 +980,7 @@ type ChildReconciler[Type, ChildType client.Object, ChildListType client.ObjectL // ReflectChildStatusOnParent updates the reconciled resource's status with values from the // child. Select types of error are passed, including: // - apierrs.IsConflict - ReflectChildStatusOnParent func(parent Type, child ChildType, err error) + ReflectChildStatusOnParent func(ctx context.Context, parent Type, child ChildType, err error) // HarmonizeImmutableFields allows fields that are immutable on the current // object to be copied to the desired object in order to avoid creating @@ -1128,13 +1128,13 @@ func (r *ChildReconciler[T, CT, CLT]) Reconcile(ctx context.Context, resource T) return Result{}, err } log.Info("unable to reconcile child, not owned", "child", namespaceName(conflicted), "ownerRefs", conflicted.GetOwnerReferences()) - r.ReflectChildStatusOnParent(resource, child, err) + r.ReflectChildStatusOnParent(ctx, resource, child, err) return Result{}, nil } log.Error(err, "unable to reconcile child") return Result{}, err } - r.ReflectChildStatusOnParent(resource, child, err) + r.ReflectChildStatusOnParent(ctx, resource, child, err) return Result{}, nil } diff --git a/reconcilers/reconcilers_test.go b/reconcilers/reconcilers_test.go index 10bc683..8ea1d37 100644 --- a/reconcilers/reconcilers_test.go +++ b/reconcilers/reconcilers_test.go @@ -1501,7 +1501,7 @@ func TestChildReconciler(t *testing.T) { MergeBeforeUpdate: func(current, desired *corev1.ConfigMap) { current.Data = desired.Data }, - ReflectChildStatusOnParent: func(parent *resources.TestResource, child *corev1.ConfigMap, err error) { + ReflectChildStatusOnParent: func(ctx context.Context, parent *resources.TestResource, child *corev1.ConfigMap, err error) { if err != nil { if apierrs.IsAlreadyExists(err) { name := err.(apierrs.APIStatus).Status().Details.Name @@ -2474,7 +2474,7 @@ func TestChildReconciler_Unstructured(t *testing.T) { MergeBeforeUpdate: func(current, desired *unstructured.Unstructured) { current.Object["data"] = desired.Object["data"] }, - ReflectChildStatusOnParent: func(parent *unstructured.Unstructured, child *unstructured.Unstructured, err error) { + ReflectChildStatusOnParent: func(ctx context.Context, parent *unstructured.Unstructured, child *unstructured.Unstructured, err error) { if err != nil { if apierrs.IsAlreadyExists(err) { name := err.(apierrs.APIStatus).Status().Details.Name diff --git a/reconcilers/reconcilers_validate_test.go b/reconcilers/reconcilers_validate_test.go index f1668dc..6545b3f 100644 --- a/reconcilers/reconcilers_validate_test.go +++ b/reconcilers/reconcilers_validate_test.go @@ -379,7 +379,7 @@ func TestChildReconciler_validate(t *testing.T) { ChildType: &corev1.Pod{}, ChildListType: &corev1.PodList{}, DesiredChild: func(ctx context.Context, parent *corev1.ConfigMap) (*corev1.Pod, error) { return nil, nil }, - ReflectChildStatusOnParent: func(parent *corev1.ConfigMap, child *corev1.Pod, err error) {}, + ReflectChildStatusOnParent: func(ctx context.Context, parent *corev1.ConfigMap, child *corev1.Pod, err error) {}, MergeBeforeUpdate: func(current, desired *corev1.Pod) {}, }, }, @@ -391,7 +391,7 @@ func TestChildReconciler_validate(t *testing.T) { // ChildType: &corev1.Pod{}, ChildListType: &corev1.PodList{}, DesiredChild: func(ctx context.Context, parent *corev1.ConfigMap) (*corev1.Pod, error) { return nil, nil }, - ReflectChildStatusOnParent: func(parent *corev1.ConfigMap, child *corev1.Pod, err error) {}, + ReflectChildStatusOnParent: func(ctx context.Context, parent *corev1.ConfigMap, child *corev1.Pod, err error) {}, MergeBeforeUpdate: func(current, desired *corev1.Pod) {}, }, }, @@ -403,7 +403,7 @@ func TestChildReconciler_validate(t *testing.T) { ChildType: &corev1.Pod{}, // ChildListType: &corev1.PodList{}, DesiredChild: func(ctx context.Context, parent *corev1.ConfigMap) (*corev1.Pod, error) { return nil, nil }, - ReflectChildStatusOnParent: func(parent *corev1.ConfigMap, child *corev1.Pod, err error) {}, + ReflectChildStatusOnParent: func(ctx context.Context, parent *corev1.ConfigMap, child *corev1.Pod, err error) {}, MergeBeforeUpdate: func(current, desired *corev1.Pod) {}, }, }, @@ -415,7 +415,7 @@ func TestChildReconciler_validate(t *testing.T) { ChildType: &corev1.Pod{}, ChildListType: &corev1.PodList{}, // DesiredChild: func(ctx context.Context, parent *corev1.ConfigMap) (*corev1.Pod, error) { return nil, nil }, - ReflectChildStatusOnParent: func(parent *corev1.ConfigMap, child *corev1.Pod, err error) {}, + ReflectChildStatusOnParent: func(ctx context.Context, parent *corev1.ConfigMap, child *corev1.Pod, err error) {}, MergeBeforeUpdate: func(current, desired *corev1.Pod) {}, }, shouldErr: `ChildReconciler "DesiredChild missing" must implement DesiredChild`, @@ -440,7 +440,7 @@ func TestChildReconciler_validate(t *testing.T) { ChildType: &corev1.Pod{}, ChildListType: &corev1.PodList{}, DesiredChild: func(ctx context.Context, parent *corev1.ConfigMap) (*corev1.Pod, error) { return nil, nil }, - ReflectChildStatusOnParent: func(parent *corev1.ConfigMap, child *corev1.Pod, err error) {}, + ReflectChildStatusOnParent: func(ctx context.Context, parent *corev1.ConfigMap, child *corev1.Pod, err error) {}, MergeBeforeUpdate: func(current, desired *corev1.Pod) {}, ListOptions: func(ctx context.Context, parent *corev1.ConfigMap) []client.ListOption { return []client.ListOption{} }, }, @@ -453,7 +453,7 @@ func TestChildReconciler_validate(t *testing.T) { ChildType: &corev1.Pod{}, ChildListType: &corev1.PodList{}, DesiredChild: func(ctx context.Context, parent *corev1.ConfigMap) (*corev1.Pod, error) { return nil, nil }, - ReflectChildStatusOnParent: func(parent *corev1.ConfigMap, child *corev1.Pod, err error) {}, + ReflectChildStatusOnParent: func(ctx context.Context, parent *corev1.ConfigMap, child *corev1.Pod, err error) {}, MergeBeforeUpdate: func(current, desired *corev1.Pod) {}, Finalizer: "my-finalizer", }, @@ -467,7 +467,7 @@ func TestChildReconciler_validate(t *testing.T) { ChildType: &corev1.Pod{}, ChildListType: &corev1.PodList{}, DesiredChild: func(ctx context.Context, parent *corev1.ConfigMap) (*corev1.Pod, error) { return nil, nil }, - ReflectChildStatusOnParent: func(parent *corev1.ConfigMap, child *corev1.Pod, err error) {}, + ReflectChildStatusOnParent: func(ctx context.Context, parent *corev1.ConfigMap, child *corev1.Pod, err error) {}, MergeBeforeUpdate: func(current, desired *corev1.Pod) {}, SkipOwnerReference: true, }, @@ -480,7 +480,7 @@ func TestChildReconciler_validate(t *testing.T) { ChildType: &corev1.Pod{}, ChildListType: &corev1.PodList{}, DesiredChild: func(ctx context.Context, parent *corev1.ConfigMap) (*corev1.Pod, error) { return nil, nil }, - ReflectChildStatusOnParent: func(parent *corev1.ConfigMap, child *corev1.Pod, err error) {}, + ReflectChildStatusOnParent: func(ctx context.Context, parent *corev1.ConfigMap, child *corev1.Pod, err error) {}, MergeBeforeUpdate: func(current, desired *corev1.Pod) {}, OurChild: func(parent *corev1.ConfigMap, child *corev1.Pod) bool { return false }, },