Skip to content

Commit

Permalink
validate MergeBeforeUpdate in ChildReconciler (#451)
Browse files Browse the repository at this point in the history
  • Loading branch information
squeedee committed Nov 3, 2023
1 parent c994cf2 commit e19c127
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions reconcilers/child.go
Expand Up @@ -230,6 +230,11 @@ func (r *ChildReconciler[T, CT, CLT]) validate(ctx context.Context) error {
return fmt.Errorf("ChildReconciler %q must implement OurChild since owner references are not used", r.Name)
}

// require MergeBeforeUpdate
if r.MergeBeforeUpdate == nil {
return fmt.Errorf("ChildReconciler %q must implement MergeBeforeUpdate", r.Name)
}

return nil
}

Expand Down
13 changes: 13 additions & 0 deletions reconcilers/validate_test.go
Expand Up @@ -438,6 +438,19 @@ func TestChildReconciler_validate(t *testing.T) {
},
shouldErr: `ChildReconciler "ReflectChildStatusOnParent missing" must implement ReflectChildStatusOnParent`,
},
{
name: "MergeBeforeUpdate missing",
parent: &corev1.ConfigMap{},
reconciler: &ChildReconciler[*corev1.ConfigMap, *corev1.Pod, *corev1.PodList]{
Name: "MergeBeforeUpdate missing",
ChildType: &corev1.Pod{},
ChildListType: &corev1.PodList{},
DesiredChild: func(ctx context.Context, parent *corev1.ConfigMap) (*corev1.Pod, error) { return nil, nil },
ReflectChildStatusOnParent: func(ctx context.Context, parent *corev1.ConfigMap, child *corev1.Pod, err error) {},
//MergeBeforeUpdate: func(current, desired *corev1.Pod) {},
},
shouldErr: `ChildReconciler "MergeBeforeUpdate missing" must implement MergeBeforeUpdate`,
},
{
name: "ListOptions",
parent: &corev1.ConfigMap{},
Expand Down

0 comments on commit e19c127

Please sign in to comment.