kubernetes-sigs / controller-runtime

Repo for the controller-runtime subproject of kubebuilder (sig-apimachinery)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add interface assertion for delegatingByGVKCache

ShyunnY opened this issue · comments

When I was reviewing the source code for delegatingByGVKCache, I found it difficult to quickly determine which interfaces this type implements. I had to examine the methods and their return values to understand the implemented interfaces. Since delegatingByGVKCache doesn't have an explicit constructor, we can't infer the implemented interfaces from the return semantics of the constructor.

Therefore, I would like to propose adding interface assertions to the delegatingByGVKCache type, as follows:

var _ Cache = &delegatingByGVKCache{}
var _ client.Reader = &delegatingByGVKCache{}
var _ Informers = &delegatingByGVKCache{}

This feature may not be essential, but it would certainly improve the user experience when reviewing the source code, as it allows for quick identification of the interfaces that the type implements. (At least this can be done without the IDE, and you can quickly learn about its implementation interface.)

This type is not even exported, why would it matter? The Cache interface is btw the combination of client.Reader and Informers, so your example is somewhat redundant.

Thank you for your reply. I thought about it carefully. It is indeed not necessary.