How to recursively get dependent resources of Kubernetes owner resource
There are no ready solutions for this.
I see two options how this can be proceeded:
1 - probably this is what you already mentioned: "need to use a custom script to do it".
Idea is to get json
s of required resource groups and then process it by any available/known language like bash/python/java/etc and/or using jq
. All dependent objects have ownerReference
field which allows to match resources.
More information about owners and dependents
2 - Write your own tool based on kubernetes garbage collector
Kubernetes garbage collector works based on graph
built by GraphBuilder
:
Graph is always up to date by using `reflectors:
GarbageCollector runs reflectors to watch for changes of managed APIobjects, funnels the results to a single-threadeddependencyGraphBuilder, which builds a graph caching the dependenciesamong objects
graph_builder source code to get whole logic of it.
Built graph
has node
type:
Also it's worth to mention that working with api server
is more convenient using kubernetes clients libraries which are available for different languages.