Skip to content
This repository was archived by the owner on Aug 28, 2024. It is now read-only.

Adding ChildSetReconciler to manage a set of child resources#382

Closed
LittleBaiBai wants to merge 3 commits intovmware-labs:mainfrom
LittleBaiBai:child-set-subreconciler
Closed

Adding ChildSetReconciler to manage a set of child resources#382
LittleBaiBai wants to merge 3 commits intovmware-labs:mainfrom
LittleBaiBai:child-set-subreconciler

Conversation

@LittleBaiBai
Copy link
Contributor

@LittleBaiBai LittleBaiBai commented Jun 14, 2023

Relates to #75

@LittleBaiBai LittleBaiBai force-pushed the child-set-subreconciler branch 3 times, most recently from 1b62191 to bc1d6f2 Compare June 14, 2023 19:01
},
},
},
"sanitize each child before logging": { //TODO: what's different?
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I copied this test from the ChildReconciler test suite but I don't fully understand how we are testing the functionality here. There seems to be no assertion on logs, and changing the return value of SanitizeForEachChild, or SanitizeForChild in ChildReconciler suite, doesn't seem to affect the test runs.

@LittleBaiBai LittleBaiBai force-pushed the child-set-subreconciler branch from bc1d6f2 to 3599f72 Compare June 14, 2023 20:23
Copy link
Contributor

@scothis scothis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

initial comments, will need to dig deeper tomorrow

"encoding/json"
"errors"
"fmt"
utilErrs "k8s.io/apimachinery/pkg/util/errors"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this package is already imported as apierrs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

apierrs "k8s.io/apimachinery/pkg/api/errors" is a different package from this.

return Result{}, err
}
r.ReflectChildStatusOnParent(ctx, resource, child, err)
r.ReflectChildStatusOnParent(ctx, resource, child, nil)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was this intentional?

Copy link
Contributor Author

@LittleBaiBai LittleBaiBai Jun 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it was intended. The if block before this already handled the case when err != nil so the err here will be nil and it reads better to me. Happy to revert it if that's preferred.

return Result{}, aggregateErr
}
if aggregateErr != nil {
for _, eachErr := range aggregateErr.(utilErrs.Aggregate).Errors() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this cast appears to be redundant since aggregateErr is already an Aggregate as defined by the reconcile signature.

Copy link
Contributor Author

@LittleBaiBai LittleBaiBai Jun 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. That was there before I change the signature of the method. Updated in latest commits.

Comment on lines +1508 to +1509
r.ReflectChildSetStatusOnParent(ctx, resource, childSet, aggregateErr)
return Result{}, nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this return can obscure other errors that exist in the aggregate

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Could you share more on why you chose to return Result{}, nil for ChildReconciler here? Is it for not triggering the rateLimiter in the requeue? I'm tempted to move the ReflectChildSetStatusOnParent call outside of the for loop and always return return Result{}, aggregateErr when something goes wrong.

return defaultValue
}

func (r *ChildSetReconciler[T, CT, CLT]) reconcile(ctx context.Context, resource T) ([]CT, utilErrs.Aggregate) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aggregate errors strip out nil values, so the errors are separated from the specific child, is this is ok? Switch to []error if linking the error with a child resource is important.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh interesting! I'll experiment with that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I try to rewrite it, there are errors that could happen before the actual child resource reconciliation, e.g. listing actual children. Also, when error occurs, the result returned by r.stamp.Manage is usually nilT so I still don't see how we can link the error to the child resource even if we switch it to []Error.

// on the reconciled resource as being not ready.
apierr := eachErr.(apierrs.APIStatus)
conflicted := r.ChildType.DeepCopyObject().(CT)
_ = c.APIReader.Get(ctx, types.NamespacedName{Namespace: resource.GetNamespace(), Name: apierr.Status().Details.Name}, conflicted)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this line comes from an earlier era of ChildReconciler where children were forced to exist in the same namespace at the parent resource. This restriction was relaxed, but this line wasn't updated... I'll need to think about how to resolve this since the namespace is not on the err object.

}

actualChildrenMap, err1 := r.childListToMap(actualChildren)
if err1 != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

avoid non-semantic names for errors. Either reassign err, or if you need to avoid shadowing the existing value, use a semantic name.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in latest commits


func (r *ChildSetReconciler[T, CT, CLT]) hasChild(childSet []CT) bool {
hasChild := false
if !internal.IsNil(childSet) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

checking the length is a more common way to nil check a slice, unless nil and length 0 have different semantic values.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in latest commits

@scothis
Copy link
Contributor

scothis commented Jul 28, 2023

Folded concepts into #396

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants