kube-object-storage / lib-bucket-provisioner

Library for the dynamic provisioning of object store buckets to be used by object store providers.
Apache License 2.0
20 stars 22 forks source link

object passing by reference (pointer) check #127

Open jeffvance opened 5 years ago

jeffvance commented 5 years ago

I think the most readable pattern for functions that accept k8s objects as arguments is to accept them by reference (in order to save memory and slightly improve performance), but if the func modifies the object then it must explicitly return it. For example:

Not So Good:

func Foo(obc *v1alpha1.ObjectBucketClaim) error {
    obc.SetFinalizers(...)
    return nil
}

Better:

func Foo(obc *v1alpha1.ObjectBucketClaim) (*v1alpha1.ObjectBucketClaim, error) {
    obc.SetFinalizers(...)
    return obc, nil
}

We have not checked the lib code for this pattern but recommend that the next owner do so.