I'm developing an application that manages many different components, including various objects in a Kubernetes cluster.
There's a nice Java library to manage K8S objects, I use it to examine objects and manipulate them, but for most of the objects, I need some kind of a "wrapper-object" to store certain internal data of my application. For example, there's the V1Pod
class, it's being used for K8S pods. An object of this class contains the list of related container objects (class V1Container
) and so on and so forth. I need to keep some records about this pod, these records can't be kept in the K8S object, so I have to create my own object (we can call it MyV1Pod
) with extra fields and a field containing a reference to the V1Pod
object. Moreover, I also have to create my own objects of the MyV1Container
class containing extra fields and references to the corresponding object of the V1Container
class. And I have to keep the list of these MyV1Container
-objects in MyV1Pod
-object.
I find it a bit cumbersome to create a separate "wrapper" for each of all these classes. Is there any way to automate that? For example, when an application starts, it would scan all the classes in that library and create a "decorating" class for each of the classes that I need? For example, it would find the V1Pod
class, create something like MyV1Pod
and add a field containing a reference to the corresponding the V1Pod
object and that additional fields that I need.
Something similar to the Decorator pattern, but with certain automation.
Or maybe I should go another way?
Any piece of advice would be very welcome!